Changeset 13442 for trunk/src/bp-core/classes/class-bp-component.php
- Timestamp:
- 03/27/2023 06:19:06 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-component.php
r13432 r13442 187 187 */ 188 188 public $directory_title = ''; 189 190 /** 191 * Component's main nav items. 192 * 193 * @since 12.0.0 194 * @var array 195 */ 196 public $main_nav = array(); 197 198 /** 199 * Component's main nav sub items. 200 * 201 * @since 12.0.0 202 * @var array 203 */ 204 public $sub_nav = array(); 189 205 190 206 /** Methods ***************************************************************/ … … 529 545 530 546 // Setup navigation. 531 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 547 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 9 ); 548 549 // Generate navigation. 550 add_action( 'bp_setup_nav', array( $this, 'generate_nav' ), 10, 0 ); 532 551 533 552 // Setup WP Toolbar menus. … … 598 617 * 599 618 * @since 1.5.0 600 * 601 * @see bp_core_new_nav_item() For a description of the $main_nav 602 * parameter formatting. 603 * @see bp_core_new_subnav_item() For a description of how each item 604 * in the $sub_nav parameter array should be formatted. 619 * @since 12.0.0 Uses `BP_Component::$main_nav` && `BP_Component::$sub_nav` to globalize nav items. 605 620 * 606 621 * @param array $main_nav Optional. Passed directly to bp_core_new_nav_item(). … … 611 626 */ 612 627 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 613 628 if ( isset( $main_nav['slug'] ) ) { 629 // Always set the component ID. 630 $this->main_nav['component_id'] = $this->id; 631 632 if ( ! isset( $main_nav['rewrite_id'] ) ) { 633 $this->main_nav['rewrite_id'] = 'bp_member_' . str_replace( '-', '_', $main_nav['slug'] ); 634 } elseif ( ! $main_nav['rewrite_id'] ) { 635 unset( $main_nav['rewrite_id'] ); 636 } 637 638 $this->main_nav = array_merge( $this->main_nav, $main_nav ); 639 640 // Sub nav items are not required. 641 if ( ! empty( $sub_nav ) ) { 642 foreach( (array) $sub_nav as $nav ) { 643 if ( ! isset( $nav['slug'], $nav['parent_slug'] ) ) { 644 continue; 645 } 646 647 if ( ! isset( $nav['rewrite_id'] ) ) { 648 $nav['rewrite_id'] = 'bp_member_' . str_replace( '-', '_', $nav['parent_slug'] ) . '_' . str_replace( '-', '_', $nav['slug'] ); 649 } elseif ( ! $nav['rewrite_id'] ) { 650 unset( $nav['rewrite_id'] ); 651 } 652 653 $this->sub_nav[] = $nav; 654 } 655 } 656 } 657 } 658 659 /** 660 * Generate component navigation using the nav/subnav set up in `BP_Component::setup_nav()`. 661 * 662 * @since 12.0.0 663 * 664 * @see bp_core_new_nav_item() For a description of the $main_nav 665 * parameter formatting. 666 * @see bp_core_new_subnav_item() For a description of how each item 667 * in the $sub_nav parameter array should be formatted. 668 */ 669 public function generate_nav() { 614 670 // No sub nav items without a main nav item. 615 if ( !empty( $main_nav ) ) { 616 // Always set the component ID. 617 $main_nav['component_id'] = $this->id; 618 619 bp_core_new_nav_item( $main_nav, 'members' ); 671 if ( $this->main_nav ) { 672 bp_core_new_nav_item( $this->main_nav, 'members' ); 620 673 621 674 // Sub nav items are not required. 622 if ( !empty( $sub_nav )) {623 foreach( (array) $ sub_nav as $nav ) {675 if ( $this->sub_nav ) { 676 foreach( (array) $this->sub_nav as $nav ) { 624 677 bp_core_new_subnav_item( $nav, 'members' ); 625 678 }
Note: See TracChangeset
for help on using the changeset viewer.