这将不会发布没有特色图片的帖子。
add_filter( \'wp_insert_post_data\', function ( $data, $postarr ) {
$post_id = $postarr[\'ID\'];
$post_status = $data[\'post_status\'];
$original_post_status = $postarr[\'original_post_status\'];
if ( $post_id && \'publish\' === $post_status && \'publish\' !== $original_post_status ) {
$post_type = get_post_type( $post_id );
if ( post_type_supports( $post_type, \'thumbnail\' ) && ! has_post_thumbnail( $post_id )) {
$data[\'post_status\'] = \'draft\';
}
}
return $data;
}, 10, 2 );
这将通知管理员需要功能映像。
global $pagenow;
if ( $pagenow == \'post-new.php\' || $pagenow == \'post.php\' ) :
add_action( \'admin_notices\', function () {
$post = get_post();
if ( \'publish\' !== get_post_status( $post->ID ) && ! has_post_thumbnail( $post->ID ) ) { ?>
<div id="message" class="error">
<p> <strong>
<?php _e( \'Please set a Featured Image. This post cannot be published without one.\'); ?>
</strong> </p>
</div>
<?php }
} );
endif;