M_Blogcreation

The Membership 2 M Blogcreation class.

Defined (1)

The class is defined in the following location(s).

/app_old/membershipincludes/includes/default.rules.php  
  1. class M_Blogcreation extends M_Rule { 
  2.  
  3. var $name = 'blogcreation'; 
  4. var $label = 'Blog Creation'; 
  5. var $description = 'Allows the creation of blogs to be limited to members.'; 
  6.  
  7. var $rulearea = 'core'; 
  8.  
  9. function admin_main($data) { 
  10. if(!$data) $data = array(); 
  11. ?> 
  12. <div class='level-operation' id='main-blogcreation'> 
  13. <h2 class='sidebar-name'><?php _e('Blog Creation', 'membership');?><span><a href='#remove' id='remove-blogcreation' class='removelink' title='<?php _e("Remove Blog Creation from this rules area.", 'membership'); ?>'><?php _e('Remove', 'membership'); ?></a></span></h2> 
  14. <div class='inner-operation'> 
  15. <?php 
  16. if(!isset($data['number'])) { 
  17. $data['number'] = ''; 
  18. ?> 
  19. <p><strong><?php _e('Positive : ', 'membership'); ?></strong><?php _e('User can create ', 'membership'); ?><input type='text' name='blogcreation[number]' value='<?php echo esc_attr($data['number']); ?>' /><?php _e(' blogs.', 'membership'); ?><br/><em><?php _e('Leave blank for unlimited blogs.', 'membership'); ?></em></p> 
  20. <p><strong><?php _e('Negative : ', 'membership'); ?></strong><?php _e('User is unable to create any blogs.', 'membership'); ?></p> 
  21. <input type='hidden' name='blogcreation[]' value='yes' /> 
  22. </div> 
  23. </div> 
  24. <?php 
  25.  
  26. function on_creation() { 
  27.  
  28.  
  29. function on_positive($data) { 
  30.  
  31. $this->data = $data; 
  32.  
  33. add_filter( 'site_option_registration', array(&$this, 'pos_blog_creation')); 
  34. add_filter( 'wpmu_active_signup', array(&$this, 'pos_blog_creation') ); 
  35.  
  36. function on_negative($data) { 
  37.  
  38. $this->data = $data; 
  39.  
  40. add_filter( 'site_option_registration', array(&$this, 'neg_blog_creation')); 
  41. add_filter( 'wpmu_active_signup', array(&$this, 'neg_blog_creation') ); 
  42.  
  43.  
  44. function neg_blog_creation( $active = 'all' ) { 
  45.  
  46. if($active == 'user' || $active == 'none') { 
  47. return $active; 
  48. } else { 
  49. return 'none'; 
  50.  
  51.  
  52. function pos_blog_creation( $active = 'all' ) { 
  53.  
  54. if($active == 'user' || $active == 'none') { 
  55. return $active; 
  56. } else { 
  57. // Check our count 
  58. if(empty($this->data['number'])) { 
  59. // unlimited 
  60. return $active; 
  61. } else { 
  62. $thelimit = (int) $this->data['number']; 
  63.  
  64. if( $thelimit > (int) $this->current_blog_count() ) { 
  65. return $active; 
  66. } else { 
  67. return $this->neg_blog_creation( $active ); 
  68.  
  69.  
  70.  
  71. function current_blog_count() { 
  72.  
  73. global $member, $wpdb; 
  74.  
  75. if(!empty($member) && method_exists($member, 'has_cap')) { 
  76. // We have a member and it is a correct object 
  77. $count = 0; 
  78. $blogs = get_blogs_of_user( $member->ID ); 
  79. foreach( $blogs as $blog ) { 
  80. if( $this->is_user_blog_admin( $member->ID, $blog->userblog_id ) ) { 
  81. $count++; 
  82.  
  83. return (int) $count; 
  84. } else { 
  85. return 0; 
  86.  
  87.  
  88. function is_user_blog_admin( $user_id, $blog_id ) { 
  89. global $wpdb; 
  90.  
  91. $meta_key = $wpdb->base_prefix . $blog_id . "_capabilities"; 
  92.  
  93. $role_sql = $wpdb->prepare( "SELECT user_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key ); 
  94.  
  95. $role = $wpdb->get_results( $role_sql ); 
  96.  
  97. //clean the role 
  98. foreach($role as $key => $r) { 
  99. $role[$key]->meta_value = maybe_unserialize($r->meta_value); 
  100.  
  101. foreach($role as $key => $r) { 
  102. if( $r->meta_value['administrator'] == 1 && $r->user_id == $user_id ) { 
  103. return true; 
  104.  
  105. return false; 
  106.  
  107.