我如何限制用户不创建新帖子-Wordpress



当有人点击添加新帖子时,会出现一条消息,类似于"你不被允许创建帖子";用户也不允许发布或起草帖子。

我试过这个代码-:

function post_published_limit( $ID, $post ) {
$max_posts = 5; // change this or set it as an option that you can retrieve.
$author = $post->post_author; // Post author ID.
$count = count_user_posts( $author, 'post'); // get author post count
if ( $count > $max_posts ) {
// count too high, let's set it to draft.
$post->post_status = 'draft';
wp_update_post( $post);
}
}
add_action( 'publish_post', 'post_published_limit', 10, 2 );

这个代码帮助我不发布帖子,但它创建了这些帖子的草稿。

我不太明白你的意思,但我认为这会奏效。

function post_published_limit( $ID, $post ) {
global $current_user; 
get_currentuserinfo(); 
if ( user_can( $current_user, "administrator" ) ){ 
$max_posts = 5; 
$author = $post->post_author; // Post author ID.
$count = count_user_posts( $author, 'post'); 
if ( $count > $max_posts ) {
$post->post_status = 'draft';
wp_update_post( $post);
}
}
}

相关内容

  • 没有找到相关文章

最新更新