Created
October 25, 2013 12:26
-
-
Save palpalani/7153895 to your computer and use it in GitHub Desktop.
Limit number of posts an user can create in WordPress admin panel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* If you, by any chance, want to limit the number of posts an user can create in your multi author WordPress blog, there is a nice way to do it. Add the following code in your theme’s functions.php file | |
*/ | |
add_action("load-post-new.php","limit_user_by_post_count"); | |
function limit_user_by_post_count(){ | |
$user = get_current_user_id(); | |
if (!current_user_can( 'manage_options')) { | |
//not an admin - so impose the limit | |
$user_post_count = count_user_posts($user); | |
if($user_post_count>=10) | |
header("Location: /wp-admin/edit.php"); | |
} | |
} | |
/* | |
* In this example, if the user has 10 posts he/she can not create a new post anymore. Every time he clicks on the “New Post” menu, he will be redirected to 'All Posts' page. But the 'admin' will not be limited at all :) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yasko88 i was posted this long back. After that, I am not working with WordPress.
Please check with this author: https://hasin.me/2013/10/25/limit-number-of-posts-an-user-can-create-in-wordpress-admin-panel/