[wp-hackers] Limit a user to write just 10 posts

Webmaster - gmcosta.com webmaster at gmcosta.com
Thu Mar 27 20:18:27 GMT 2008

I'm trying to do a plugin to limit a user to post only (a number of posts determined and changeble by me).
I'm using wordpress 2.3.3 with Role Manager latest version, and Custom Write Panel.
I created a role with a custom capability to let that role access the Custom Write Panel.

When the user try to access the Custom Write Panel to post something, the plugin has to check if the user has wrote more than the allowed posts by the plugin.
If the write post limit it's more than allowed, the wordpress doesn't show de the custom write panel and doesn't let the user add posts.

How I'm studyng php so I tryed to create something but it became a mass.
Any one could give me a hand on this, or try to give me some links to get this work?
Thanks for all.

THE CODE it's bellow:

/*Plugin Name: UPA Users Posts Allowed */

block_post_write() {
remove_cap('job', 'edit_posts');
remove_cap('job', 'upload_files');
remove_cap('job', 'imovel');
echo '<p>You does not have permission to write a new post. Call the administrator of the site to get permission again. Thank you!</p>';

add_action('publish_post', 'limit_post_write');

function limit_post_write(){
$user_total_posts_wrote = get_usernumposts($user->ID);
if($user_total_posts_wrote >= 3) {
$block = block_post_write();
echo $block;
return block_post_write();

Giovanni M.Costa

More information about the wp-hackers mailing list