Changeset 5922 for trunk/bp-core/bp-core-buddybar.php
- Timestamp:
- 03/16/2012 12:30:11 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/bp-core/bp-core-buddybar.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-buddybar.php
r5895 r5922 1 1 <?php 2 3 /** 4 * Core BuddyPress Navigational Functions 5 * 6 * @package BuddyPress 7 * @subpackage Core 8 * @todo Deprecate BuddyBar functions 9 */ 10 2 11 // Exit if accessed directly 3 12 if ( !defined( 'ABSPATH' ) ) exit; … … 31 40 32 41 // If this is for site admins only and the user is not one, don't create the subnav item 33 if ( $site_admin_only&& !bp_current_user_can( 'bp_moderate' ) )42 if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) 34 43 return false; 35 44 … … 48 57 ); 49 58 50 /** *59 /** 51 60 * If this nav item is hidden for the displayed user, and 52 61 * the logged in user is not the displayed user 53 62 * looking at their own profile, don't create the nav item. 54 63 */ 55 if ( !$show_for_displayed_user&& !bp_user_has_access() )56 return false; 57 58 /** *64 if ( empty( $show_for_displayed_user ) && !bp_user_has_access() ) 65 return false; 66 67 /** 59 68 * If the nav item is visible, we are not viewing a user, and this is a root 60 69 * component, don't attach the default subnav function so we can display a … … 66 75 // Look for current component 67 76 if ( bp_is_current_component( $slug ) ) { 77 78 // The requested URL has explicitly included the default subnav (eg 79 // example.com/members/membername/activity/just-me/). The canonical 80 // version will not contain this subnav slug. 68 81 if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) ) { 69 // The requested URL has explicitly included the default subnav (eg70 // example.com/members/membername/activity/just-me/). The canonical71 // version will not contain this subnav slug.72 82 unset( $bp->canonical_stack['action'] ); 73 83 } else if ( !bp_current_action() ) { 74 if ( !is_object( $screen_function[0] ) ) 75 add_action( 'bp_screens', $screen_function ); 76 else 84 if ( is_object( $screen_function[0] ) ) { 77 85 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 ); 86 } else { 87 add_action( 'bp_screens', $screen_function, 3 ); 88 } 78 89 79 90 if ( !empty( $default_subnav_slug ) ) { 80 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );91 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r ); 81 92 } 82 93 } … … 84 95 // Look for current item 85 96 } elseif ( bp_is_current_item( $slug ) ) { 97 98 // The requested URL has explicitly included the default subnav 99 // (eg: http://example.com/members/membername/activity/just-me/) 100 // The canonical version will not contain this subnav slug. 86 101 if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) ) { 87 // The requested URL has explicitly included the default subnav (eg88 // example.com/members/membername/activity/just-me/). The canonical89 // version will not contain this subnav slug.90 102 unset( $bp->canonical_stack['action'] ); 91 103 } else if ( !bp_current_action() ) { 92 if ( !is_object( $screen_function[0] ) ) 93 add_action( 'bp_screens', $screen_function ); 94 else 104 if ( is_object( $screen_function[0] ) ) { 95 105 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 ); 96 106 } else { 107 add_action( 'bp_screens', $screen_function, 3 ); 108 } 109 97 110 if ( !empty( $default_subnav_slug ) ) { 98 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );111 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r ); 99 112 } 100 113 } … … 123 136 124 137 if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) { 125 if ( !is_object( $function[0] ) ) 138 if ( is_object( $function[0] ) ) { 139 remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 ); 140 } else { 126 141 remove_action( 'bp_screens', $function, 3 ); 127 else 128 remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 ); 142 } 129 143 } 130 144 … … 142 156 } 143 157 } 144 158 159 // No subnav item has been requested in the URL, so set a new nav default 145 160 if ( empty( $unfiltered_action ) ) { 146 // No subnav item has been requested in the URL, so set a new nav default147 161 if ( !bp_is_current_action( $subnav_slug ) ) { 148 if ( !is_object( $screen_function[0] ) ) {149 add_action( 'bp_screens', $screen_function);162 if ( is_object( $screen_function[0] ) ) { 163 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 ); 150 164 } else { 151 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ));165 add_action( 'bp_screens', $screen_function, 3 ); 152 166 } 153 167 … … 155 169 unset( $bp->canonical_stack['action'] ); 156 170 } 157 } else if ( $unfiltered_action == $subnav_slug ) { 158 // The URL is explicitly requesting the new subnav item, but should be 159 // directed to the canonical URL 171 172 // The URL is explicitly requesting the new subnav item, but should be 173 // directed to the canonical URL 174 } elseif ( $unfiltered_action == $subnav_slug ) { 160 175 unset( $bp->canonical_stack['action'] ); 176 177 // In all other cases (including the case where the original subnav item 178 // is explicitly called in the URL), the canonical URL will contain the 179 // subnav slug 161 180 } else { 162 // In all other cases (including the case where the original subnav item163 // is explicitly called in the URL), the canonical URL will contain the164 // subnav slug165 181 $bp->canonical_stack['action'] = bp_current_action(); 166 182 } 167 183 } 168 184 169 185 return; 170 186 } … … 184 200 185 201 foreach ( (array) $bp->bp_nav as $slug => $nav_item ) { 186 if ( empty( $temp[$nav_item['position']]) ) 202 if ( empty( $temp[$nav_item['position']]) ) { 187 203 $temp[$nav_item['position']] = $nav_item; 188 else {204 } else { 189 205 // increase numbers here to fit new items in. 190 206 do { … … 231 247 return false; 232 248 233 if ( empty( $link ) ) 249 // Link was not forced, so create one 250 if ( empty( $link ) ) { 234 251 $link = $parent_url . $slug; 235 252 253 // If this sub item is the default for its parent, skip the slug 254 if ( $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) { 255 $link = $parent_url; 256 } 257 } 258 236 259 // If this is for site admins only and the user is not one, don't create the subnav item 237 if ( $site_admin_only&& !bp_current_user_can( 'bp_moderate' ) )260 if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) ) 238 261 return false; 239 262 … … 257 280 * following two conditions: 258 281 * (1) Either: 259 * (a) the parent slug matches the current_component, or260 * (b) the parent slug matches the current_item282 * (a) the parent slug matches the current_component, or 283 * (b) the parent slug matches the current_item 261 284 * (2) And either: 262 * (a) the current_action matches $slug, or285 * (a) the current_action matches $slug, or 263 286 * (b) there is no current_action (ie, this is the default subnav for the parent nav) 264 287 * and this subnav item is the default for the parent item (which we check by … … 277 300 // Before hooking the screen function, check user access 278 301 if ( !empty( $user_has_access ) ) { 279 if ( !is_object( $screen_function[0] ) ) {280 add_action( 'bp_screens', $screen_function);302 if ( is_object( $screen_function[0] ) ) { 303 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 ); 281 304 } else { 282 add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ));305 add_action( 'bp_screens', $screen_function, 3 ); 283 306 } 284 307 } else { 285 // When the content is off-limits, we handle the situation differently 286 // depending on whether the current user is logged in 308 309 // When the content is off-limits, we handle the situation 310 // differently depending on whether the current user is logged in 287 311 if ( is_user_logged_in() ) { 288 if ( !bp_is_my_profile() && !$bp->bp_nav[$bp->default_component]['show_for_displayed_user'] ) { 312 if ( !bp_is_my_profile() && empty( $bp->bp_nav[$bp->default_component]['show_for_displayed_user'] ) ) { 313 289 314 // This covers the edge case where the default component is 290 315 // a non-public tab, like 'messages' … … 307 332 'redirect' => false 308 333 ) ); 334 335 // Not logged in. Allow the user to log in, and attempt to redirect 309 336 } else { 310 // Not logged in. Allow the user to log in, and attempt to redirect311 337 bp_core_no_access(); 312 338 } … … 383 409 384 410 if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) { 385 if ( !is_object( $function[0] ) ) {386 remove_action( 'bp_screens', $function);411 if ( is_object( $function[0] ) ) { 412 remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 ); 387 413 } else { 388 remove_action( 'bp_screens', array( &$function[0], $function[1] ));414 remove_action( 'bp_screens', $function, 3 ); 389 415 } 390 416 } … … 403 429 global $bp; 404 430 405 $screen_function = ( isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false; 406 407 if ( $screen_function ) { 408 if ( !is_object( $screen_function[0] ) ) 409 remove_action( 'bp_screens', $screen_function ); 410 else 411 remove_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) ); 431 $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false; 432 433 if ( !empty( $screen_function ) ) { 434 if ( is_object( $screen_function[0] ) ) { 435 remove_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 ); 436 } else { 437 remove_action( 'bp_screens', $screen_function, 3 ); 438 } 412 439 } 413 440 … … 439 466 return false; 440 467 441 if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )468 if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) 442 469 return false; 443 470
Note: See TracChangeset
for help on using the changeset viewer.