要求作者为后期设置精选图片 [英] Require authors to set featured image for post

查看:109
本文介绍了要求作者为后期设置精选图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经自定义了我的Wordpress网站设计,使用精选图片的帖子相当过分。这就是为什么我需要要求非管理员发布的所有帖子都需要设置特色图片。

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.

这可能怎么样?

推荐答案

您需要将发布操作绑定到您编写的自定义插件中。虽然这是要求标题,但这应该让你开始,你只需要检查是否分配了一个精选图像。

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 !' );
    }
}

请看( has_post_thumbnail($ post-> ID) )来确定帖子是否有一个精选图片。

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

这篇关于要求作者为后期设置精选图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆