Limit number of posts an user can create in WordPress admin panel

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 :)

Sweet, eh?

About these ads

2 thoughts on “Limit number of posts an user can create in WordPress admin panel

  1. Can this be modified to limit the number of published posts a user can create? Eg. Unlimited drafts but runs a check on save and if X posts are already published then error message?

  2. Hi :)
    Could you help to change this code to limit the number of Custom Post Types an user can create? I’m looking for a simple solution, like this above. Thank You!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s