Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $limits = array(
- '0' => array(
- 'post' => 5, 'page' => 10
- ),
- '1' => array(
- 'post' => 6, 'page' => 30
- ),
- '2' => array(
- 'post' => 25, 'page' => 30
- ),
- );
- add_filter( 'user_has_cap', 'check_pro_limit', 999, 3 );
- function check_pro_limit( $allcaps, $caps, $args ) {
- $id = get_current_blog_id();
- global $psts, $limits;
- if( $id != 1 ){
- $level = $psts->get_level($id);
- if( is_array( $limits[$level - 1] ) )
- foreach ($limits[$level - 1] as $post_type => $settings) {
- if ( wp_count_posts($post_type)->publish >= $settings ) {
- $pt_obj = get_post_type_object($post_type);
- unset($allcaps[$pt_obj->cap->publish_posts]);
- }
- }
- }
- return $allcaps;
- }
- add_action( 'admin_notices', 'message_notice' );
- function message_notice() {
- $id = get_current_blog_id();
- global $psts, $limits;
- if( $id != 1 ){
- $level = $psts->get_level($id);
- $screen = get_current_screen();
- switch( $screen->post_type ){
- case 'post':
- $published_posts = wp_count_posts( 'post' )->publish;
- if( $published_posts >= $limits[$level - 1]['post'] ){
- ?>
- <div class='error'>
- <p>Please upgrade to publish more posts.</p>
- </div>
- <?php
- }
- break;
- case 'page':
- $published_posts = wp_count_posts( 'page' )->publish;
- if( $published_posts >= $limits[$level - 1]['page'] ){
- ?>
- <div class='error'>
- <p>Please upgrade to publish more pages.</p>
- </div>
- <?php
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement