Ticket #5720: 5720.break-up-bp_core_new_subnav_item.patch
File 5720.break-up-bp_core_new_subnav_item.patch, 5.2 KB (added by , 10 years ago) |
---|
-
src/bp-core/bp-core-buddybar.php
diff --git src/bp-core/bp-core-buddybar.php src/bp-core/bp-core-buddybar.php index 89e3934..a854fd3 100644
function bp_core_new_subnav_item( $args = '' ) { 295 295 if ( empty( $item_css_id ) ) 296 296 $item_css_id = $slug; 297 297 298 $ bp->bp_options_nav[$parent_slug][$slug]= array(298 $subnav_item = array( 299 299 'name' => $name, 300 300 'link' => trailingslashit( $link ), 301 301 'slug' => $slug, … … function bp_core_new_subnav_item( $args = '' ) { 304 304 'user_has_access' => $user_has_access, 305 305 'screen_function' => &$screen_function 306 306 ); 307 $bp->bp_options_nav[$parent_slug][$slug] = $subnav_item; 307 308 308 309 /** 309 310 * The last step is to hook the screen function for the added subnav item. But this only … … function bp_core_new_subnav_item( $args = '' ) { 329 330 // If we *do* meet condition (2), then the added subnav item is currently being requested 330 331 if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) { 331 332 332 // Before hooking the screen function, check user access 333 if ( !empty( $user_has_access ) ) { 334 // Add our screen hook if screen function is callable 335 if ( is_callable( $screen_function ) ) { 336 add_action( 'bp_screens', $screen_function, 3 ); 337 } 333 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 334 335 // If redirect args have been returned, perform the redirect now 336 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 337 bp_core_no_access( $hooked['redirect_args'] ); 338 } 339 } 340 } 341 342 /** 343 * For a given subnav item, either hook the screen function or generate redirect arguments, as necessary. 344 * 345 * @since BuddyPress (2.1.0) 346 * 347 * @param array $subnav_item The subnav array added to bp_options_nav in 348 * bp_core_new_subnav_item(). 349 * @return array 350 */ 351 function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 352 $retval = array( 353 'status' => '', 354 ); 355 356 // User has access, so let's try to hook the display callback 357 if ( ! empty( $subnav_item['user_has_access'] ) ) { 358 359 // Screen function is invalid 360 if ( ! is_callable( $subnav_item['screen_function'] ) ) { 361 $retval['status'] = 'failure'; 362 363 // Success - hook to bp_screens 338 364 } else { 365 add_action( 'bp_screens', $subnav_item['screen_function'], 3 ); 366 $retval['status'] = 'success'; 367 } 339 368 340 // When the content is off-limits, we handle the situation341 // differently depending on whether the current user is logged in342 if ( is_user_logged_in() ){343 if ( !bp_is_my_profile() && empty( $bp->bp_nav[$bp->default_component]['show_for_displayed_user'] ) ) {369 // User doesn't have access. Determine redirect arguments based on 370 // user status 371 } else { 372 $retval['status'] = 'failure'; 344 373 345 // This covers the edge case where the default component is 346 // a non-public tab, like 'messages' 347 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 348 $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ); 349 } else { 350 $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) ); 351 } 374 if ( is_user_logged_in() ) { 352 375 353 $message = ''; 354 } else { 355 $message = __( 'You do not have access to this page.', 'buddypress' ); 356 $redirect_to = bp_displayed_user_domain(); 357 } 376 $bp = buddypress(); 358 377 359 // Off-limits to this user. Throw an error and redirect to the displayed user's domain 360 bp_core_no_access( array( 361 'message' => $message, 362 'root' => $redirect_to, 363 'redirect' => false 364 ) ); 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'] ) ) { 383 $message = __( 'You do not have access to this page.', 'buddypress' ); 384 $redirect_to = bp_displayed_user_domain(); 365 385 366 // Not logged in. Allow the user to log in, and attempt to redirect 386 // In some cases, the default tab is not accessible to 387 // the logged-in user. So we look for a fallback. 367 388 } else { 368 bp_core_no_access(); 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 = ''; 369 398 } 399 400 $retval['redirect_args'] = array( 401 'message' => $message, 402 'root' => $redirect_to, 403 'redirect' => false, 404 ); 405 406 } else { 407 // When the user is logged out, pass an empty array 408 // This indicates that the default arguments should be 409 // used in bp_core_no_access() 410 $retval['redirect_args'] = array(); 370 411 } 371 412 } 413 414 return $retval; 372 415 } 373 416 374 417 /**