Require authors to set featured image for post

前端 未结 3 754
天命终不由人
天命终不由人 2021-01-06 04:29

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

3条回答
  •  温柔的废话
    2021-01-06 05:22

    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.

提交回复
热议问题