钩入wp_insert_post
, 检查是否是页面的自动草稿,并设置comment_status
到closed
:
add_action( \'wp_insert_post\', \'t5_disable_default_comments_on_pages\', 10, 2 );
function t5_disable_default_comments_on_pages( $post_ID, $post )
{
remove_filter( current_filter(), __FUNCTION__ );
if ( \'auto-draft\' !== $post->post_status or \'page\' !== $post->post_type )
return;
$post->comment_status = \'closed\';
wp_update_post( $post );
}