簡體   English   中英

如何限制用戶不創建新帖子 - Wordpress

[英]How can I restrict users not to create new posts - 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);
      }
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM