Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require authors to set featured image for post

I have customised my Wordpress site design to use the featured image for posts quite excessively. This is why I need to require all post made by non-admins to require a set featured image.

How is this possible?

like image 751
Gary Woods Avatar asked Dec 11 '22 22:12

Gary Woods


1 Answers

You need to hook the Publish Action in a custom PlugIn you write. Although this is to require a title, this should get you started, you just need to check if a featured image was assigned.

add_action( 'pre_post_update', 'bawdp_dont_publish' );

function bawdp_dont_publish()
{
    global $post;
    if ( strlen( $post->title ) < 10 ) {
        wp_die( 'The title of your post have to be 10 or more !' );
    }
}

Look at (has_post_thumbnail( $post->ID )) to determine if a post has a featured image.

like image 150
Gary Avatar answered Jan 03 '23 22:01

Gary