Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/04/2014 01:47:49 AM (11 years ago)
Author:
boonebgorges
Message:

Introduce Member Types API.

BuddyPress member types are akin to WordPress's custom post types. Developers
can use bp_register_member_type() to register their types with BuddyPress,
and BP will automatically provide a number of pieces of functionality:

  • Mechanisms for storing and fetching member types (as a WP taxonomy term), with full cache support.
  • A 'member_type' argument for the bp_has_members()/BP_User_Query stack, which allows filtering member loops by member type.
  • Admin UI for changing member types on Dashboard > Users > Community Profile (appears when member types have been registered).

We'll continue to build out more core member type functionality in future
versions of BuddyPress. In the meantime, this is a good starting point for BP
site implementations to have a shared infrastructure for storing and retrieving
this data.

See #6006.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-classes.php

    r9178 r9210  
    3838 *                                              override all others; BP User objects will be constructed using these
    3939 *                                              IDs only. Default: false.
     40 *     @type array|string      $member_type     Array or comma-separated list of member types to limit results to.
    4041 *     @type string|bool       $meta_key        Limit results to users that have usermeta associated with this meta_key.
    4142 *                                              Usually used with $meta_value. Default: false.
     
    165166                'exclude'         => false,
    166167                'user_ids'        => false,
     168                'member_type'     => '',
    167169                'meta_key'        => false,
    168170                'meta_value'      => false,
     
    400402                $search_terms_space
    401403            );
     404        }
     405
     406        // Member type.
     407        if ( ! empty( $member_type ) ) {
     408            $member_types = array();
     409
     410            if ( ! is_array( $member_type ) ) {
     411                $member_type = preg_split( '/[,\s+]/', $member_type );
     412            }
     413
     414            foreach ( $member_type as $mt ) {
     415                if ( ! bp_get_member_type_object( $mt ) ) {
     416                    continue;
     417                }
     418
     419                $member_types[] = $mt;
     420            }
     421
     422            if ( ! empty( $member_types ) ) {
     423                $member_type_tq = new WP_Tax_Query( array(
     424                    array(
     425                        'taxonomy' => 'bp_member_type',
     426                        'field'    => 'name',
     427                        'operator' => 'IN',
     428                        'terms'    => $member_types,
     429                    ),
     430                ) );
     431
     432                // Switch to the root blog, where member type taxonomies live.
     433                switch_to_blog( bp_get_root_blog_id() );
     434
     435                $member_type_sql_clauses = $member_type_tq->get_sql( 'u', $this->uid_name );
     436                restore_current_blog();
     437
     438
     439                // Grab the first term_relationships clause and convert to a subquery.
     440                if ( preg_match( '/' . $wpdb->term_relationships . '\.term_taxonomy_id.*/', $member_type_sql_clauses['where'], $matches ) ) {
     441                    $sql['where']['member_type'] = "u.{$this->uid_name} IN ( SELECT object_id FROM $wpdb->term_relationships WHERE {$matches[0]} )";
     442                }
     443            }
    402444        }
    403445
Note: See TracChangeset for help on using the changeset viewer.