Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/09/2015 03:31:18 PM (5 years ago)
Author:
boonebgorges
Message:

Introduce member-type-specific Members directories.

The new 'has_directory' argument for bp_register_member_type() allows
developers to specify whether a list of members matching a given type 'foo'
should be available at http://example.com/members/type/foo/. A slug can be
passed to 'has_directory' to customize the URL used for the member type's
directory.

Note that plugins registering member types must do so at the new hook
'bp_register_member_types' in order to be able to customize the 'has_directory'
value (from its default of true).

bp_has_members() automatically detects the presence of a member type in a
URL. When no member type of the form example.com/members/type/foo/ is found,
URLs of the form example.com/members/?member_type=foo will be detected.

See #6286.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r9625 r9723  
    24522452 *     Array of arguments describing the member type.
    24532453 *
    2454  *     @type array $labels {
     2454 *     @type array       $labels {
    24552455 *         Array of labels to use in various parts of the interface.
    24562456 *
     
    24582458 *         @type string $singular_name Singular name.
    24592459 *     }
     2460 *     @type bool|string $has_directory Whether the member type should have its own type-specific directory.
     2461 *                                      Pass `true` to use the `$member_type` string as the type's slug.
     2462 *                                      Pass a string to customize the slug. Pass `false` to disable.
     2463 *                                      Default: true.
    24602464 * }
    24612465 * @return object|WP_Error Member type object on success, WP_Error object on failure.
     
    24692473
    24702474    $r = bp_parse_args( $args, array(
    2471         'labels' => array(),
     2475        'labels'        => array(),
     2476        'has_directory' => true,
    24722477    ), 'register_member_type' );
    24732478
     
    24832488        'singular_name' => $default_name,
    24842489    ), $r['labels'] );
     2490
     2491    // Directory slug.
     2492    if ( $r['has_directory'] ) {
     2493        // A string value is intepreted as the directory slug. Otherwise fall back on member type.
     2494        if ( is_string( $r['has_directory'] ) ) {
     2495            $directory_slug = $r['has_directory'];
     2496        } else {
     2497            $directory_slug = $member_type;
     2498        }
     2499
     2500        // Sanitize for use in URLs.
     2501        $r['directory_slug'] = sanitize_title( $directory_slug );
     2502        $r['has_directory']  = true;
     2503    } else {
     2504        $r['directory_slug'] = '';
     2505        $r['has_directory']  = false;
     2506    }
    24852507
    24862508    $bp->members->types[ $member_type ] = $type = (object) $r;
     
    27152737add_action( 'wpmu_delete_user', 'bp_remove_member_type_on_user_delete' );
    27162738add_action( 'delete_user', 'bp_remove_member_type_on_user_delete' );
     2739
     2740/**
     2741 * Get the "current" member type, if one is provided, in member directories.
     2742 *
     2743 * @since BuddyPress (2.3.0)
     2744 *
     2745 * @return string
     2746 */
     2747function bp_get_current_member_type() {
     2748    return apply_filters( 'bp_get_current_member_type', buddypress()->current_member_type );
     2749}
Note: See TracChangeset for help on using the changeset viewer.