[buddypress-trac] [BuddyPress] #4482: Better member type support in bp_group_has_members()

buddypress-trac noreply at wordpress.org
Wed May 15 05:52:14 UTC 2013


#4482: Better member type support in bp_group_has_members()
--------------------------+---------------------------
 Reporter:  boonebgorges  |       Owner:  boonebgorges
     Type:  enhancement   |      Status:  assigned
 Priority:  high          |   Milestone:  1.8
Component:  Groups        |     Version:
 Severity:  major         |  Resolution:
 Keywords:  needs-patch   |
--------------------------+---------------------------

Comment (by trishasalas):

 I may be way off base so I'm going to go ahead and post what I have so as
 not to waste time.  I'll look at it again in the morning and I'll be here
 for devchat.  boonegorges, if OOP is the direction you are going with
 BuddyPress php this is encouraging.  I am starting to take classes to fill
 in the gaps with what I know and OOP has made the most sense but doesn't
 always seem to fit with WordPress.  Let me know if this is an accurate
 assessment on my part.  I have just signed up for a class in Plugin
 Development with Tom McFarlin so I'll likely do a bit of both.

 Here is what I have so far...clueless as to how to submit a patch...unless
 this is that ;)


 {{{
 <?php


 class BP_User_Query {
      // ...
      public function get_include_ids() {
          return wp_parse_id_list( $this->query_vars['include'] );
      }
  }

  // and then the extending class

  class BP_Group_Member_Query extends BP_User_Query {

      public function get_include_ids() {

          // Passed to 'include'

          $include = wp_parse_id_list( $this->query_vars['include'] );

          // Figure out what user type is currently being requested

          if ( isset( $this->query_vars['group_id'] ) && isset(

  $this->query_vars['group_role'] ) ) {

              $group_members = $this->get_group_members_by_role(

  $this->query_vars['group_id'], $this->query_vars['group_role'] );

          }

          // Put them together
          return array_intersect( $include, $group_members );
      }

      protected function get_group_members_by_role( $group_id, $group_role
 )
  {
          //Get the group Admins

 {               {
                 $this->uid_name = 'user_id';
                 $sql['select'] = "SELECT {$this->user_id} FROM
 {$wpdb->bp_groups}";
                 $sql['where'][] = $wpdb->prepare( "group_id = %s",
 group_id( $group_id ) ); //I'm not sure how to pass the group_id variable
 here

                                 if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_admin( 1 ) );
                                         $group_role = 'admin';
                                 } else if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_admin( 0 ) );
                                         return;
                                 }

                 //Get the group Moderators


                 $this->uid_name = 'user_id';
                 $sql['select'] = "SELECT {$this->user_id} FROM
 {$wpdb->bp_groups}";
                 $sql['where'][] = $wpdb->prepare( "group_id = %s",
 group_id( $group_id ) ); //I'm not sure how to pass the group_id variable
 here

                                 if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_mod( 1 ) );
                                         $group_role = 'moderator';
                                 } else if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_mod( 0 ) );
                                         return;
                                 }

                 //Get Banned Members


                 $this->uid_name = 'user_id';
                 $sql['select'] = "SELECT {$this->user_id} FROM
 {$wpdb->bp_groups}";
                 $sql['where'][] = $wpdb->prepare( "group_id = %s",
 group_id( $group_id ) ); //I'm not sure how to pass the group_id variable
 here

                                 if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_banned( 1 ) );
                                         $group_role = 'banned';
                                 } else if  {
                                         $sql['where'][] = $wpdb->prepare(
 is_banned( 0 ) );
                                         return;
                                 }
         }

      }
  }
  //I'm also assuming here that the $group_id variable is defined
 previously in the page as it is currently
 }}}

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4482#comment:11>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list