Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/04/2014 01:47:49 AM (10 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-members/bp-members-template.php

    r9189 r9210  
    222222     * @see BP_User_Query for an in-depth description of parameters.
    223223     *
    224      * @param string $type Sort order.
    225      * @param int $page_number Page of results.
    226      * @param int $per_page Number of results per page.
    227      * @param int $max Max number of results to return.
    228      * @param int $user_id Limit to friends of a user.
    229      * @param string $search_terms Limit to users matching search terms.
    230      * @param array $include Limit results by these user IDs.
    231      * @param bool $populate_extras Fetch optional extras.
    232      * @param array $exclude Exclude these IDs from results.
    233      * @param array $meta_key Limit to users with a meta_key.
    234      * @param array $meta_value Limit to users with a meta_value (with meta_key).
    235      * @param array $page_arg Optional. The string used as a query
    236      *        parameter in pagination links. Default: 'upage'.
    237      */
    238     function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage' ) {
     224     * @param string       $type            Sort order.
     225     * @param int          $page_number     Page of results.
     226     * @param int          $per_page        Number of results per page.
     227     * @param int          $max             Max number of results to return.
     228     * @param int          $user_id         Limit to friends of a user.
     229     * @param string       $search_terms    Limit to users matching search terms.
     230     * @param array        $include         Limit results by these user IDs.
     231     * @param bool         $populate_extras Fetch optional extras.
     232     * @param array        $exclude         Exclude these IDs from results.
     233     * @param array        $meta_key        Limit to users with a meta_key.
     234     * @param array        $meta_value      Limit to users with a meta_value (with meta_key).
     235     * @param array        $page_arg        Optional. The string used as a query parameter in pagination links.
     236     *                                      Default: 'upage'.
     237     * @param array|string $member_type     Array or comma-separated string of member types to limit results to.
     238     */
     239    function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '' ) {
    239240
    240241        $this->pag_page = !empty( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : (int) $page_number;
     
    245246            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude );
    246247        else
    247             $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value ) );
     248            $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type ) );
    248249
    249250        if ( !$max || $max >= (int) $this->members['total'] )
     
    399400 *     string (eg, 'user_id=4&per_page=3').
    400401 *
    401  *     @type int $type Sort order. 'active', 'random', 'newest', 'popular',
    402  *           'online', 'alphabetical'. Default: 'active'.
    403  *     @type int|bool $page Page of results to display. Default: 1.
    404  *     @type int|bool $per_page Number of results per page. Default: 20.
    405  *     @type int|bool $max Maximum number of results to return.
    406  *           Default: false (unlimited).
    407  *     @type string $page_arg The string used as a query parameter in
    408  *           pagination links. Default: 'bpage'.
    409  *     @type array|int|string|bool $include Limit results by a list of user
    410  *           IDs. Accepts an array, a single integer, a comma-separated list of
    411  *           IDs, or false (to disable this limiting). Default: false.
    412  *       'active', 'alphabetical', 'newest', or 'random'.
    413  *     @type array|int|string|bool $exclude Exclude users from results by ID.
    414  *           Accepts an array, a single integer, a comma-separated list of
    415  *           IDs, or false (to disable this limiting). Default: false.
    416  *     @type int $user_id If provided, results are limited to the friends of
    417  *           the specified user. When on a user's Friends page, defaults to
    418  *           the ID of the displayed user. Otherwise defaults to 0.
    419  *     @type string $search_terms Limit results by a search term. Default: null.
    420  *     @type string $meta_key Limit results by the presence of a usermeta key.
     402 *     @type int                   $type            Sort order. Accepts 'active', 'random', 'newest', 'popular',
     403 *                                                  'online', 'alphabetical'. Default: 'active'.
     404 *     @type int|bool              $page            Page of results to display. Default: 1.
     405 *     @type int|bool              $per_page        Number of results per page. Default: 20.
     406 *     @type int|bool              $max             Maximum number of results to return. Default: false (unlimited).
     407 *     @type string                $page_arg        The string used as a query parameter in pagination links.
     408 *                                                  Default: 'bpage'.
     409 *     @type array|int|string|bool $include         Limit results by a list of user IDs. Accepts an array, a
     410 *                                                  single integer, a comma-separated list of IDs, or false (to
     411 *                                                  disable this limiting). Accepts 'active', 'alphabetical',
     412 *                                                  'newest', or 'random'. Default: false.
     413 *     @type array|int|string|bool $exclude         Exclude users from results by ID. Accepts an array, a single
     414 *                                                  integer, a comma-separated list of IDs, or false (to disable
     415 *                                                  this limiting). Default: false.
     416 *     @type int                   $user_id         If provided, results are limited to the friends of the specified
     417 *                                                  user. When on a user's Friends page, defaults to the ID of the
     418 *                                                  displayed user. Otherwise defaults to 0.
     419 *     @type string|array          $member_type     Array or comma-separated list of member types to limit results to.
     420 *     @type string                $search_terms    Limit results by a search term. Default: null.
     421 *     @type string                $meta_key        Limit results by the presence of a usermeta key.
    421422 *           Default: false.
    422  *     @type mixed $meta_value When used with meta_key, limits results by the
     423 *     @type mixed                 $meta_value      When used with meta_key, limits results by the
    423424 *           a matching usermeta value. Default: false.
    424  *     @type bool $populate_extras Whether to fetch optional data, such as
     425 *     @type bool                  $populate_extras Whether to fetch optional data, such as
    425426 *           friend counts. Default: true.
    426427 * }
     
    451452
    452453        'user_id'         => $user_id, // Pass a user_id to only show friends of this user
     454        'member_type'     => '',
    453455        'search_terms'    => null,     // Pass search_terms to filter users by their profile data
    454456
     
    486488        $r['meta_key'],
    487489        $r['meta_value'],
    488         $r['page_arg']
     490        $r['page_arg'],
     491        $r['member_type']
    489492    );
    490493
Note: See TracChangeset for help on using the changeset viewer.