Changeset 10356 for trunk/src/bp-core/bp-core-buddybar.php
- Timestamp:
- 11/15/2015 07:57:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-buddybar.php
r10326 r10356 34 34 35 35 $defaults = array( 36 'name' => false, // Display name for the nav item 37 'slug' => false, // URL slug for the nav item 38 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 36 'name' => false, // Display name for the nav item. 37 'slug' => false, // URL slug for the nav item. 38 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 39 39 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 40 40 'site_admin_only' => false, // Can only site admins see this nav item? 41 'position' => 99, // Index of where this nav item should be positioned 42 'screen_function' => false, // The name of the function to run when clicked 43 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 41 'position' => 99, // Index of where this nav item should be positioned. 42 'screen_function' => false, // The name of the function to run when clicked. 43 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 44 44 ); 45 45 … … 103 103 104 104 $defaults = array( 105 'name' => false, // Display name for the nav item 106 'slug' => false, // URL slug for the nav item 107 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 105 'name' => false, // Display name for the nav item. 106 'slug' => false, // URL slug for the nav item. 107 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 108 108 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 109 109 'site_admin_only' => false, // Can only site admins see this nav item? 110 'position' => 99, // Index of where this nav item should be positioned 111 'screen_function' => false, // The name of the function to run when clicked 112 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 110 'position' => 99, // Index of where this nav item should be positioned. 111 'screen_function' => false, // The name of the function to run when clicked. 112 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 113 113 ); 114 114 … … 178 178 179 179 $defaults = array( 180 'name' => false, // Display name for the nav item 181 'slug' => false, // URL slug for the nav item 182 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 180 'name' => false, // Display name for the nav item. 181 'slug' => false, // URL slug for the nav item. 182 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 183 183 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 184 184 'site_admin_only' => false, // Can only site admins see this nav item? 185 'position' => 99, // Index of where this nav item should be positioned 186 'screen_function' => false, // The name of the function to run when clicked 187 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked 185 'position' => 99, // Index of where this nav item should be positioned. 186 'screen_function' => false, // The name of the function to run when clicked. 187 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 188 188 ); 189 189 … … 221 221 } 222 222 223 // Look for current component 223 // Look for current component. 224 224 if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) { 225 225 … … 231 231 } elseif ( ! bp_current_action() ) { 232 232 233 // Add our screen hook if screen function is callable 233 // Add our screen hook if screen function is callable. 234 234 if ( is_callable( $r['screen_function'] ) ) { 235 235 add_action( 'bp_screens', $r['screen_function'], 3 ); … … 278 278 279 279 $defaults = array( 280 'parent_slug' => false, // Slug of the parent 281 'screen_function' => false, // The name of the function to run when clicked 282 'subnav_slug' => false // The slug of the subnav item to select when clicked 280 'parent_slug' => false, // Slug of the parent. 281 'screen_function' => false, // The name of the function to run when clicked. 282 'subnav_slug' => false // The slug of the subnav item to select when clicked. 283 283 ); 284 284 … … 286 286 287 287 if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) { 288 // Remove our screen hook if screen function is callable 288 // Remove our screen hook if screen function is callable. 289 289 if ( is_callable( $function ) ) { 290 290 remove_action( 'bp_screens', $function, 3 ); … … 297 297 298 298 // The only way to tell whether to set the subnav is to peek at the unfiltered_uri 299 // Find the component 299 // Find the component. 300 300 $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri ); 301 301 … … 306 306 } 307 307 308 // No subnav item has been requested in the URL, so set a new nav default 308 // No subnav item has been requested in the URL, so set a new nav default. 309 309 if ( empty( $unfiltered_action ) ) { 310 310 if ( ! bp_is_current_action( $r['subnav_slug'] ) ) { … … 318 318 319 319 // The URL is explicitly requesting the new subnav item, but should be 320 // directed to the canonical URL 320 // directed to the canonical URL. 321 321 } elseif ( $unfiltered_action == $r['subnav_slug'] ) { 322 322 unset( $bp->canonical_stack['action'] ); … … 324 324 // In all other cases (including the case where the original subnav item 325 325 // is explicitly called in the URL), the canonical URL will contain the 326 // subnav slug 326 // subnav slug. 327 327 } else { 328 328 $bp->canonical_stack['action'] = bp_current_action(); … … 354 354 $temp[$nav_item['position']] = $nav_item; 355 355 } else { 356 // increase numbers here to fit new items in.356 // Increase numbers here to fit new items in. 357 357 do { 358 358 $nav_item['position']++; … … 444 444 * Default: false. 445 445 * } 446 *447 446 * @return bool|null Returns false on failure. 448 447 */ … … 451 450 452 451 $r = wp_parse_args( $args, array( 453 'name' => false, // Display name for the nav item 454 'slug' => false, // URL slug for the nav item 455 'parent_slug' => false, // URL slug of the parent nav item 456 'parent_url' => false, // URL of the parent item 457 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item 452 'name' => false, // Display name for the nav item. 453 'slug' => false, // URL slug for the nav item. 454 'parent_slug' => false, // URL slug of the parent nav item. 455 'parent_url' => false, // URL of the parent item. 456 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 458 457 'user_has_access' => true, // Can the logged in user see this nav item? 459 458 'no_access_url' => '', 460 459 'site_admin_only' => false, // Can only site admins see this nav item? 461 'position' => 90, // Index of where this nav item should be positioned 462 'screen_function' => false, // The name of the function to run when clicked 460 'position' => 90, // Index of where this nav item should be positioned. 461 'screen_function' => false, // The name of the function to run when clicked. 463 462 'link' => '', // The link for the subnav item; optional, not usually required. 464 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu 463 'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu. 465 464 ) ); 466 465 467 // If we don't have the required info we need, don't create this subnav item 466 // If we don't have the required info we need, don't create this subnav item. 468 467 if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) ) 469 468 return false; 470 469 471 // Link was not forced, so create one 470 // Link was not forced, so create one. 472 471 if ( empty( $r['link'] ) ) { 473 472 $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] ); 474 473 475 // If this sub item is the default for its parent, skip the slug 474 // If this sub item is the default for its parent, skip the slug. 476 475 if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) { 477 476 $r['link'] = trailingslashit( $r['parent_url'] ); … … 479 478 } 480 479 481 // If this is for site admins only and the user is not one, don't create the subnav item 480 // If this is for site admins only and the user is not one, don't create the subnav item. 482 481 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 483 482 return false; … … 529 528 * Default: false. 530 529 * } 531 *532 530 * @return bool|null Returns false on failure. 533 531 */ … … 536 534 537 535 $r = wp_parse_args( $args, array( 538 'slug' => false, // URL slug for the screen 539 'parent_slug' => false, // URL slug of the parent screen 536 'slug' => false, // URL slug for the screen. 537 'parent_slug' => false, // URL slug of the parent screen. 540 538 'user_has_access' => true, // Can the user visit this screen? 541 539 'no_access_url' => '', 542 540 'site_admin_only' => false, // Can only site admins visit this screen? 543 'screen_function' => false, // The name of the function to run when clicked 541 'screen_function' => false, // The name of the function to run when clicked. 544 542 ) ); 545 543 … … 550 548 * checking the following two conditions: 551 549 * (1) Either: 552 * 553 * 550 * (a) the parent slug matches the current_component, or 551 * (b) the parent slug matches the current_item 554 552 * (2) And either: 555 * 553 * (a) the current_action matches $slug, or 556 554 * (b) there is no current_action (ie, this is the default subnav for the parent nav) 557 * 558 * 559 * 560 * 555 * and this subnav item is the default for the parent item (which we check by 556 * comparing this subnav item's screen function with the screen function of the 557 * parent nav item in $bp->bp_nav). This condition only arises when viewing a 558 * user, since groups should always have an action set. 561 559 */ 562 560 563 // If we *don't* meet condition (1), return 561 // If we *don't* meet condition (1), return. 564 562 if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) { 565 563 return; 566 564 } 567 565 568 // If we *do* meet condition (2), then the added subnav item is currently being requested 566 // If we *do* meet condition (2), then the added subnav item is currently being requested. 569 567 if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $bp->bp_nav[$r['parent_slug']]['screen_function'] ) ) ) { 570 568 571 // If this is for site admins only and the user is not one, don't create the subnav item 569 // If this is for site admins only and the user is not one, don't create the subnav item. 572 570 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 573 571 return false; … … 576 574 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $r ); 577 575 578 // If redirect args have been returned, perform the redirect now 576 // If redirect args have been returned, perform the redirect now. 579 577 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { 580 578 bp_core_no_access( $hooked['redirect_args'] ); … … 589 587 * 590 588 * @param array $subnav_item The subnav array added to bp_options_nav in `bp_core_new_subnav_item()`. 591 *592 589 * @return array 593 590 */ … … 603 600 } 604 601 605 // User has access, so let's try to hook the display callback 602 // User has access, so let's try to hook the display callback. 606 603 if ( ! empty( $subnav_item['user_has_access'] ) && ! $site_admin_restricted ) { 607 604 608 // Screen function is invalid 605 // Screen function is invalid. 609 606 if ( ! is_callable( $subnav_item['screen_function'] ) ) { 610 607 $retval['status'] = 'failure'; 611 608 612 // Success - hook to bp_screens 609 // Success - hook to bp_screens. 613 610 } else { 614 611 add_action( 'bp_screens', $subnav_item['screen_function'], 3 ); … … 617 614 618 615 // User doesn't have access. Determine redirect arguments based on 619 // user status 616 // user status. 620 617 } else { 621 618 $retval['status'] = 'failure'; … … 626 623 627 624 // If a redirect URL has been passed to the subnav 628 // item, respect it 625 // item, respect it. 629 626 if ( ! empty( $subnav_item['no_access_url'] ) ) { 630 627 $message = __( 'You do not have access to this page.', 'buddypress' ); … … 632 629 633 630 // In the case of a user page, we try to assume a 634 // redirect URL 631 // redirect URL. 635 632 } elseif ( bp_is_user() ) { 636 633 … … 646 643 // know will be accessible. 647 644 } else { 648 // Try 'activity' first 645 // Try 'activity' first. 649 646 if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) { 650 647 $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() ); 651 // Then try 'profile' 648 // Then try 'profile'. 652 649 } else { 653 650 $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) ); … … 657 654 } 658 655 659 // Fall back to the home page 656 // Fall back to the home page. 660 657 } else { 661 658 $message = __( 'You do not have access to this page.', 'buddypress' ); … … 672 669 // When the user is logged out, pass an empty array 673 670 // This indicates that the default arguments should be 674 // used in bp_core_no_access() 671 // used in bp_core_no_access(). 675 672 $retval['redirect_args'] = array(); 676 673 } … … 699 696 $temp[$subnav_item['position']] = $subnav_item; 700 697 else { 701 // increase numbers here to fit new items in.698 // Increase numbers here to fit new items in. 702 699 do { 703 700 $subnav_item['position']++; … … 722 719 * @param string $nav_item The slug of the top-level nav item whose subnav items you're checking. 723 720 * Default: the current component slug. 724 *725 721 * @return bool $has_subnav True if the nav item is found and has subnav items; false otherwise. 726 722 */ … … 748 744 * 749 745 * @param int $parent_id The slug of the parent navigation item. 750 *751 746 * @return bool Returns false on failure, ie if the nav item can't be found. 752 747 */ … … 754 749 $bp = buddypress(); 755 750 756 // Unset subnav items for this nav item 751 // Unset subnav items for this nav item. 757 752 if ( isset( $bp->bp_options_nav[$parent_id] ) && is_array( $bp->bp_options_nav[$parent_id] ) ) { 758 753 foreach( (array) $bp->bp_options_nav[$parent_id] as $subnav_item ) { … … 765 760 766 761 if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) { 767 // Remove our screen hook if screen function is callable 762 // Remove our screen hook if screen function is callable. 768 763 if ( is_callable( $function ) ) { 769 764 remove_action( 'bp_screens', $function, 3 ); … … 788 783 789 784 if ( ! empty( $screen_function ) ) { 790 // Remove our screen hook if screen function is callable 785 // Remove our screen hook if screen function is callable. 791 786 if ( is_callable( $screen_function ) ) { 792 787 remove_action( 'bp_screens', $screen_function, 3 ); … … 823 818 * @param string $context Context of this preference check. 'admin' or 'front'. 824 819 * @param int $user Optional. ID of the user to check. Default: 0 (which falls back to the logged-in user's ID). 825 *826 820 * @return bool True if the toolbar should be showing for this user. 827 821 */
Note: See TracChangeset
for help on using the changeset viewer.