Advertisement
Guest User

Untitled

a guest
Sep 6th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. $limits = array(
  2. '0' => array(
  3. 'post' => 5, 'page' => 10
  4. ),
  5. '1' => array(
  6. 'post' => 6, 'page' => 30
  7. ),
  8. '2' => array(
  9. 'post' => 25, 'page' => 30
  10. ),
  11. );
  12.  
  13. add_filter( 'user_has_cap', 'check_pro_limit', 999, 3 );
  14. function check_pro_limit( $allcaps, $caps, $args ) {
  15. $id = get_current_blog_id();
  16. global $psts, $limits;
  17. if( $id != 1 ){
  18. $level = $psts->get_level($id);
  19. if( is_array( $limits[$level - 1] ) )
  20. foreach ($limits[$level - 1] as $post_type => $settings) {
  21. if ( wp_count_posts($post_type)->publish >= $settings ) {
  22. $pt_obj = get_post_type_object($post_type);
  23. unset($allcaps[$pt_obj->cap->publish_posts]);
  24. }
  25. }
  26. }
  27. return $allcaps;
  28. }
  29.  
  30. add_action( 'admin_notices', 'message_notice' );
  31. function message_notice() {
  32. $id = get_current_blog_id();
  33. global $psts, $limits;
  34. if( $id != 1 ){
  35. $level = $psts->get_level($id);
  36. $screen = get_current_screen();
  37. switch( $screen->post_type ){
  38. case 'post':
  39. $published_posts = wp_count_posts( 'post' )->publish;
  40. if( $published_posts >= $limits[$level - 1]['post'] ){
  41. ?>
  42. <div class='error'>
  43. <p>Please upgrade to publish more posts.</p>
  44. </div>
  45. <?php
  46. }
  47. break;
  48.  
  49. case 'page':
  50. $published_posts = wp_count_posts( 'page' )->publish;
  51. if( $published_posts >= $limits[$level - 1]['page'] ){
  52. ?>
  53. <div class='error'>
  54. <p>Please upgrade to publish more pages.</p>
  55. </div>
  56. <?php
  57. }
  58. break;
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement