2015-12-16 171 views
0

我想限制作者的帖子,目前我允許2帖子沒有更多然後2帖子,目前我有幾個用戶有更多然後2帖子,所以我如何修復我的代碼,所以它不dont允許他們做更多的帖子。wordpress作者帖子數量限制

if ($post_count < 2) { 
     return TRUE; 
    } else { 
     echo 'You have already posted your maximum number of posts.'; 
     return FALSE; 
    } 
} 

正如我所說的幾個作者有超過2後,因此使用此代碼將允許他們做專,因爲如果西港島線,說明被繞過,因爲它的努力,因爲他們走過去,要檢測值2。

回答

0

您應該使用wp_insert_post_data過濾器。並在此過濾器中定義您的條件。 因此,這將是類似的東西:

add_filter('wp_insert_post_data', 'aa_func_20150916080916', 20, 2); 
function aa_func_20150916080916($data , $postarr) 
{ 
    $warn = "You have already posted your maximum number of posts"; 
    $current_user = get_current_user_id(); 
    $user_post_count = count_user_posts($current_user); 
    if($user_post_count >2) { 
    return wp_die($warn); 
    } 
    return $data; 
} 

請注意:它的快速的答案,你應該爲你的目的改變代碼。

Docs:https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data

相關問題