I want to turn the comments off by default with pages and custom post-types
Initially I simply used conditionals in the comments display function to avoid displaying the block on these pages, but I need the user to be able to turn the comments back on as required.
From what I understand, you want to set pages and some custom post types to have commenting ‘off’ by default, while posts will still use the default option (i.e. commenting ‘on’). If this is the case, the following function will do it.
function default_comments_off( $data ) {
if( $data['post_type'] == 'page' && $data['post_status'] == 'auto-draft' ) {
$data['comment_status'] = 0;
}
return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_off' );