Ticket #6534: 6534.02.patch
File 6534.02.patch, 57.0 KB (added by , 9 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 9f1ffb0..e676c00 100644
defined( 'ABSPATH' ) || exit; 16 16 * Add an item to the main BuddyPress navigation array. 17 17 * 18 18 * @since 1.1.0 19 * @since 2.6.0 Adds the $nav parameter. 19 20 * 20 21 * @param array|string $args { 21 22 * Array describing the new nav item. … … defined( 'ABSPATH' ) || exit; 32 33 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 33 34 * item is clicked. 34 35 * } 36 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 35 37 * @return bool|null Returns false on failure. 36 38 */ 37 function bp_core_new_nav_item( $args = '' ) {39 function bp_core_new_nav_item( $args = '', $nav = null ) { 38 40 39 41 $defaults = array( 40 42 'name' => false, // Display name for the nav item. … … function bp_core_new_nav_item( $args = '' ) { 50 52 $r = wp_parse_args( $args, $defaults ); 51 53 52 54 // First, add the nav item link to the bp_nav array. 53 $created = bp_core_create_nav_link( $r );55 $created = bp_core_create_nav_link( $r, $nav ); 54 56 55 57 // To mimic the existing behavior, if bp_core_create_nav_link() 56 58 // returns false, we make an early exit and don't attempt to register … … function bp_core_new_nav_item( $args = '' ) { 84 86 * Add a link to the main BuddyPress navigation array. 85 87 * 86 88 * @since 2.4.0 89 * @since 2.6.0 Adds the $nav parameter. 87 90 * 88 91 * @param array|string $args { 89 92 * Array describing the new nav item. … … function bp_core_new_nav_item( $args = '' ) { 100 103 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 101 104 * item is clicked. 102 105 * } 106 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 103 107 * @return bool|null Returns false on failure. 104 108 */ 105 function bp_core_create_nav_link( $args = '' ) {109 function bp_core_create_nav_link( $args = '', $nav = null ) { 106 110 $bp = buddypress(); 107 111 112 if ( ! is_a( $nav, 'BP_Core_Item_Nav' ) ) { 113 $nav = $bp->bp_nav; 114 } 115 108 116 $defaults = array( 109 117 'name' => false, // Display name for the nav item. 110 118 'slug' => false, // URL slug for the nav item. … … function bp_core_create_nav_link( $args = '' ) { 132 140 $r['item_css_id'] = $r['slug']; 133 141 } 134 142 135 $ bp->bp_nav[$r['slug']]= array(143 $nav->{ $r['slug'] } = array( 136 144 'name' => $r['name'], 137 145 'slug' => $r['slug'], 138 146 'link' => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ), … … function bp_core_new_nav_default( $args = '' ) { 290 298 291 299 $r = wp_parse_args( $args, $defaults ); 292 300 293 if ( $function = $bp->bp_nav [$r['parent_slug']]['screen_function'] ) {301 if ( $function = $bp->bp_nav->{ $r['parent_slug'] }['screen_function'] ) { 294 302 // Remove our screen hook if screen function is callable. 295 303 if ( is_callable( $function ) ) { 296 304 remove_action( 'bp_screens', $function, 3 ); 297 305 } 298 306 } 299 307 300 $bp->bp_nav[$r['parent_slug']]['screen_function'] = &$r['screen_function']; 308 $reset_item = $bp->bp_nav->{ $r['parent_slug'] }; 309 $reset_item['screen_function'] = &$r['screen_function']; 310 311 $bp->bp_nav->reset( $reset_item, $r['parent_slug'] ); 301 312 302 313 if ( bp_is_current_component( $r['parent_slug'] ) ) { 303 314 … … function bp_core_new_nav_default( $args = '' ) { 351 362 function bp_core_sort_nav_items() { 352 363 $bp = buddypress(); 353 364 354 if ( empty( $bp->bp_nav ) || ! is_a rray( $bp->bp_nav) ) {365 if ( empty( $bp->bp_nav ) || ! is_a( $bp->bp_nav, 'BP_Core_Item_Nav' ) ) { 355 366 return false; 356 367 } 357 368 358 369 $temp = array(); 359 370 360 foreach ( (array) $bp->bp_nav as $slug => $nav_item ) {371 foreach ( (array) $bp->bp_nav->get() as $slug => $nav_item ) { 361 372 if ( empty( $temp[$nav_item['position']] ) ) { 362 373 $temp[$nav_item['position']] = $nav_item; 363 374 } else { … … function bp_core_sort_nav_items() { 371 382 } 372 383 373 384 ksort( $temp ); 374 $bp->bp_nav = &$temp;385 $bp->bp_nav->reset( $temp ); 375 386 } 376 387 add_action( 'wp_head', 'bp_core_sort_nav_items' ); 377 388 add_action( 'admin_head', 'bp_core_sort_nav_items' ); … … add_action( 'admin_head', 'bp_core_sort_nav_items' ); 380 391 * Add a subnav item to the BuddyPress navigation. 381 392 * 382 393 * @since 1.1.0 394 * @since 2.6.0 Adds the $subnav & $nav parameters. 383 395 * 384 396 * @param array|string $args { 385 397 * Array describing the new subnav item. … … add_action( 'admin_head', 'bp_core_sort_nav_items' ); 403 415 * @type bool $show_in_admin_bar Optional. Whether the nav item should be added into the group's "Edit" 404 416 * Admin Bar menu for group admins. Default: false. 405 417 * } 418 * @param BP_Core_Item_Nav $subnav The specific subnav to use. Optional. 419 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 406 420 * @return bool|null Returns false on failure. 407 421 */ 408 function bp_core_new_subnav_item( $args = '' ) {422 function bp_core_new_subnav_item( $args = '', $subnav = null, $nav = null ) { 409 423 410 424 // First, add the subnav item link to the bp_options_nav array. 411 $created = bp_core_create_subnav_link( $args );425 $created = bp_core_create_subnav_link( $args, $subnav, $nav ); 412 426 413 427 // To mimic the existing behavior, if bp_core_create_subnav_link() 414 428 // returns false, we make an early exit and don't attempt to register … … function bp_core_new_subnav_item( $args = '' ) { 418 432 } 419 433 420 434 // Then, hook the screen function for the added subnav item. 421 $hooked = bp_core_register_subnav_screen_function( $args );435 $hooked = bp_core_register_subnav_screen_function( $args, $nav ); 422 436 if ( false === $hooked ) { 423 437 return false; 424 438 } … … function bp_core_new_subnav_item( $args = '' ) { 428 442 * Add a subnav link to the BuddyPress navigation. 429 443 * 430 444 * @since 2.4.0 445 * @since 2.6.0 Adds the $subnav & $nav parameters. 431 446 * 432 447 * @param array|string $args { 433 448 * Array describing the new subnav item. … … function bp_core_new_subnav_item( $args = '' ) { 455 470 * the group's "Edit" Admin Bar menu for group admins. 456 471 * Default: false. 457 472 * } 473 * @param BP_Core_Item_Nav $subnav The specific subnav to use. Optional. 474 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 458 475 * @return bool|null Returns false on failure. 459 476 */ 460 function bp_core_create_subnav_link( $args = '' ) {477 function bp_core_create_subnav_link( $args = '', $subnav = null, $nav = null ) { 461 478 $bp = buddypress(); 462 479 480 if ( ! is_a( $subnav, 'BP_Core_Item_Nav' ) ) { 481 $subnav = $bp->bp_options_nav; 482 } 483 484 if ( ! is_a( $nav, 'BP_Core_Item_Nav' ) ) { 485 $nav = $bp->bp_nav; 486 } 487 463 488 $r = wp_parse_args( $args, array( 464 489 'name' => false, // Display name for the nav item. 465 490 'slug' => false, // URL slug for the nav item. … … function bp_core_create_subnav_link( $args = '' ) { 484 509 $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] ); 485 510 486 511 // If this sub item is the default for its parent, skip the slug. 487 if ( ! empty( $ bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) {512 if ( ! empty( $nav->{ $r['parent_slug'] }['default_subnav_slug'] ) && $r['slug'] == $nav->{ $r['parent_slug'] }['default_subnav_slug'] ) { 488 513 $r['link'] = trailingslashit( $r['parent_url'] ); 489 514 } 490 515 } … … function bp_core_create_subnav_link( $args = '' ) { 510 535 'show_in_admin_bar' => (bool) $r['show_in_admin_bar'], 511 536 ); 512 537 513 $ bp->bp_options_nav[$r['parent_slug']][$r['slug']] = $subnav_item;538 $subnav->add_subitem( $r['parent_slug'], $r['slug'], $subnav_item ); 514 539 } 515 540 516 541 /** 517 542 * Register a screen function, whether or not a related subnav link exists. 518 543 * 519 544 * @since 2.4.0 545 * @since 2.6.0 Adds the $nav parameters. 520 546 * 521 547 * @param array|string $args { 522 548 * Array describing the new subnav item. … … function bp_core_create_subnav_link( $args = '' ) { 541 567 * the group's "Edit" Admin Bar menu for group admins. 542 568 * Default: false. 543 569 * } 570 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 544 571 * @return bool|null Returns false on failure. 545 572 */ 546 function bp_core_register_subnav_screen_function( $args = '' ) {573 function bp_core_register_subnav_screen_function( $args = '', $nav = null ) { 547 574 $bp = buddypress(); 548 575 576 if ( ! is_a( $nav, 'BP_Core_Item_Nav' ) ) { 577 $nav = $bp->bp_nav; 578 } 579 549 580 $r = wp_parse_args( $args, array( 550 581 'slug' => false, // URL slug for the screen. 551 582 'parent_slug' => false, // URL slug of the parent screen. … … function bp_core_register_subnav_screen_function( $args = '' ) { 578 609 } 579 610 580 611 // If we *do* meet condition (2), then the added subnav item is currently being requested. 581 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'] ) ) ) {612 if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $nav->{ $r['parent_slug'] }['screen_function'] ) ) ) { 582 613 583 614 // If this is for site admins only and the user is not one, don't create the subnav item. 584 615 if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { 585 616 return false; 586 617 } 587 618 588 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $r );619 $hooked = bp_core_maybe_hook_new_subnav_screen_function( $r, $nav ); 589 620 590 621 // If redirect args have been returned, perform the redirect now. 591 622 if ( ! empty( $hooked['status'] ) && 'failure' === $hooked['status'] && isset( $hooked['redirect_args'] ) ) { … … function bp_core_register_subnav_screen_function( $args = '' ) { 598 629 * For a given subnav item, either hook the screen function or generate redirect arguments, as necessary. 599 630 * 600 631 * @since 2.1.0 632 * @since 2.6.0 Adds the $nav parameters. 601 633 * 602 * @param array $subnav_item The subnav array added to bp_options_nav in `bp_core_new_subnav_item()`. 634 * @param array $subnav_item The subnav array added to bp_options_nav in `bp_core_new_subnav_item()`. 635 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 603 636 * @return array 604 637 */ 605 function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) {638 function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item, $nav = null ) { 606 639 $retval = array( 607 640 'status' => '', 608 641 ); … … function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 635 668 636 669 $bp = buddypress(); 637 670 671 if ( ! is_a( $nav, 'BP_Core_Item_Nav' ) ) { 672 $nav = $bp->bp_nav; 673 } 674 638 675 // If a redirect URL has been passed to the subnav 639 676 // item, respect it. 640 677 if ( ! empty( $subnav_item['no_access_url'] ) ) { … … function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 648 685 // Redirect to the displayed user's default 649 686 // component, as long as that component is 650 687 // publicly accessible. 651 if ( bp_is_my_profile() || ! empty( $ bp->bp_nav[ $bp->default_component ]['show_for_displayed_user'] ) ) {688 if ( bp_is_my_profile() || ! empty( $nav->{ $bp->default_component }['show_for_displayed_user'] ) ) { 652 689 $message = __( 'You do not have access to this page.', 'buddypress' ); 653 690 $redirect_to = bp_displayed_user_domain(); 654 691 … … function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 691 728 } 692 729 693 730 /** 731 * Sort subnav items by position 732 * 733 * @since 2.6.0 734 * 735 * @param array $subnav_items The subnav items to sort. 736 * @return array The sorted subnav items. 737 */ 738 function bp_core_sort_get_sorted_subnav_by_position( $subnav_items ) { 739 $temp = array(); 740 741 if ( empty( $subnav_items ) ) { 742 return $temp; 743 } 744 745 foreach ( (array) $subnav_items as $subnav_item ) { 746 if ( empty( $temp[ $subnav_item['position'] ] ) ) { 747 $temp[ $subnav_item['position'] ] = $subnav_item; 748 } else { 749 // Increase numbers here to fit new items in. 750 do { 751 $subnav_item['position']++; 752 } while ( ! empty( $temp[ $subnav_item['position'] ] ) ); 753 754 $temp[ $subnav_item['position'] ] = $subnav_item; 755 } 756 } 757 758 return $temp; 759 } 760 761 /** 694 762 * Sort all subnavigation arrays. 695 763 * 696 764 * @since 1.1.0 … … function bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ) { 700 768 function bp_core_sort_subnav_items() { 701 769 $bp = buddypress(); 702 770 703 if ( empty( $bp->bp_options_nav ) || ! is_array( $bp->bp_options_nav ) )771 if ( empty( $bp->bp_options_nav ) || ! is_a( $bp->bp_options_nav, 'BP_Core_Item_Nav' ) ) { 704 772 return false; 773 } 705 774 706 foreach ( (array) $bp->bp_options_nav as $parent_slug => $subnav_items ) {707 if ( ! is_array( $subnav_items ) )775 foreach ( (array) $bp->bp_options_nav->get() as $parent_slug => $subnav_items ) { 776 if ( ! is_array( $subnav_items ) ) { 708 777 continue; 778 } 709 779 710 foreach ( (array) $subnav_items as $subnav_item ) { 711 if ( empty( $temp[$subnav_item['position']]) ) 712 $temp[$subnav_item['position']] = $subnav_item; 713 else { 714 // Increase numbers here to fit new items in. 715 do { 716 $subnav_item['position']++; 717 } while ( !empty( $temp[$subnav_item['position']] ) ); 780 $temp = bp_core_sort_get_sorted_subnav_by_position( $subnav_items ); 718 781 719 $temp[$subnav_item['position']] = $subnav_item;720 }721 }722 782 ksort( $temp ); 723 $bp->bp_options_nav [$parent_slug] = &$temp;783 $bp->bp_options_nav->reset( $temp, $parent_slug ); 724 784 unset( $temp ); 725 785 } 726 786 } … … add_action( 'admin_head', 'bp_core_sort_subnav_items' ); 731 791 * Check whether a given nav item has subnav items. 732 792 * 733 793 * @since 1.5.0 794 * @since 2.6.0 Add the subnav parameter. 734 795 * 735 * @param string $nav_item The slug of the top-level nav item whose subnav items you're checking. 736 * Default: the current component slug. 796 * @param string $nav_item The slug of the top-level nav item whose subnav items you're checking. 797 * Default: the current component slug. 798 * @param BP_Core_Item_Nav $subnav The Nav object to check upon. Optional. 799 * Default Legacy's buddypress()->bp_options_nav 737 800 * @return bool $has_subnav True if the nav item is found and has subnav items; false otherwise. 738 801 */ 739 function bp_nav_item_has_subnav( $nav_item = '' ) {802 function bp_nav_item_has_subnav( $nav_item = '', $subnav = null ) { 740 803 $bp = buddypress(); 741 804 742 if ( !$nav_item ) 805 if ( ! is_a( $subnav, 'BP_Core_Item_Nav' ) ) { 806 $subnav = $bp->bp_options_nav; 807 } 808 809 if ( ! $nav_item ) { 743 810 $nav_item = bp_current_component(); 811 } 744 812 745 $has_subnav = isset( $ bp->bp_options_nav[$nav_item] ) && count( $bp->bp_options_nav[$nav_item]) > 0;813 $has_subnav = isset( $subnav->{ $nav_item } ) && count( $subnav->{ $nav_item } ) > 0; 746 814 747 815 /** 748 816 * Filters whether or not a given nav item has subnav items. … … function bp_nav_item_has_subnav( $nav_item = '' ) { 759 827 * Remove a nav item from the navigation array. 760 828 * 761 829 * @since 1.0.0 830 * @since 2.6.0 Adds the $nav & $subnav parameters. 762 831 * 763 * @param int $parent_id The slug of the parent navigation item. 832 * @param int $parent_id The slug of the parent navigation item. 833 * @param BP_Core_Item_Nav $nav The specific main nav to use. Optional. 834 * @param BP_Core_Item_Nav $subnav The specific subnav to use. Optional. 764 835 * @return bool Returns false on failure, ie if the nav item can't be found. 765 836 */ 766 function bp_core_remove_nav_item( $parent_id ) {837 function bp_core_remove_nav_item( $parent_id, $nav = null, $subnav = null ) { 767 838 $bp = buddypress(); 768 839 840 if ( ! is_a( $nav, 'BP_Core_Item_Nav' ) ) { 841 $nav = $bp->bp_nav; 842 } 843 844 if ( ! is_a( $subnav, 'BP_Core_Item_Nav' ) ) { 845 $subnav = $bp->bp_options_nav; 846 } 847 769 848 // Unset subnav items for this nav item. 770 if ( isset( $ bp->bp_options_nav[$parent_id] ) && is_array( $bp->bp_options_nav[$parent_id]) ) {771 foreach( (array) $ bp->bp_options_nav[$parent_id]as $subnav_item ) {772 bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );849 if ( isset( $subnav->{ $parent_id } ) && is_array( $subnav->{ $parent_id } ) ) { 850 foreach( (array) $subnav->{ $parent_id } as $subnav_item ) { 851 bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'], $subnav ); 773 852 } 774 853 } 775 854 776 if ( empty( $ bp->bp_nav[ $parent_id ] ) )855 if ( empty( $nav->{ $parent_id } ) ) { 777 856 return false; 857 } 778 858 779 if ( $function = $ bp->bp_nav[$parent_id]['screen_function'] ) {859 if ( $function = $nav->{ $parent_id }['screen_function'] ) { 780 860 // Remove our screen hook if screen function is callable. 781 861 if ( is_callable( $function ) ) { 782 862 remove_action( 'bp_screens', $function, 3 ); 783 863 } 784 864 } 785 865 786 unset( $bp->bp_nav[$parent_id]);866 $nav->delete( $parent_id ); 787 867 } 788 868 789 869 /** 790 870 * Remove a subnav item from the navigation array. 791 871 * 792 872 * @since 1.0.0 873 * @since 2.6.0 Adds the $subnav parameter. 793 874 * 794 * @param string $parent_id The slug of the parent navigation item. 795 * @param string $slug The slug of the subnav item to be removed. 875 * @param string $parent_id The slug of the parent navigation item. 876 * @param string $slug The slug of the subnav item to be removed. 877 * @param BP_Core_Item_Nav $subnav The specific subnav to use. Optional. 796 878 */ 797 function bp_core_remove_subnav_item( $parent_id, $slug ) {879 function bp_core_remove_subnav_item( $parent_id, $slug, $subnav = null ) { 798 880 $bp = buddypress(); 799 881 800 $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) 801 ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] 882 if ( ! is_a( $subnav, 'BP_Core_Item_Nav' ) ) { 883 $subnav = $bp->bp_options_nav; 884 } 885 886 $screen_function = isset( $subnav->{ $parent_id }[ $slug ]['screen_function'] ) 887 ? $subnav->{ $parent_id }[ $slug ]['screen_function'] 802 888 : false; 803 889 804 890 if ( ! empty( $screen_function ) ) { … … function bp_core_remove_subnav_item( $parent_id, $slug ) { 808 894 } 809 895 } 810 896 811 unset( $bp->bp_options_nav[$parent_id][$slug]);897 $subnav->delete( $parent_id, $slug ); 812 898 813 if ( isset( $bp->bp_options_nav[$parent_id] ) && !count( $bp->bp_options_nav[$parent_id] ) ) 814 unset($bp->bp_options_nav[$parent_id]); 899 if ( isset( $subnav->{ $parent_id } ) && ! count( $subnav->{ $parent_id } ) ) { 900 $subnav->delete( $parent_id ); 901 } 815 902 } 816 903 817 904 /** 818 905 * Clear all subnav items from a specific nav item. 819 906 * 820 907 * @since 1.0.0 908 * @since 2.6.0 Adds the $subnav parameter. 821 909 * 822 * @param string $parent_slug The slug of the parent navigation item. 910 * @param string $parent_slug The slug of the parent navigation item. 911 * @param BP_Core_Item_Nav $subnav The specific subnav to use. Optional. 823 912 */ 824 function bp_core_reset_subnav_items( $parent_slug ) {913 function bp_core_reset_subnav_items( $parent_slug, $subnav = null ) { 825 914 $bp = buddypress(); 826 915 827 unset( $bp->bp_options_nav[$parent_slug] ); 916 if ( ! is_a( $subnav, 'BP_Core_Item_Nav' ) ) { 917 $subnav = $bp->bp_options_nav; 918 } 919 920 $subnav->delete( $parent_slug );; 828 921 } 829 922 830 923 -
src/bp-core/bp-core-classes.php
diff --git src/bp-core/bp-core-classes.php src/bp-core/bp-core-classes.php index bebf4ed..1bd97b9 100644
require dirname( __FILE__ ) . '/classes/class-bp-email-recipient.php'; 30 30 require dirname( __FILE__ ) . '/classes/class-bp-email.php'; 31 31 require dirname( __FILE__ ) . '/classes/class-bp-email-delivery.php'; 32 32 require dirname( __FILE__ ) . '/classes/class-bp-phpmailer.php'; 33 require dirname( __FILE__ ) . '/classes/class-bp-core-item-nav.php'; -
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index 227237b..9f19a2a 100644
function bp_nav_menu_get_loggedin_pages() { 2359 2359 } 2360 2360 2361 2361 // Pull up a list of items registered in BP's top-level nav array. 2362 $bp_menu_items = buddypress()->bp_nav ;2362 $bp_menu_items = buddypress()->bp_nav->get(); 2363 2363 2364 2364 // Alphabetize. 2365 2365 $bp_menu_items = bp_alpha_sort_by_key( $bp_menu_items, 'name' ); -
src/bp-core/bp-core-template.php
diff --git src/bp-core/bp-core-template.php src/bp-core/bp-core-template.php index 1f2c5e9..b52756b 100644
function bp_get_options_nav( $parent_slug = '' ) { 40 40 $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() ); 41 41 $selected_item = bp_current_action(); 42 42 43 // Default nav & list type 44 $nav = $bp->bp_options_nav; 45 $list_type = 'personal'; 46 47 if ( bp_is_group() ) { 48 $nav = $bp->groups->sub_nav; 49 $list_type = 'groups'; 50 } 51 43 52 if ( ! bp_is_single_item() ) { 44 if ( !isset( $ bp->bp_options_nav[$component_index] ) || count( $bp->bp_options_nav[$component_index]) < 1 ) {53 if ( !isset( $nav->{ $component_index } ) || count( $nav->{ $component_index } ) < 1 ) { 45 54 return false; 46 55 } else { 47 56 $the_index = $component_index; … … function bp_get_options_nav( $parent_slug = '' ) { 54 63 $selected_item = bp_action_variable( 0 ); 55 64 } 56 65 57 if ( !isset( $ bp->bp_options_nav[$current_item] ) || count( $bp->bp_options_nav[$current_item]) < 1 ) {66 if ( !isset( $nav->{ $current_item } ) || count( $nav->{ $current_item } ) < 1 ) { 58 67 return false; 59 68 } else { 60 69 $the_index = $current_item; … … function bp_get_options_nav( $parent_slug = '' ) { 62 71 } 63 72 64 73 // Loop through each navigation item. 65 foreach ( (array) $ bp->bp_options_nav[$the_index]as $subnav_item ) {74 foreach ( (array) $nav->{ $the_index } as $subnav_item ) { 66 75 if ( empty( $subnav_item['user_has_access'] ) ) { 67 76 continue; 68 77 } … … function bp_get_options_nav( $parent_slug = '' ) { 74 83 $selected = ''; 75 84 } 76 85 77 // List type depends on our current component. 78 $list_type = bp_is_group() ? 'groups' : 'personal'; 86 79 87 80 88 /** 81 89 * Filters the "options nav", the secondary-level single item navigation menu. … … function bp_get_title_parts( $seplocation = 'right' ) { 3011 3019 $component_subnav_name = ''; 3012 3020 3013 3021 // Use the component nav name. 3014 if ( ! empty( $bp->bp_nav [$component_id]) ) {3015 $component_name = _bp_strip_spans_from_title( $bp->bp_nav [ $component_id ]['name'] );3022 if ( ! empty( $bp->bp_nav->{ $component_id } ) ) { 3023 $component_name = _bp_strip_spans_from_title( $bp->bp_nav->{ $component_id }['name'] ); 3016 3024 3017 3025 // Fall back on the component ID. 3018 3026 } elseif ( ! empty( $bp->{$component_id}->id ) ) { … … function bp_get_title_parts( $seplocation = 'right' ) { 3020 3028 } 3021 3029 3022 3030 // Append action name if we're on a member component sub-page. 3023 if ( ! empty( $bp->bp_options_nav [ $component_id ]) && ! empty( $bp->canonical_stack['action'] ) ) {3024 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav [ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' );3031 if ( ! empty( $bp->bp_options_nav->{ $component_id } ) && ! empty( $bp->canonical_stack['action'] ) ) { 3032 $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav->{ $component_id }, array( 'slug' => bp_current_action() ), 'and', 'name' ); 3025 3033 3026 3034 if ( ! empty( $component_subnav_name ) ) { 3027 3035 $component_subnav_name = array_shift( $component_subnav_name ); … … function bp_get_title_parts( $seplocation = 'right' ) { 3046 3054 } 3047 3055 3048 3056 // A single group. 3049 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp-> bp_options_nav[ $bp->groups->current_group->slug ]) ) {3050 $subnav = isset( $bp-> bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] ) ? $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] : '';3057 } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->groups->sub_nav->{ $bp->groups->current_group->slug } ) ) { 3058 $subnav = isset( $bp->groups->sub_nav->{ $bp->groups->current_group->slug }[ bp_current_action() ]['name'] ) ? $bp->groups->sub_nav->{ $bp->groups->current_group->slug }[ bp_current_action() ]['name'] : ''; 3051 3059 $bp_title_parts = array( $bp->bp_options_title, $subnav ); 3052 3060 3053 3061 // A single item from a component other than groups. 3054 3062 } elseif ( bp_is_single_item() ) { 3055 $bp_title_parts = array( $bp->bp_options_title, $bp->bp_options_nav [ bp_current_item() ][ bp_current_action() ]['name'] );3063 $bp_title_parts = array( $bp->bp_options_title, $bp->bp_options_nav->{ bp_current_item() }[ bp_current_action() ]['name'] ); 3056 3064 3057 3065 // An index or directory. 3058 3066 } elseif ( bp_is_directory() ) { … … function bp_get_nav_menu_items() { 3435 3443 $menus = $selected_menus = array(); 3436 3444 3437 3445 // Get the second level menus. 3438 foreach ( (array) buddypress()->bp_options_nav as $parent_menu => $sub_menus ) {3446 foreach ( (array) buddypress()->bp_options_nav->get() as $parent_menu => $sub_menus ) { 3439 3447 3440 3448 // The root menu's ID is "xprofile", but the Profile submenus are using "profile". See BP_Core::setup_nav(). 3441 3449 if ( 'profile' === $parent_menu ) { -
src/bp-core/classes/class-bp-core-item-nav.php
diff --git src/bp-core/classes/class-bp-core-item-nav.php src/bp-core/classes/class-bp-core-item-nav.php index e69de29..fede9f2 100644
1 <?php 2 /** 3 * Core component class. 4 * 5 * @package BuddyPress 6 * @subpackage Core 7 * @since 2.6.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * BuddyPress Item Nav. 15 * 16 * This class is used to store the Single Items nav 17 * 18 * @since 2.6.0 19 */ 20 class BP_Core_Item_Nav { 21 /** 22 * An associative array containing the nav items for the Item ID 23 * 24 * @var array 25 */ 26 private $nav; 27 28 /** 29 * The Current Item ID 30 * 31 * @var int 32 */ 33 private $item_id; 34 35 /** 36 * Init the Nav for the given Item ID 37 * 38 * @since 2.6.0 39 * 40 * @param int $item_id The item ID to build the nav for. Optional. 41 * Default: The displayed user ID 42 */ 43 public function __construct( $item_id = 0 ) { 44 if ( empty( $item_id ) ) { 45 $this->item_id = (int) bp_displayed_user_id(); 46 } else { 47 $this->item_id = (int) $item_id; 48 } 49 50 $this->nav[ $this->item_id ] = array(); 51 } 52 53 /** 54 * Checks if a nav attribute is set. 55 * 56 * @since 2.6.0 57 * 58 * @param string $key The requested nav slug 59 * @return bool True if the nav attribute is set, false otherwise. 60 */ 61 public function __isset( $key ) { 62 return isset( $this->nav[ $this->item_id ][ $key ] ); 63 } 64 65 /** 66 * Gets a nav attribute. 67 * 68 * @since 2.6.0 69 * 70 * @param string $key The requested nav slug. 71 * @return mixed The value corresponding to the requested attribute. 72 */ 73 public function __get( $key ) { 74 if ( ! isset( $this->nav[ $this->item_id ][ $key ] ) ) { 75 $this->nav[ $this->item_id ][ $key ] = null; 76 } 77 78 return $this->nav[ $this->item_id ][ $key ]; 79 } 80 81 /** 82 * Sets a nav attribute. 83 * 84 * @since 2.6.0 85 * 86 * @param string $key The requested nav slug. 87 * @param mixed $value The value of the attribute. 88 */ 89 public function __set( $key, $value ) { 90 $this->nav[ $this->item_id ][ $key ] = $value; 91 } 92 93 /** 94 * Gets a specific Item Nav attribute or all attributes. 95 * 96 * @since 2.6.0 97 * 98 * @param string $key The attribute to get. Optional. 99 * @return mixed An array of attribute(s), null if not found. 100 */ 101 public function get( $key = '' ) { 102 $return = null; 103 104 // Return the requested nav item attribute 105 if ( ! empty( $key ) ) { 106 if ( ! isset( $this->nav[ $this->item_id ][ $key ] ) ) { 107 $return = null; 108 } else { 109 $return = $this->nav[ $this->item_id ][ $key ]; 110 } 111 112 // Return all nav item attributes 113 } else { 114 $return = $this->nav[ $this->item_id ]; 115 } 116 117 return $return; 118 } 119 120 /** 121 * Completely resets the nav or a specific attribute of the nav. 122 * 123 * NB: This is used when sorting the nav items. 124 * 125 * @since 2.6.0 126 * 127 * @param array $args The arguments to update with. Required. 128 * @param string $key The specific attribute to update. Optional. 129 */ 130 public function reset( $args, $key = '' ) { 131 if ( empty( $key ) ) { 132 $this->nav[ $this->item_id ] = $args; 133 } elseif ( isset( $this->nav[ $this->item_id ][ $key ] ) ) { 134 $this->nav[ $this->item_id ][ $key ] = $args; 135 } 136 } 137 138 /** 139 * Unset an item or a subitem of the nav. 140 * 141 * @since 2.6.0 142 * 143 * @param string $key The slug of the main item. 144 * @param string $sub_key The slug of the sub item. 145 */ 146 public function delete( $key, $sub_key = '' ) { 147 if ( isset( $this->nav[ $this->item_id ][ $key ] ) ) { 148 if ( ! empty( $sub_key ) ) { 149 unset( $this->nav[ $this->item_id ][ $key ][ $sub_key ] ); 150 } else { 151 unset( $this->nav[ $this->item_id ][ $key ] ); 152 } 153 } 154 } 155 156 /** 157 * Adds one or more subitems to the nav. 158 * 159 * @since 2.6.0 160 * 161 * @param string $key The slug of the main item. 162 * @param string $sub_key The slug of the sub item. 163 * @param array $sub_value The value of the sub item. 164 */ 165 public function add_subitem( $key, $sub_key, $sub_value ) { 166 if ( ! empty( $this->nav[ $this->item_id ][ $key ] ) ) { 167 $this->nav[ $this->item_id ][ $key ][ $sub_key ] = $sub_value; 168 } else { 169 $this->nav[ $this->item_id ][ $key ] = array( $sub_key => $sub_value ); 170 } 171 } 172 } -
src/bp-groups/bp-groups-actions.php
diff --git src/bp-groups/bp-groups-actions.php src/bp-groups/bp-groups-actions.php index 2190cec..7a75fc3 100644
function groups_action_group_feed() { 551 551 ) ); 552 552 } 553 553 add_action( 'bp_actions', 'groups_action_group_feed' ); 554 555 556 /** 557 * Sort all subnavigation arrays. 558 * 559 * @since 2.6.0 560 * 561 * @return bool|null Returns false on failure. 562 */ 563 function bp_groups_sort_subnav_items() { 564 $bp = buddypress(); 565 566 if ( ! bp_is_group() || empty( $bp->groups->sub_nav ) || ! is_a( $bp->groups->sub_nav, 'BP_Core_Item_Nav' ) ) { 567 return false; 568 } 569 570 foreach ( (array) $bp->groups->sub_nav->get() as $parent_slug => $subnav_items ) { 571 if ( ! is_array( $subnav_items ) ) { 572 continue; 573 } 574 575 $temp = bp_core_sort_get_sorted_subnav_by_position( $subnav_items ); 576 577 ksort( $temp ); 578 $bp->groups->sub_nav->reset( $temp, $parent_slug ); 579 unset( $temp ); 580 } 581 } 582 add_action( 'wp_head', 'bp_groups_sort_subnav_items' ); -
src/bp-groups/bp-groups-adminbar.php
diff --git src/bp-groups/bp-groups-adminbar.php src/bp-groups/bp-groups-adminbar.php index f27f74e..174f84f 100644
function bp_groups_group_admin_menu() { 50 50 $nav_index = $bp->groups->current_group->slug . '_manage'; 51 51 52 52 // Check if current group has Manage tabs. 53 if ( empty( $bp-> bp_options_nav[ $nav_index ]) ) {53 if ( empty( $bp->groups->sub_nav->{ $nav_index } ) ) { 54 54 return; 55 55 } 56 56 57 57 // Build the Group Admin menus. 58 foreach ( $bp-> bp_options_nav[ $nav_index ]as $menu ) {58 foreach ( $bp->groups->sub_nav->{ $nav_index } as $menu ) { 59 59 /** 60 60 * Should we add the current manage link in the Group's "Edit" Admin Bar menu ? 61 61 * -
src/bp-groups/classes/class-bp-group-extension.php
diff --git src/bp-groups/classes/class-bp-group-extension.php src/bp-groups/classes/class-bp-group-extension.php index 5709b0b..69b168d 100644
class BP_Group_Extension { 737 737 'screen_function' => array( &$this, '_display_hook' ), 738 738 'user_has_access' => $user_can_see_nav_item, 739 739 'no_access_url' => $group_permalink, 740 ) );740 ), buddypress()->groups->sub_nav ); 741 741 } 742 742 743 743 // If the user can visit the screen, we register it. … … class BP_Group_Extension { 967 967 } 968 968 969 969 // Add the tab to the manage navigation. 970 bp_core_new_subnav_item( $subnav_args );970 bp_core_new_subnav_item( $subnav_args, buddypress()->groups->sub_nav ); 971 971 972 972 // Catch the edit screen and forward it to the plugin template. 973 973 if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) && bp_is_action_variable( $screen['slug'], 0 ) ) { -
src/bp-groups/classes/class-bp-groups-component.php
diff --git src/bp-groups/classes/class-bp-groups-component.php src/bp-groups/classes/class-bp-groups-component.php index 355ab8c..d46ba34 100644
class BP_Groups_Component extends BP_Component { 253 253 // Check once if the current group has a custom front template. 254 254 $this->current_group->front_template = bp_groups_get_front_template( $this->current_group ); 255 255 256 /** 257 * Since 2.6.0 The Groups single items are using their own navigation to avoid slug 258 * collisions with the displayed user options nav (buddypress()->bp_options_nav) 259 * and for more flexibility in future releases. 260 */ 261 262 // Current Group's Primary Nav 263 $this->nav = new BP_Core_Item_Nav( $this->current_group->id ); 264 265 // Current Group's Secondary Nav 266 $this->sub_nav = new BP_Core_Item_Nav( $this->current_group->id ); 267 256 268 // Set current_group to 0 to prevent debug errors. 257 269 } else { 258 270 $this->current_group = 0; … … class BP_Groups_Component extends BP_Component { 492 504 } 493 505 494 506 if ( bp_is_groups_component() && bp_is_single_item() ) { 495 496 507 // Reset sub nav. 497 508 $sub_nav = array(); 498 509 499 // Add 'Groups' to the main navigation. 500 $main_nav = array( 510 /** 511 * Set the Current Group's main navigation 512 * 513 * Since 2.6.0 it's now using its own navigation by passing it 514 * as the second argument of bp_core_new_nav_item() 515 */ 516 bp_core_new_nav_item( array( 501 517 'name' => __( 'Memberships', 'buddypress' ), 502 518 'slug' => $this->current_group->slug, 503 519 'position' => -1, // Do not show in BuddyBar. 504 520 'screen_function' => 'groups_screen_group_home', 505 521 'default_subnav_slug' => $this->default_extension, 506 522 'item_css_id' => $this->id 507 ) ;523 ), $this->nav ); 508 524 509 525 $group_link = bp_get_group_permalink( $this->current_group ); 510 526 … … class BP_Groups_Component extends BP_Component { 675 691 ), $default_params ); 676 692 } 677 693 678 parent::setup_nav( $main_nav, $sub_nav ); 694 foreach( $sub_nav as $nav ) { 695 /** 696 * Set the Current Group's sub navigation 697 * 698 * Since 2.6.0 it's now using its own sub navigation by passing it 699 * as the second argument of bp_core_new_subnav_item() 700 */ 701 bp_core_new_subnav_item( $nav, $this->sub_nav ); 702 } 679 703 } 680 704 681 705 if ( isset( $this->current_group->user_has_access ) ) { -
src/bp-loader.php
diff --git src/bp-loader.php src/bp-loader.php index f7b3f3f..2ace4e8 100644
class BuddyPress { 54 54 /** Not Magic *************************************************************/ 55 55 56 56 /** 57 * @var arrayPrimary BuddyPress navigation.57 * @var object Primary BuddyPress navigation. 58 58 */ 59 public $bp_nav = array();59 public $bp_nav = null; 60 60 61 61 /** 62 * @var arraySecondary BuddyPress navigation to $bp_nav.62 * @var object Secondary BuddyPress navigation to $bp_nav. 63 63 */ 64 public $bp_options_nav = array();64 public $bp_options_nav = null; 65 65 66 66 /** 67 67 * @var array The unfiltered URI broken down into chunks. -
src/bp-members/bp-members-template.php
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php index bffd155..939d859 100644
function bp_get_loggedin_user_nav() { 1333 1333 function bp_get_displayed_user_nav() { 1334 1334 $bp = buddypress(); 1335 1335 1336 foreach ( (array) $bp->bp_nav as $user_nav_item ) {1336 foreach ( (array) $bp->bp_nav->get() as $user_nav_item ) { 1337 1337 if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() ) 1338 1338 continue; 1339 1339 -
src/bp-members/classes/class-bp-members-component.php
diff --git src/bp-members/classes/class-bp-members-component.php src/bp-members/classes/class-bp-members-component.php index 92a2c85..63bb928 100644
class BP_Members_Component extends BP_Component { 150 150 // The domain for the user currently being displayed. 151 151 $bp->displayed_user->domain = bp_core_get_user_domain( bp_displayed_user_id() ); 152 152 153 // Set User's primary nav 154 $bp->bp_nav = new BP_Core_Item_Nav( bp_displayed_user_id() ); 155 156 // Set User's secondary nav 157 $bp->bp_options_nav = new BP_Core_Item_Nav( bp_displayed_user_id() ); 158 153 159 /** Signup *********************************************************** 154 160 */ 155 161 -
tests/phpunit/includes/testcase.php
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php index 1e8bcb4..e3e3d6d 100644
class BP_UnitTestCase extends WP_UnitTestCase { 91 91 } 92 92 93 93 function clean_up_global_scope() { 94 buddypress()->bp_nav = buddypress()->bp_options_nav = buddypress()->action_variables = buddypress()->canonical_stack = buddypress()->unfiltered_uri = $GLOBALS['bp_unfiltered_uri'] = array(); 94 buddypress()->bp_nav = buddypress()->bp_options_nav = null; 95 buddypress()->action_variables = buddypress()->canonical_stack = buddypress()->unfiltered_uri = $GLOBALS['bp_unfiltered_uri'] = array(); 95 96 buddypress()->current_component = buddypress()->current_item = buddypress()->current_action = buddypress()->current_member_type = ''; 96 97 buddypress()->unfiltered_uri_offset = 0; 97 98 buddypress()->is_single_item = false; -
tests/phpunit/testcases/blogs/activity.php
diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php index d7595ef..38c9dc6 100644
class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 618 618 /** 619 619 * @group bp_blogs_sync_activity_edit_to_post_comment 620 620 * @group post_type_comment_activities 621 * @group imath622 621 */ 623 622 public function test_bp_blogs_sync_activity_edit_to_post_comment_trash_comment_ham_activity() { 624 623 $old_user = get_current_user_id(); -
tests/phpunit/testcases/core/nav.php
diff --git tests/phpunit/testcases/core/nav.php tests/phpunit/testcases/core/nav.php index 721217d..84fdfe7 100644
class BP_Tests_Core_Nav extends BP_UnitTestCase { 39 39 40 40 bp_core_sort_nav_items(); 41 41 42 $this->assertSame( buddypress()->bp_nav[25], $expected ); 42 43 $this->assertSame( buddypress()->bp_nav->get()[25], $expected ); 43 44 44 45 // Clean up 45 46 buddypress()->bp_nav = $bp_nav; … … class BP_Tests_Core_Nav extends BP_UnitTestCase { 83 84 'show_in_admin_bar' => false, 84 85 ); 85 86 86 $this->assertSame( buddypress()->bp_options_nav ['foo'][10], $expected );87 $this->assertSame( buddypress()->bp_options_nav->get()['foo'][10], $expected ); 87 88 88 89 // Clean up 89 90 buddypress()->bp_options_nav = $bp_options_nav; 90 91 $this->set_current_user( $old_current_user ); 91 92 } 93 94 /** 95 * @ticket BP5103 96 */ 97 public function test_bp_core_new_subnav_item_group_slug_collision() { 98 $u = $this->factory->user->create(); 99 $old_current_user = get_current_user_id(); 100 $this->set_current_user( $u ); 101 102 $g = $this->factory->group->create( array( 'creator_id' => $u, 'slug' => 'profile' ) ); 103 $group = groups_get_group( array( 'group_id' => $g ) ); 104 $group_url = bp_get_group_permalink( $group ); 105 106 $not_group_menu_item = array(); 107 108 $this->go_to( $group_url ); 109 110 ob_start(); 111 bp_get_options_nav( $group->slug ); 112 $output = ob_get_clean(); 113 114 preg_match_all( '/href=["\']?([^"\']*)["\' ]/is', $output, $hrefs ); 115 116 foreach ( $hrefs[1] as $href ) { 117 if ( false === strpos( $href, $group_url ) ) { 118 $not_group_menu_item[] = $href; 119 } 120 } 121 122 $this->assertEmpty( $not_group_menu_item ); 123 124 // Clean up 125 $this->set_current_user( $old_current_user ); 126 } 127 128 /** 129 * @ticket BP6534 130 * @group bp_core_new_nav_default 131 */ 132 public function test_bp_core_new_nav_default() { 133 $bp = buddypress(); 134 $bp_options_nav = $bp->bp_options_nav; 135 $bp_nav = $bp->bp_nav; 136 137 $u = $this->factory->user->create(); 138 $old_current_user = get_current_user_id(); 139 $this->set_current_user( $u ); 140 141 $user_domain = bp_core_get_user_domain( $u ); 142 143 $this->go_to( trailingslashit( $user_domain ) . 'activity/mentions' ); 144 145 $this->assertTrue( 'mentions' === $bp->canonical_stack['action'] ); 146 147 bp_core_new_nav_default( array( 'parent_slug' => 'activity', 'subnav_slug' => 'mentions' ) ); 148 149 $this->assertTrue( ! isset( $bp->canonical_stack['action'] ) ); 150 151 // Clean up 152 $bp->bp_options_nav = $bp_options_nav; 153 $bp->bp_nav = $bp_nav; 154 $this->set_current_user( $old_current_user ); 155 } 156 157 /** 158 * @ticket BP6534 159 * @group bp_nav_item_has_subnav 160 */ 161 public function test_bp_nav_item_has_subnav() { 162 $bp = buddypress(); 163 $bp_options_nav = $bp->bp_options_nav; 164 $bp_nav = $bp->bp_nav; 165 166 $u = $this->factory->user->create(); 167 $old_current_user = get_current_user_id(); 168 $this->set_current_user( $u ); 169 170 $user_domain = bp_core_get_user_domain( $u ); 171 172 $this->go_to( $user_domain ); 173 174 bp_core_new_subnav_item( array( 175 'name' => 'Bar', 176 'slug' => 'bar', 177 'parent_url' => trailingslashit( $user_domain . 'bar' ), 178 'parent_slug' => 'bar', 179 'screen_function' => 'bar_screen_function', 180 'position' => 10 181 ) ); 182 183 $this->assertTrue( bp_nav_item_has_subnav( 'bar' ) ); 184 185 // Clean up 186 $bp->bp_options_nav = $bp_options_nav; 187 $bp->bp_nav = $bp_nav; 188 $this->set_current_user( $old_current_user ); 189 } 190 191 /** 192 * @ticket BP6534 193 * @group bp_core_remove_nav_item 194 * @group bp_core_remove_subnav_item 195 * @group bp_nav_item_has_subnav 196 */ 197 public function test_bp_core_remove_nav_item() { 198 $bp = buddypress(); 199 $bp_options_nav = $bp->bp_options_nav; 200 $bp_nav = $bp->bp_nav; 201 202 $u = $this->factory->user->create(); 203 $old_current_user = get_current_user_id(); 204 $this->set_current_user( $u ); 205 206 $user_domain = bp_core_get_user_domain( $u ); 207 208 $this->go_to( $user_domain ); 209 210 bp_core_new_nav_item( array( 211 'name' => 'Foo', 212 'slug' => 'foo', 213 'position' => 80, 214 'screen_function' => 'foo_screen_function', 215 'default_subnav_slug' => 'bar' 216 ) ); 217 218 bp_core_new_subnav_item( array( 219 'name' => 'Bar', 220 'slug' => 'bar', 221 'parent_url' => trailingslashit( $user_domain . 'bar' ), 222 'parent_slug' => 'foo', 223 'screen_function' => 'bar_screen_function', 224 'position' => 10 225 ) ); 226 227 bp_core_remove_nav_item( 'foo' ); 228 229 $this->assertFalse( bp_nav_item_has_subnav( 'bar' ) ); 230 231 // Clean up 232 $bp->bp_options_nav = $bp_options_nav; 233 $bp->bp_nav = $bp_nav; 234 $this->set_current_user( $old_current_user ); 235 } 236 237 /** 238 * @ticket BP6534 239 * @group bp_core_reset_subnav_items 240 */ 241 public function test_bp_core_reset_subnav_items() { 242 $bp = buddypress(); 243 $bp_options_nav = $bp->bp_options_nav; 244 $bp_nav = $bp->bp_nav; 245 246 $u = $this->factory->user->create(); 247 $old_current_user = get_current_user_id(); 248 $this->set_current_user( $u ); 249 250 $user_domain = bp_core_get_user_domain( $u ); 251 252 $this->go_to( $user_domain ); 253 254 bp_core_new_subnav_item( array( 255 'name' => 'Bar', 256 'slug' => 'bar', 257 'parent_url' => trailingslashit( $user_domain . 'bar' ), 258 'parent_slug' => 'bar', 259 'screen_function' => 'bar_screen_function', 260 'position' => 10 261 ) ); 262 263 $this->assertTrue( bp_nav_item_has_subnav( 'bar' ) ); 264 265 bp_core_reset_subnav_items( 'bar' ); 266 267 $this->assertFalse( bp_nav_item_has_subnav( 'bar' ) ); 268 269 // Clean up 270 $bp->bp_options_nav = $bp_options_nav; 271 $bp->bp_nav = $bp_nav; 272 $this->set_current_user( $old_current_user ); 273 } 92 274 } -
tests/phpunit/testcases/core/nav/bpCoreMaybeHookNewSubnavScreenFunction.php
diff --git tests/phpunit/testcases/core/nav/bpCoreMaybeHookNewSubnavScreenFunction.php tests/phpunit/testcases/core/nav/bpCoreMaybeHookNewSubnavScreenFunction.php index 2ebc74c..5aa4b24 100644
class BP_Tests_Core_Nav_BpCoreMaybeHookNewSubnavScreenFunction extends BP_UnitTe 82 82 $old_bp_nav = buddypress()->bp_nav; 83 83 $old_default_component = buddypress()->default_component; 84 84 buddypress()->default_component = 'foo'; 85 buddypress()->bp_nav = array( 86 'foo' =>array(87 'show_for_displayed_user' => true,88 ),89 ) ;85 86 bp_core_new_nav_item( array( 87 'name' => 'Foo', 88 'slug' => 'foo', 89 ) ); 90 90 91 91 $subnav_item = array( 92 92 'user_has_access' => false, … … class BP_Tests_Core_Nav_BpCoreMaybeHookNewSubnavScreenFunction extends BP_UnitTe 94 94 95 95 // Just test relevant info 96 96 $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item ); 97 97 98 $this->assertSame( 'failure', $found['status'] ); 98 99 $this->assertSame( bp_core_get_user_domain( $u2 ), $found['redirect_args']['root'] ); 99 100 … … class BP_Tests_Core_Nav_BpCoreMaybeHookNewSubnavScreenFunction extends BP_UnitTe 114 115 $old_bp_nav = buddypress()->bp_nav; 115 116 $old_default_component = buddypress()->default_component; 116 117 buddypress()->default_component = 'foo'; 117 buddypress()->bp_nav = array( 118 'foo' => array( 119 'show_for_displayed_user' => false, 120 ), 121 ); 118 119 bp_core_new_nav_item( array( 120 'name' => 'Foo', 121 'slug' => 'foo', 122 'show_for_displayed_user' => false, 123 ) ); 122 124 123 125 $subnav_item = array( 124 126 'user_has_access' => false, -
tests/phpunit/testcases/core/nav/bpCoreNewNavItem.php
diff --git tests/phpunit/testcases/core/nav/bpCoreNewNavItem.php tests/phpunit/testcases/core/nav/bpCoreNewNavItem.php index b6f6439..7e13def 100644
class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 33 33 'default_subnav_slug' => 'foo-sub' 34 34 ); 35 35 36 $this->assertSame( buddypress()->bp_nav ['foo'], $expected );36 $this->assertSame( buddypress()->bp_nav->get()['foo'], $expected ); 37 37 38 38 // Clean up 39 39 buddypress()->bp_nav = $bp_nav; … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 41 41 } 42 42 43 43 public function test_group_nav() { 44 $bp_nav = buddypress()->bp_nav;45 46 44 $u = $this->factory->user->create(); 47 45 $g = $this->factory->group->create(); 48 46 $old_current_user = get_current_user_id(); … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 54 52 55 53 $this->go_to( bp_get_group_permalink( $group ) ); 56 54 57 $this->assertTrue( buddypress()-> bp_nav[ $group->slug ]['position'] === -1 );55 $this->assertTrue( buddypress()->groups->nav->{ $group->slug }['position'] === -1 ); 58 56 59 57 // Clean up 60 buddypress()->bp_nav = $bp_nav;61 58 $this->set_current_user( $old_current_user ); 62 59 } 63 60 … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 96 93 ); 97 94 bp_core_new_nav_item( $args ); 98 95 99 $this->assertSame( 'foo', buddypress()->bp_nav ['foo']['css_id'] );96 $this->assertSame( 'foo', buddypress()->bp_nav->get()['foo']['css_id'] ); 100 97 } 101 98 102 99 public function test_css_id_should_be_respected() { … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 107 104 ); 108 105 bp_core_new_nav_item( $args ); 109 106 110 $this->assertSame( 'bar', buddypress()->bp_nav ['foo']['css_id'] );107 $this->assertSame( 'bar', buddypress()->bp_nav->get()['foo']['css_id'] ); 111 108 } 112 109 113 110 public function test_show_for_displayed_user_false_should_force_function_to_return_false_when_bp_user_has_access_is_also_false() { … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 145 142 'default_subnav_slug' => 'general' 146 143 ); 147 144 148 $this->assertSame( buddypress()->bp_nav ['settings'], $expected );145 $this->assertSame( buddypress()->bp_nav->settings, $expected ); 149 146 150 147 // Clean up 151 148 buddypress()->bp_nav = $bp_nav; … … class BP_Tests_Core_Nav_BpCoreNewNavItem extends BP_UnitTestCase { 184 181 'default_subnav_slug' => 'woof-one' 185 182 ); 186 183 187 $this->assertSame( buddypress()->bp_nav ['woof'], $expected );184 $this->assertSame( buddypress()->bp_nav->woof, $expected ); 188 185 189 186 // Clean up 190 187 buddypress()->bp_nav = $bp_nav; -
tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php
diff --git tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php index cf07a2f..e88413a 100644
class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 37 37 'show_in_admin_bar' => false, 38 38 ); 39 39 40 $this->assertSame( buddypress()->bp_options_nav ['foo']['foo'], $expected );40 $this->assertSame( buddypress()->bp_options_nav->foo['foo'], $expected ); 41 41 42 42 // Clean up 43 43 buddypress()->bp_options_nav = $bp_options_nav; … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 114 114 'link' => 'https://buddypress.org/', 115 115 ) ); 116 116 117 $this->assertSame( 'https://buddypress.org/', buddypress()->bp_options_nav ['foo']['bar']['link'] );117 $this->assertSame( 'https://buddypress.org/', buddypress()->bp_options_nav->foo['bar']['link'] ); 118 118 119 119 buddypress()->bp_options_nav = $bp_options_nav; 120 120 } … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 130 130 'screen_function' => 'foo', 131 131 ) ); 132 132 133 $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav ['foo']['bar']['link'] );133 $this->assertSame( 'http://example.com/foo/bar/', buddypress()->bp_options_nav->foo['bar']['link'] ); 134 134 135 135 buddypress()->bp_options_nav = $bp_options_nav; 136 136 } … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 140 140 $bp_options_nav = buddypress()->bp_options_nav; 141 141 142 142 // fake the parent 143 buddypress()->bp_nav = array( 144 'foo' => array( 145 'default_subnav_slug' => 'bar', 146 ), 147 ); 143 bp_core_new_nav_item( array( 144 'name' => 'Foo', 145 'slug' => 'foo', 146 'position' => 25, 147 'screen_function' => 'foo', 148 'default_subnav_slug' => 'bar' 149 ) ); 148 150 149 151 bp_core_new_subnav_item( array( 150 152 'name' => 'bar', … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 154 156 'screen_function' => 'foo', 155 157 ) ); 156 158 157 $this->assertSame( 'http://example.com/foo/', buddypress()->bp_options_nav ['foo']['bar']['link'] );159 $this->assertSame( 'http://example.com/foo/', buddypress()->bp_options_nav->foo['bar']['link'] ); 158 160 159 161 // clean up 160 162 buddypress()->bp_nav = $bp_nav; … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 171 173 ) ); 172 174 173 175 $expected = bp_get_root_domain() . 'foo/bar/'; 174 $this->assertSame( $expected, buddypress()->bp_options_nav ['foo']['bar']['link'] );176 $this->assertSame( $expected, buddypress()->bp_options_nav->foo['bar']['link'] ); 175 177 } 176 178 177 179 public function test_should_trailingslash_link_when_link_is_autogenerated_not_using_slug() { … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 192 194 ) ); 193 195 194 196 $expected = bp_get_root_domain() . 'foo-parent/'; 195 $this->assertSame( $expected, buddypress()->bp_options_nav ['foo-parent']['bar']['link'] );197 $this->assertSame( $expected, buddypress()->bp_options_nav->get()['foo-parent']['bar']['link'] ); 196 198 } 197 199 198 200 /** … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 210 212 'link' => $link, 211 213 ) ); 212 214 213 $this->assertSame( $link, buddypress()->bp_options_nav ['foo']['bar']['link'] );215 $this->assertSame( $link, buddypress()->bp_options_nav->foo['bar']['link'] ); 214 216 } 215 217 216 218 public function test_should_return_false_if_site_admin_only_and_current_user_cannot_bp_moderate() { … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 238 240 ); 239 241 bp_core_new_subnav_item( $args ); 240 242 241 $this->assertSame( 'foo', buddypress()->bp_options_nav ['parent']['foo']['css_id'] );243 $this->assertSame( 'foo', buddypress()->bp_options_nav->parent['foo']['css_id'] ); 242 244 } 243 245 244 246 public function test_css_id_should_be_respected() { … … class BP_Tests_Core_Nav_BpCoreNewSubnavItem extends BP_UnitTestCase { 252 254 ); 253 255 bp_core_new_subnav_item( $args ); 254 256 255 $this->assertSame( 'bar', buddypress()->bp_options_nav ['parent']['foo']['css_id'] );257 $this->assertSame( 'bar', buddypress()->bp_options_nav->parent['foo']['css_id'] ); 256 258 } 257 259 } -
tests/phpunit/testcases/groups/class-bp-group-extension.php
diff --git tests/phpunit/testcases/groups/class-bp-group-extension.php tests/phpunit/testcases/groups/class-bp-group-extension.php index 55b12e5..b66fd0c 100644
class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 219 219 * @group enable_nav_item 220 220 */ 221 221 public function test_enable_nav_item_true() { 222 $old_options_nav = buddypress()->bp_options_nav;223 224 222 $g = $this->factory->group->create(); 225 223 $g_obj = groups_get_group( array( 'group_id' => $g ) ); 226 224 … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 231 229 232 230 $e->_register(); 233 231 234 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 235 236 // Clean up 237 buddypress()->bp_options_nav = $old_options_nav; 232 $this->assertTrue( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 238 233 } 239 234 240 235 /** 241 236 * @group enable_nav_item 242 237 */ 243 238 public function test_enable_nav_item_false() { 244 $old_options_nav = buddypress()->bp_options_nav;245 246 239 $g = $this->factory->group->create(); 247 240 $g_obj = groups_get_group( array( 'group_id' => $g ) ); 248 241 … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 253 246 254 247 $e->_register(); 255 248 256 $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 257 258 // Clean up 259 buddypress()->bp_options_nav = $old_options_nav; 249 $this->assertFalse( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 260 250 } 261 251 262 252 /** 263 253 * @group visibility 264 254 */ 265 255 public function test_visibility_private() { 266 $old_options_nav = buddypress()->bp_options_nav;267 256 $old_current_user = get_current_user_id(); 268 257 269 258 $g = $this->factory->group->create( array( … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 278 267 $this->set_current_user( 0 ); 279 268 $this->go_to( bp_get_group_permalink( $g_obj ) ); 280 269 $e->_register(); 281 $this->assertFalse( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 282 283 // Clean up 284 buddypress()->bp_options_nav = $old_options_nav; 270 $this->assertFalse( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 285 271 286 272 // Test as group member 287 273 $u = $this->factory->user->create(); … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 289 275 $this->add_user_to_group( $u, $g ); 290 276 $this->go_to( bp_get_group_permalink( $g_obj ) ); 291 277 $e->_register(); 292 $this->assertTrue( isset( buddypress()-> bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );278 $this->assertTrue( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 293 279 294 280 // Clean up 295 buddypress()->bp_options_nav = $old_options_nav;296 281 $this->set_current_user( $old_current_user ); 297 282 } 298 283 … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 306 291 * @see https://buddypress.trac.wordpress.org/ticket/4785 307 292 */ 308 293 public function test_visibility_public() { 309 $old_options_nav = buddypress()->bp_options_nav;310 294 $old_current_user = get_current_user_id(); 311 295 312 296 $g = $this->factory->group->create( array( … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 321 305 $this->set_current_user( 0 ); 322 306 $this->go_to( bp_get_group_permalink( $g_obj ) ); 323 307 $e->_register(); 324 $this->assertTrue( isset( buddypress()->bp_options_nav[ $g_obj->slug ][ $e->slug ] ) ); 325 326 // Clean up 327 buddypress()->bp_options_nav = $old_options_nav; 308 $this->assertTrue( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 328 309 329 310 // Test as group member 330 311 $u = $this->factory->user->create(); … … class BP_Tests_Group_Extension_TestCases extends BP_UnitTestCase { 332 313 $this->add_user_to_group( $u, $g ); 333 314 $this->go_to( bp_get_group_permalink( $g_obj ) ); 334 315 $e->_register(); 335 $this->assertTrue( isset( buddypress()-> bp_options_nav[ $g_obj->slug ][ $e->slug ] ) );316 $this->assertTrue( isset( buddypress()->groups->sub_nav->{ $g_obj->slug }[ $e->slug ] ) ); 336 317 337 318 // Clean up 338 buddypress()->bp_options_nav = $old_options_nav;339 319 $this->set_current_user( $old_current_user ); 340 320 } 341 321 -
tests/phpunit/testcases/routing/anonymous.php
diff --git tests/phpunit/testcases/routing/anonymous.php tests/phpunit/testcases/routing/anonymous.php index e83776f..130b338 100644
class BP_Tests_Routing_Anonymous extends BP_UnitTestCase { 10 10 11 11 function test_nav_menu() { 12 12 $this->go_to( '/' ); 13 $this->assertEmpty( buddypress()->bp_nav );13 $this->assertEmpty( buddypress()->bp_nav->get() ); 14 14 } 15 15 } -
tests/phpunit/testcases/routing/core.php
diff --git tests/phpunit/testcases/routing/core.php tests/phpunit/testcases/routing/core.php index 30f9a8e..e703ea0 100644
class BP_Tests_Routing_Core extends BP_UnitTestCase { 24 24 25 25 function test_nav_menu() { 26 26 $this->go_to( '/' ); 27 $this->assertArrayHasKey( 'activity', buddypress()->bp_nav );28 $this->assertArrayHasKey( 'profile', buddypress()->bp_nav );27 $this->assertArrayHasKey( 'activity', buddypress()->bp_nav->get() ); 28 $this->assertArrayHasKey( 'profile', buddypress()->bp_nav->get() ); 29 29 } 30 30 }