Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/03/2014 12:04:40 PM (12 years ago)
Author:
boonebgorges
Message:

Introduce 'no_access_url' param to bp_core_new_subnav_item()

bp_core_new_subnav_item() allows access to be controlled using the
'show_for_displayed_user' parameter. When this param is false for a given user,
the function attempts to determine a proper redirect URL. But this URL
determining logic assumes that we are looking at a user profile, while BP uses
bp_core_new_subnav_item() for group navigation as well. Rather than attempting
to bake more URL determination logic into bp_core_new_subnav_item() itself, we
introduce a 'no_access_url' parameter that allows calling functions to specify
dynamically the URL that users should be directed to when they do not have
permission to access a requested subnav item.

Fixes #5720

File:
1 edited

Legend:

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

    r8544 r8556  
    267267                'item_css_id'     => false, // The CSS ID to apply to the HTML of the nav item
    268268                'user_has_access' => true,  // Can the logged in user see this nav item?
     269                'no_access_url'   => '',
    269270                'site_admin_only' => false, // Can only site admins see this nav item?
    270271                'position'        => 90,    // Index of where this nav item should be positioned
    … …  
    303304                'position'        => $position,
    304305                'user_has_access' => $user_has_access,
     306                'no_access_url'   => $no_access_url,
    305307                'screen_function' => &$screen_function
    306308        );
    … …  
    376378                        $bp = buddypress();
    377379
    378                         // Redirect to the displayed user's default component
    379                         // If the displayed user is different from the logged-
    380                         // in user, we first check to ensure that the user has
    381                         // access to the default component
    382                         if ( bp_is_my_profile() || ! empty( $bp->bp_nav[ $bp->default_component ]['show_for_displayed_user'] ) ) {
     380                        // If a redirect URL has been passed to the subnav
     381                        // item, respect it
     382                        if ( ! empty( $subnav_item['no_access_url'] ) ) {
    383383                                $message     = __( 'You do not have access to this page.', 'buddypress' );
    384                                 $redirect_to = bp_displayed_user_domain();
    385 
    386                         // In some cases, the default tab is not accessible to
    387                         // the logged-in user. So we look for a fallback.
     384                                $redirect_to = trailingslashit( $subnav_item['no_access_url'] );
     385
     386                        // In the case of a user page, we try to assume a
     387                        // redirect URL
     388                        } else if ( bp_is_user() ) {
     389
     390                                // Redirect to the displayed user's default
     391                                // component, as long as that component is
     392                                // publicly accessible.
     393                                if ( bp_is_my_profile() || ! empty( $bp->bp_nav[ $bp->default_component ]['show_for_displayed_user'] ) ) {
     394                                        $message     = __( 'You do not have access to this page.', 'buddypress' );
     395                                        $redirect_to = bp_displayed_user_domain();
     396
     397                                // In some cases, the default tab is not accessible to
     398                                // the logged-in user. So we fall back on a tab that we
     399                                // know will be accessible.
     400                                } else {
     401                                        // Try 'activity' first
     402                                        if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
     403                                                $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() );
     404                                        // Then try 'profile'
     405                                        } else {
     406                                                $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) );
     407                                        }
     408
     409                                        $message     = '';
     410                                }
     411
     412                        // Fall back to the home page
    388413                        } else {
    389                                 // Try 'activity' first
    390                                 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
    391                                         $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() );
    392                                 // Then try 'profile'
    393                                 } else {
    394                                         $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) );
    395                                 }
    396 
    397                                 $message     = '';
     414                                $message     = __( 'You do not have access to this page.', 'buddypress' );
     415                                $redirect_to = bp_get_root_domain();
    398416                        }
    399417
Note: See TracChangeset for help on using the changeset viewer.