Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/09/2015 03:31:18 PM (10 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-core/bp-core-catchuri.php

    r9664 r9723  
    259259        if ( 'members' == $match->key ) {
    260260
    261             // Viewing a specific user
    262             if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
    263 
     261            $after_member_slug = false;
     262            if ( ! empty( $bp_uri[ $uri_offset + 1 ] ) ) {
     263                $after_member_slug = $bp_uri[ $uri_offset + 1 ];
     264            }
     265
     266            // Are we viewing a specific user?
     267            if ( $after_member_slug ) {
    264268                // Switch the displayed_user based on compatibility mode
    265269                if ( bp_is_username_compatibility_mode() ) {
    266                     $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) );
     270                    $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) );
    267271                } else {
    268                     $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) );
     272                    $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( $after_member_slug );
    269273                }
    270 
    271                 if ( !bp_displayed_user_id() ) {
    272 
    273                     // Prevent components from loading their templates
    274                     $bp->current_component = '';
    275 
     274            }
     275
     276            // Is this a member type directory?
     277            if ( ! bp_displayed_user_id() && $after_member_slug === apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) ) && ! empty( $bp_uri[ $uri_offset + 2 ] ) ) {
     278                $matched_types = bp_get_member_types( array(
     279                    'has_directory'  => true,
     280                    'directory_slug' => $bp_uri[ $uri_offset + 2 ],
     281                ) );
     282
     283                if ( ! empty( $matched_types ) ) {
     284                    $bp->current_member_type = reset( $matched_types );
     285                    unset( $bp_uri[ $uri_offset + 1 ] );
     286                }
     287            }
     288
     289            // If the slug matches neither a member type nor a specific member, 404.
     290            if ( ! bp_displayed_user_id() && ! bp_get_current_member_type() && $after_member_slug ) {
     291                // Prevent components from loading their templates.
     292                $bp->current_component = '';
     293                bp_do_404();
     294                return;
     295            }
     296
     297            // If the displayed user is marked as a spammer, 404 (unless logged-in user is a super admin)
     298            if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) {
     299                if ( bp_current_user_can( 'bp_moderate' ) ) {
     300                    bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'warning' );
     301                } else {
    276302                    bp_do_404();
    277303                    return;
    278304                }
    279 
    280                 // If the displayed user is marked as a spammer, 404 (unless logged-
    281                 // in user is a super admin)
    282                 if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) {
    283                     if ( bp_current_user_can( 'bp_moderate' ) ) {
    284                         bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'warning' );
    285                     } else {
    286                         bp_do_404();
    287                         return;
    288                     }
    289                 }
    290 
    291                 // Bump the offset
     305            }
     306
     307            // Bump the offset.
     308            if ( bp_displayed_user_id() ) {
    292309                if ( isset( $bp_uri[$uri_offset + 2] ) ) {
    293310                    $bp_uri                = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
     
    299316                    $bp->current_component = '';
    300317                }
    301 
    302                 // Reset the offset
    303                 $uri_offset = 0;
    304             }
     318            }
     319
     320            // Reset the offset
     321            $uri_offset = 0;
    305322        }
    306323    }
Note: See TracChangeset for help on using the changeset viewer.