Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to limit how many pages a user can make inside a custom post type? This would be pretty effective for commercial WP plugins and I am making one, but have come across a little problem and I would need to figure out how to do this. Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Check out my plugin Bainternet Posts Creation Limits this plugin helps you to limit the number of posts/pages/custom post types each user can create on your site. Its just what you need.

Update

open up bapl.php and in bapl_limit_post_count function change on line 44:

if ( current_user_can('manage_options') ) {}else{ 
            if (isset($postt[$curent_type])){
                //$postt= bapl_getOptions('bapl');
                foreach ($postt as $key => $option){
                    if ($key = $curent_type) {
                        $ptname = $key;
                        $limit = $option;
                        break;
                    }
                }
                //print_r($postt);
                $count_posts = count(get_posts(array('author'=>$current_user->ID,'post_type',$ptname)));

                if ($count_posts >= $limit){
                    //wp_die( __('You Can\'t Create any more pages of this type.') );
                    bapl_not_allowed();
                    exit;
                }
            }
        }

to:

        if (isset($postt[$curent_type])){
            foreach ($postt as $key => $option){
                if ($key = $curent_type) {
                    $ptname = $key;
                    $limit = $option;
                    break;
                }
            }
            $count_posts = count(get_posts(array('author'=>$current_user->ID,'post_type',$ptname)));

            if ($count_posts >= $limit){

                bapl_not_allowed();
                exit;
            }
        }

this way the admin is limited too.

Next you will need to change bapl_getOptions function and set you defaults there. And last you will probably wont to remove the admin control panel of this plugin so comment out line 69 were it says :

add_action('admin_menu', 'bapl_menu');
share|improve this answer
    
Excellent! I notice it says not to try it with the admin user, as they are never limited. Is there any way to override that? For a commercial plugin, for example my plugin, I will have different license types. The Single use license will only allow about 10 posts. The developer license will be unlimited. This will always be for the admin user. –  Jared Mar 18 '11 at 7:32
    
Yes you can do that and its quite simple , i will look at the code when i get home and update my answer. –  Bainternet Mar 18 '11 at 7:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.