Changeset 13450
- Timestamp:
- 04/12/2023 10:12:37 PM (18 months ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/classes/class-bp-activity-component.php
r13441 r13450 239 239 240 240 /** 241 * Set up component navigation. 242 * 243 * @since 1.5.0 244 * 245 * @see BP_Component::setup_nav() for a description of arguments. 246 * 247 * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 248 * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 249 */ 250 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 251 252 // Stop if there is no user displayed or logged in. 253 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 254 return; 255 } 256 241 * Register component navigation. 242 * 243 * @since 12.0.0 244 * 245 * @see `BP_Component::register_nav()` for a description of arguments. 246 * 247 * @param array $main_nav Optional. See `BP_Component::register_nav()` for description. 248 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for description. 249 */ 250 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 257 251 $slug = bp_get_activity_slug(); 258 252 … … 277 271 278 272 // Check @mentions. 279 if ( bp_activity_do_mentions() ) { 280 $sub_nav[] = array( 281 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ), 282 'slug' => 'mentions', 283 'parent_slug' => $slug, 284 'screen_function' => 'bp_activity_screen_mentions', 285 'position' => 20, 286 'item_css_id' => 'activity-mentions' 287 ); 288 } 273 $sub_nav[] = array( 274 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ), 275 'slug' => 'mentions', 276 'parent_slug' => $slug, 277 'screen_function' => 'bp_activity_screen_mentions', 278 'position' => 20, 279 'item_css_id' => 'activity-mentions', 280 'generate' => bp_activity_do_mentions(), 281 ); 289 282 290 283 // Favorite activity items. 291 if ( bp_activity_can_favorite() ) { 292 $sub_nav[] = array( 293 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ), 294 'slug' => 'favorites', 295 'parent_slug' => $slug, 296 'screen_function' => 'bp_activity_screen_favorites', 297 'position' => 30, 298 'item_css_id' => 'activity-favs' 299 ); 300 } 284 $sub_nav[] = array( 285 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ), 286 'slug' => 'favorites', 287 'parent_slug' => $slug, 288 'screen_function' => 'bp_activity_screen_favorites', 289 'position' => 30, 290 'item_css_id' => 'activity-favs', 291 'generate' => bp_activity_can_favorite(), 292 ); 301 293 302 294 // Additional menu if friends is active. … … 308 300 'screen_function' => 'bp_activity_screen_friends', 309 301 'position' => 40, 310 'item_css_id' => 'activity-friends' 311 ) 302 'item_css_id' => 'activity-friends', 303 ); 312 304 } 313 305 … … 324 316 } 325 317 326 parent:: setup_nav( $main_nav, $sub_nav );318 parent::register_nav( $main_nav, $sub_nav ); 327 319 } 328 320 -
trunk/src/bp-blogs/classes/class-bp-blogs-component.php
r13442 r13450 199 199 200 200 /** 201 * Set up component navigation for bp-blogs. 202 * 203 * @see BP_Component::setup_nav() for a description of arguments. 204 * 205 * @param array $main_nav Optional. See BP_Component::setup_nav() for 201 * Register component navigation. 202 * 203 * @since 12.0.0 204 * 205 * @see `BP_Component::register_nav()` for a description of arguments. 206 * 207 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 206 208 * description. 207 * @param array $sub_nav Optional. See BP_Component::setup_nav()for209 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 208 210 * description. 209 211 */ 210 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 211 212 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 212 213 /** 213 214 * Blog/post/comment menus should not appear on single WordPress setups. … … 219 220 } 220 221 221 // Stop if there is no user displayed or logged in.222 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {223 return;224 }225 226 222 $slug = bp_get_blogs_slug(); 227 223 228 // Add 'Sites' to the main navigation.229 $count = (int) bp_get_total_blog_count_for_user();230 $class = ( 0 === $count ) ? 'no-count' : 'count';231 $nav_text = sprintf(232 /* translators: %s: Site count for the current user */233 __( 'Sites %s', 'buddypress' ),234 sprintf(235 '<span class="%s">%s</span>',236 esc_attr( $class ),237 esc_html( $count )238 )239 );240 224 $main_nav = array( 241 'name' => $nav_text,225 'name' => __( 'Sites', 'buddypress' ), 242 226 'slug' => $slug, 243 227 'position' => 30, … … 256 240 257 241 // Setup navigation. 242 parent::register_nav( $main_nav, $sub_nav ); 243 } 244 245 /** 246 * Set up component navigation. 247 * 248 * @since 1.5.0 249 * @since 12.0.0 Used to customize the main navigation name. 250 * 251 * @see `BP_Component::setup_nav()` for a description of arguments. 252 * 253 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 254 * description. 255 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 256 * description. 257 */ 258 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 259 // Only grab count if we're on a user page. 260 if ( is_multisite() && bp_is_user() && isset( $this->main_nav['name'] ) ) { 261 // Add the number of sites to the main nav. 262 $count = (int) bp_get_total_blog_count_for_user(); 263 $class = ( 0 === $count ) ? 'no-count' : 'count'; 264 $this->main_nav['name'] = sprintf( 265 /* translators: %s: Site count for the displayed user */ 266 __( 'Sites %s', 'buddypress' ), 267 sprintf( 268 '<span class="%s">%s</span>', 269 esc_attr( $class ), 270 bp_core_number_format( $count ) 271 ) 272 ); 273 } 274 258 275 parent::setup_nav( $main_nav, $sub_nav ); 259 276 } -
trunk/src/bp-core/admin/bp-core-admin-functions.php
r13449 r13450 489 489 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components' ), 'admin.php' ) ), 490 490 'name' => __( 'Components', 'buddypress' ), 491 ), 492 '1' => array( 493 'id' => 'bp-rewrites', 494 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-rewrites' ), 'admin.php' ) ), 495 'name' => __( 'URLs', 'buddypress' ), 491 496 ), 492 497 '2' => array( -
trunk/src/bp-core/bp-core-caps.php
r13405 r13450 305 305 306 306 /** 307 * Callback function to inform whether current user can moderate the community. 308 * 309 * @since 12.0.0 310 * 311 * @return boolean True if current user can moderate the community. False otherwise. 312 */ 313 function bp_current_user_can_moderate() { 314 return bp_current_user_can( 'bp_moderate' ); 315 } 316 317 /** 307 318 * Check whether the specified user has a given capability on a given site. 308 319 * -
trunk/src/bp-core/classes/class-bp-admin.php
r13431 r13450 143 143 */ 144 144 private function includes() { 145 require( $this->admin_dir . 'bp-core-admin-actions.php' ); 146 require( $this->admin_dir . 'bp-core-admin-settings.php' ); 147 require( $this->admin_dir . 'bp-core-admin-functions.php' ); 148 require( $this->admin_dir . 'bp-core-admin-components.php' ); 149 require( $this->admin_dir . 'bp-core-admin-tools.php' ); 150 require( $this->admin_dir . 'bp-core-admin-optouts.php' ); 145 require $this->admin_dir . 'bp-core-admin-actions.php'; 146 require $this->admin_dir . 'bp-core-admin-settings.php'; 147 require $this->admin_dir . 'bp-core-admin-functions.php'; 148 require $this->admin_dir . 'bp-core-admin-components.php'; 149 require $this->admin_dir . 'bp-core-admin-rewrites.php'; 150 require $this->admin_dir . 'bp-core-admin-tools.php'; 151 require $this->admin_dir . 'bp-core-admin-optouts.php'; 151 152 } 152 153 … … 274 275 $this->submenu_pages['settings']['bp-components'] = $bp_components_page; 275 276 $hooks[] = $bp_components_page; 277 278 $bp_rewrite_settings_page = add_submenu_page( 279 $this->settings_page, 280 __( 'BuddyPress URLs', 'buddypress' ), 281 __( 'BuddyPress URLs', 'buddypress' ), 282 $this->capability, 283 'bp-rewrites', 284 'bp_core_admin_rewrites_settings' 285 ); 286 287 $this->submenu_pages['settings']['bp-rewrites'] = $bp_rewrite_settings_page; 288 $hooks[] = $bp_rewrite_settings_page; 276 289 277 290 $bp_settings_page = add_submenu_page( … … 375 388 foreach( $hooks as $hook ) { 376 389 add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' ); 390 391 if ( 'settings_page_bp-rewrites' === $hook ) { 392 add_action( "load-{$hook}", 'bp_core_admin_rewrites_load' ); 393 } 377 394 } 378 395 … … 614 631 615 632 // Settings pages. 616 remove_submenu_page( $this->settings_page, 'bp-settings' ); 617 remove_submenu_page( $this->settings_page, 'bp-credits' ); 633 remove_submenu_page( $this->settings_page, 'bp-rewrites' ); 634 remove_submenu_page( $this->settings_page, 'bp-settings' ); 635 remove_submenu_page( $this->settings_page, 'bp-credits' ); 618 636 619 637 // Network Admin Tools. … … 1397 1415 ), 1398 1416 ), 1417 1418 // 12.0 1419 'bp-rewrites-ui' => array( 1420 'file' => "{$url}rewrites-ui.js", 1421 'dependencies' => array(), 1422 'footer' => true, 1423 ), 1399 1424 ) ); 1400 1425 -
trunk/src/bp-core/classes/class-bp-component.php
r13442 r13450 544 544 add_action( 'bp_late_include', array( $this, 'late_includes' ) ); 545 545 546 // Generate navigation. 547 add_action( 'bp_setup_nav', array( $this, 'register_nav' ), 7 ); 548 546 549 // Setup navigation. 547 550 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 );551 551 552 552 // Setup WP Toolbar menus. … … 614 614 615 615 /** 616 * Set up component navigation. 617 * 618 * @since 1.5.0 619 * @since 12.0.0 Uses `BP_Component::$main_nav` && `BP_Component::$sub_nav` to globalize nav items. 616 * Registers nav items globalizing them into `BP_Component::$main_nav` & `BP_Component::$sub_nav` properties. 617 * 618 * @since 12.0.0 620 619 * 621 620 * @param array $main_nav Optional. Passed directly to bp_core_new_nav_item(). … … 625 624 * function for a description. 626 625 */ 627 public function setup_nav( $main_nav = array(), $sub_nav = array() ) {626 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 628 627 if ( isset( $main_nav['slug'] ) ) { 629 628 // Always set the component ID. … … 658 657 659 658 /** 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() { 670 // No sub nav items without a main nav item. 671 if ( $this->main_nav ) { 672 bp_core_new_nav_item( $this->main_nav, 'members' ); 659 * Set up component navigation. 660 * 661 * @since 1.5.0 662 * @since 12.0.0 Uses the registered navigations to generate it. 663 * 664 * @param array $main_nav Optional. Passed directly to bp_core_new_nav_item(). 665 * See that function for a description. 666 * @param array $sub_nav Optional. Multidimensional array, each item in 667 * which is passed to bp_core_new_subnav_item(). See that 668 * function for a description. 669 */ 670 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 671 // Use the registered navigations if available. 672 if ( empty( $main_nav ) && $this->main_nav ) { 673 // Don't generate navigation if there's no member. 674 if ( ! is_user_logged_in() && ! bp_is_user() ) { 675 return; 676 } 677 678 $generate = true; 679 if ( isset( $this->main_nav['generate'] ) ) { 680 $generate = is_callable( $this->main_nav['generate'] ) ? call_user_func( $this->main_nav['generate'] ) : (bool) $this->main_nav['generate']; 681 unset( $this->main_nav['generate'] ); 682 } 683 684 if ( bp_displayed_user_has_front_template() ) { 685 bp_core_new_nav_item( 686 array( 687 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 688 'slug' => 'front', 689 'position' => 5, 690 'screen_function' => 'bp_members_screen_display_profile', 691 'default_subnav_slug' => 'public', 692 ), 693 'members' 694 ); 695 } 696 697 if ( 'xprofile' === $this->id ) { 698 $extra_subnavs = wp_list_filter( 699 buddypress()->members->sub_nav, 700 array( 701 'slug' => 'change-avatar', 702 'screen_function' => 'bp_members_screen_change_cover_image', 703 ), 704 'OR' 705 ); 706 707 $this->sub_nav = array_merge( $this->sub_nav, $extra_subnavs ); 708 } 709 710 // No sub nav items without a main nav item. 711 if ( $this->main_nav && $generate) { 712 if ( isset( $this->main_nav['user_has_access_callback'] ) && is_callable( $this->main_nav['user_has_access_callback'] ) ) { 713 $this->main_nav['show_for_displayed_user'] = call_user_func( $this->main_nav['user_has_access_callback'] ); 714 unset( $this->main_nav['user_has_access_callback'] ); 715 } 716 717 bp_core_new_nav_item( $this->main_nav, 'members' ); 718 719 // Sub nav items are not required. 720 if ( $this->sub_nav ) { 721 foreach( (array) $this->sub_nav as $nav ) { 722 if ( isset( $nav['user_has_access_callback'] ) && is_callable( $nav['user_has_access_callback'] ) ) { 723 $nav['user_has_access'] = call_user_func( $nav['user_has_access_callback'] ); 724 unset( $nav['user_has_access_callback'] ); 725 } 726 727 if ( isset( $nav['generate'] ) ) { 728 if ( is_callable( $nav['generate'] ) ) { 729 $generate_sub = call_user_func( $nav['generate'] ); 730 } else { 731 $generate_sub = (bool) $nav['generate']; 732 } 733 734 unset( $nav['generate'] ); 735 736 if ( ! $generate_sub ) { 737 continue; 738 } 739 } 740 741 bp_core_new_subnav_item( $nav, 'members' ); 742 } 743 } 744 } 745 746 /* 747 * If the `$main_nav` is populated, it means a plugin is not registering its navigation using 748 * `BP_Component::register_nav()` to enjoy the BP Rewrites API slug customization. Let's simply 749 * preverve backward compatibility in this case. 750 */ 751 } elseif ( ! empty( $main_nav ) && ! $this->main_nav ) { 752 // Always set the component ID. 753 $main_nav['component_id'] = $this->id; 754 $this->main_nav = $main_nav; 755 756 bp_core_new_nav_item( $main_nav, 'members' ); 673 757 674 758 // Sub nav items are not required. 675 if ( $this->sub_nav ) { 676 foreach( (array) $this->sub_nav as $nav ) { 759 if ( ! empty( $sub_nav ) ) { 760 $this->sub_nav = $sub_nav; 761 762 foreach( (array) $sub_nav as $nav ) { 677 763 bp_core_new_subnav_item( $nav, 'members' ); 678 764 } -
trunk/src/bp-friends/classes/class-bp-friends-component.php
r13441 r13450 149 149 150 150 /** 151 * Set upcomponent navigation.152 * 153 * @since 1 .5.0154 * 155 * @see BP_Component::setup_nav()for a description of arguments.156 * 157 * @param array $main_nav Optional. See BP_Component::setup_nav()for151 * Register component navigation. 152 * 153 * @since 12.0.0 154 * 155 * @see `BP_Component::register_nav()` for a description of arguments. 156 * 157 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 158 158 * description. 159 * @param array $sub_nav Optional. See BP_Component::setup_nav()for159 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 160 160 * description. 161 161 */ 162 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 163 164 // Stop if there is no user displayed or logged in. 165 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 166 return; 167 } 168 169 $access = bp_core_can_edit_settings(); 162 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 170 163 $slug = bp_get_friends_slug(); 171 164 172 // Add 'Friends' to the main navigation.173 $count = friends_get_total_friend_count();174 $class = ( 0 === $count ) ? 'no-count' : 'count';175 176 $main_nav_name = sprintf(177 /* translators: %s: Friend count for the current user */178 __( 'Friends %s', 'buddypress' ),179 sprintf(180 '<span class="%s">%s</span>',181 esc_attr( $class ),182 esc_html( $count )183 )184 );185 186 165 $main_nav = array( 187 'name' => $main_nav_name,166 'name' => __( 'Friends', 'buddypress' ), 188 167 'slug' => $slug, 189 168 'position' => 60, … … 204 183 205 184 $sub_nav[] = array( 206 'name' => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ), 207 'slug' => 'requests', 208 'parent_slug' => $slug, 209 'screen_function' => 'friends_screen_requests', 210 'position' => 20, 211 'user_has_access' => $access, 212 ); 185 'name' => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ), 186 'slug' => 'requests', 187 'parent_slug' => $slug, 188 'screen_function' => 'friends_screen_requests', 189 'position' => 20, 190 'user_has_access' => false, 191 'user_has_access_callback' => 'bp_core_can_edit_settings', 192 ); 193 194 parent::register_nav( $main_nav, $sub_nav ); 195 } 196 197 /** 198 * Set up component navigation. 199 * 200 * @since 1.5.0 201 * 202 * @see `BP_Component::setup_nav()` for a description of arguments. 203 * 204 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 205 * description. 206 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 207 * description. 208 */ 209 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 210 // Only grab count if we're on a user page. 211 if ( bp_is_user() && isset( $this->main_nav['name'] ) ) { 212 // Add 'Friends' to the main navigation. 213 $count = friends_get_total_friend_count(); 214 $class = ( 0 === $count ) ? 'no-count' : 'count'; 215 $this->main_nav['name'] = sprintf( 216 /* translators: %s: Friend count for the current user */ 217 __( 'Friends %s', 'buddypress' ), 218 sprintf( 219 '<span class="%s">%s</span>', 220 esc_attr( $class ), 221 esc_html( $count ) 222 ) 223 ); 224 } 213 225 214 226 parent::setup_nav( $main_nav, $sub_nav ); -
trunk/src/bp-groups/classes/class-bp-groups-component.php
r13448 r13450 34 34 */ 35 35 public $current_group; 36 37 /**38 * Default group extension.39 *40 * @since 1.6.041 * @todo Is this used anywhere? Is this a duplicate of $default_extension?42 * @var string43 */44 var $default_component;45 36 46 37 /** … … 564 555 565 556 /** 557 * Register component navigation. 558 * 559 * @since 12.0.0 560 * 561 * @see `BP_Component::register_nav()` for a description of arguments. 562 * 563 * @param array $main_nav Optional. See `BP_Component::register_nav()` for description. 564 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for description. 565 */ 566 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 567 $slug = bp_get_groups_slug(); 568 569 // Add 'Groups' to the main navigation. 570 $main_nav = array( 571 'name' => _x( 'Groups', 'Group screen nav without counter', 'buddypress' ), 572 'slug' => $slug, 573 'position' => 70, 574 'screen_function' => 'groups_screen_my_groups', 575 'default_subnav_slug' => 'my-groups', 576 'item_css_id' => $this->id 577 ); 578 579 // Add the My Groups nav item. 580 $sub_nav[] = array( 581 'name' => __( 'Memberships', 'buddypress' ), 582 'slug' => 'my-groups', 583 'parent_slug' => $slug, 584 'screen_function' => 'groups_screen_my_groups', 585 'position' => 10, 586 'item_css_id' => 'groups-my-groups' 587 ); 588 589 if ( bp_is_active( 'groups', 'invitations' ) ) { 590 // Add the Group Invites nav item. 591 $sub_nav[] = array( 592 'name' => __( 'Invitations', 'buddypress' ), 593 'slug' => 'invites', 594 'parent_slug' => $slug, 595 'screen_function' => 'groups_screen_group_invites', 596 'position' => 30, 597 'user_has_access' => false, 598 'user_has_access_callback' => 'bp_core_can_edit_settings', 599 ); 600 } 601 602 parent::register_nav( $main_nav, $sub_nav ); 603 } 604 605 /** 566 606 * Set up component navigation. 567 607 * 568 608 * @since 1.5.0 569 * 570 * @see BP_Component::setup_nav() for a description of arguments. 571 * 572 * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 573 * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 609 * @since 12.0.0 Used to customize the main navigation name and set 610 * a Groups single item navigation. 611 * 612 * @see `BP_Component::setup_nav()` for a description of arguments. 613 * 614 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 615 * description. 616 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 617 * description. 574 618 */ 575 619 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 576 577 if ( is_user_logged_in() || bp_displayed_user_id() ) { 578 // Only grab count if we're on a user page. 579 if ( bp_is_user() ) { 580 $class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count'; 581 582 $nav_name = sprintf( 583 /* translators: %s: Group count for the current user */ 584 _x( 'Groups %s', 'Group screen nav with counter', 'buddypress' ), 585 sprintf( 586 '<span class="%s">%s</span>', 587 esc_attr( $class ), 588 bp_get_total_group_count_for_user() 589 ) 590 ); 591 } else { 592 $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' ); 593 } 594 595 $slug = bp_get_groups_slug(); 596 $access = bp_core_can_edit_settings(); 597 598 // Add 'Groups' to the main navigation. 599 $main_nav = array( 600 'name' => $nav_name, 601 'slug' => $slug, 602 'position' => 70, 603 'screen_function' => 'groups_screen_my_groups', 604 'default_subnav_slug' => 'my-groups', 605 'item_css_id' => $this->id 620 // Only grab count if we're on a user page. 621 if ( isset( $this->main_nav['name'] ) && bp_is_user() ) { 622 $class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count'; 623 $this->main_nav['name'] = sprintf( 624 /* translators: %s: Group count for the current user */ 625 _x( 'Groups %s', 'Group screen nav with counter', 'buddypress' ), 626 sprintf( 627 '<span class="%s">%s</span>', 628 esc_attr( $class ), 629 bp_get_total_group_count_for_user() 630 ) 606 631 ); 607 608 // Add the My Groups nav item.609 $sub_nav[] = array(610 'name' => __( 'Memberships', 'buddypress' ),611 'slug' => 'my-groups',612 'parent_slug' => $slug,613 'screen_function' => 'groups_screen_my_groups',614 'position' => 10,615 'item_css_id' => 'groups-my-groups'616 );617 618 if ( bp_is_active( 'groups', 'invitations' ) ) {619 // Add the Group Invites nav item.620 $sub_nav[] = array(621 'name' => __( 'Invitations', 'buddypress' ),622 'slug' => 'invites',623 'parent_slug' => $slug,624 'screen_function' => 'groups_screen_group_invites',625 'user_has_access' => $access,626 'position' => 30627 );628 }629 630 parent::setup_nav( $main_nav, $sub_nav );631 632 } 632 633 633 634 if ( bp_is_groups_component() && bp_is_single_item() ) { 634 635 // Reset sub nav.636 $sub_nav = array();637 638 635 /* 639 636 * The top-level Groups item is called 'Memberships' for legacy reasons. … … 661 658 ); 662 659 663 // If this is a private group, and the user is not a 664 // member and does not have an outstanding invitation, 665 // show a "Request Membership" nav item. 660 /* 661 * If this is a private group, and the user is not a member and does not 662 * have an outstanding invitation, how a "Request Membership" nav item. 663 */ 666 664 if ( bp_current_user_can( 'groups_request_membership', array( 'group_id' => $this->current_group->id ) ) ) { 667 668 665 $sub_nav[] = array( 669 666 'name' => _x( 'Request Membership','Group screen nav', 'buddypress' ), … … 676 673 677 674 if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) { 678 /** 679 * If the theme is using a custom front, create activity subnav. 680 */ 675 // If the theme is using a custom front, create activity subnav. 681 676 if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) { 682 677 $sub_nav[] = array( … … 692 687 } 693 688 694 /** 695 * Only add the members subnav if it's not the home's nav. 696 */ 689 // Only add the members subnav if it's not the home's nav. 697 690 $sub_nav[] = array( 698 691 'name' => sprintf( … … 804 797 bp_core_new_subnav_item( $nav, 'groups' ); 805 798 } 806 } 807 808 if ( isset( $this->current_group->user_has_access ) ) { 809 810 /** 811 * Fires at the end of the groups navigation setup if user has access. 812 * 813 * @since 1.0.2 814 * 815 * @param bool $user_has_access Whether or not user has access. 816 */ 817 do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 818 } else { 819 820 /** This action is documented in bp-groups/bp-groups-loader.php */ 821 do_action( 'groups_setup_nav'); 822 } 799 800 if ( isset( $this->current_group->user_has_access ) ) { 801 802 /** 803 * Fires at the end of the groups navigation setup if user has access. 804 * 805 * @since 1.0.2 806 * 807 * @param bool $user_has_access Whether or not user has access. 808 */ 809 do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 810 } else { 811 812 /** This action is documented in bp-groups/bp-groups-loader.php */ 813 do_action( 'groups_setup_nav'); 814 } 815 } 816 817 parent::setup_nav( $main_nav, $sub_nav ); 823 818 } 824 819 -
trunk/src/bp-members/classes/class-bp-members-component.php
r13443 r13450 423 423 * 424 424 * @since 6.0.0 425 * @deprecated 12.0.0 425 426 * 426 427 * @return array The Avatar and Cover image subnavs. 427 428 */ 428 429 public function get_avatar_cover_image_subnavs() { 429 $subnavs = array(); 430 431 $access = bp_core_can_edit_settings(); 432 $slug = bp_get_profile_slug(); 433 434 // Change Avatar. 435 if ( buddypress()->avatar->show_avatars ) { 436 $subnavs[] = array( 437 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ), 438 'slug' => 'change-avatar', 439 'parent_slug' => $slug, 440 'screen_function' => 'bp_members_screen_change_avatar', 441 'position' => 30, 442 'user_has_access' => $access 443 ); 444 } 445 446 // Change Cover image. 447 if ( bp_displayed_user_use_cover_image_header() ) { 448 $subnavs[] = array( 449 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ), 450 'slug' => 'change-cover-image', 451 'parent_slug' => $slug, 452 'screen_function' => 'bp_members_screen_change_cover_image', 453 'position' => 40, 454 'user_has_access' => $access 455 ); 456 } 457 458 return $subnavs; 459 } 460 461 /** 462 * Set up fall-back component navigation if XProfile is inactive. 463 * 464 * @since 1.5.0 465 * 466 * @see BP_Component::setup_nav() for a description of arguments. 467 * 468 * @param array $main_nav Optional. See BP_Component::setup_nav() for 430 _deprecated_function( __METHOD__, '12.0.0' ); 431 } 432 433 /** 434 * Register component navigation. 435 * 436 * @since 12.0.0 437 * 438 * @see `BP_Component::register_nav()` for a description of arguments. 439 * 440 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 469 441 * description. 470 * @param array $sub_nav Optional. See BP_Component::setup_nav()for442 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 471 443 * description. 472 444 */ 473 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 474 475 // Don't set up navigation if there's no member. 476 if ( ! is_user_logged_in() && ! bp_is_user() ) { 477 return; 478 } 479 480 $is_xprofile_active = bp_is_active( 'xprofile' ); 481 482 // Bail if XProfile component is active and there's no custom front page for the user. 483 if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) { 484 add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) ); 485 return; 486 } 487 445 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 488 446 // Set slug to profile in case the xProfile component is not active 489 447 $slug = bp_get_profile_slug(); 490 448 491 // Defaults to empty navs 492 $this->main_nav = array(); 493 $this->sub_nav = array(); 494 495 if ( ! $is_xprofile_active ) { 496 $this->main_nav = array( 497 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 498 'slug' => $slug, 499 'position' => 20, 500 'screen_function' => 'bp_members_screen_display_profile', 501 'default_subnav_slug' => 'public', 502 'item_css_id' => buddypress()->profile->id 503 ); 504 505 /** 506 * The xProfile component is active. 507 * 508 * We need to make sure the Change Avatar and Change Cover Image subnavs are 509 * added just like it was the case before. 510 */ 511 } else { 512 add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) ); 513 } 514 515 /** 516 * Setup the subnav items for the member profile. 517 * 518 * This is required in case there's a custom front or in case the xprofile component 519 * is not active. 520 */ 521 $this->sub_nav = array( 449 $main_nav = array( 450 'name' => _x( 'Profile', 'Member profile main navigation', 'buddypress' ), 451 'slug' => $slug, 452 'position' => 20, 453 'screen_function' => 'bp_members_screen_display_profile', 454 'default_subnav_slug' => 'public', 455 'item_css_id' => buddypress()->profile->id, 456 'generate' => ! bp_is_active( 'xprofile' ), 457 ); 458 459 $sub_nav[] = array( 522 460 'name' => _x( 'View', 'Member profile view', 'buddypress' ), 523 461 'slug' => 'public', 524 462 'parent_slug' => $slug, 525 463 'screen_function' => 'bp_members_screen_display_profile', 526 'position' => 10 527 ); 528 529 /** 530 * If there's a front template the members component nav 531 * will be there to display the user's front page. 532 */ 533 if ( bp_displayed_user_has_front_template() ) { 534 $main_nav = array( 535 'name' => _x( 'Home', 'Member Home page', 'buddypress' ), 536 'slug' => 'front', 537 'position' => 5, 538 'screen_function' => 'bp_members_screen_display_profile', 539 'default_subnav_slug' => 'public', 540 ); 541 542 // We need a dummy subnav for the front page to load. 543 $front_subnav = $this->sub_nav; 544 $front_subnav['parent_slug'] = 'front'; 545 546 // Set the subnav 547 $sub_nav[] = $front_subnav; 548 549 /** 550 * If the profile component is not active, we need to create a new 551 * nav to display the WordPress profile. 552 */ 553 if ( ! $is_xprofile_active ) { 554 add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) ); 555 } 556 557 /** 558 * If there's no front template and xProfile is not active, the members 559 * component nav will be there to display the WordPress profile 560 */ 561 } else { 562 $main_nav = $this->main_nav; 563 $sub_nav = array( $this->sub_nav ); 564 565 if ( ! $is_xprofile_active ) { 566 $sub_nav = array_merge( $sub_nav, $this->get_avatar_cover_image_subnavs() ); 567 } 568 } 569 570 parent::setup_nav( $main_nav, $sub_nav ); 464 'position' => 10, 465 'generate' => ! bp_is_active( 'xprofile' ), 466 ); 467 468 $sub_nav[] = array( 469 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ), 470 'slug' => 'change-avatar', 471 'parent_slug' => $slug, 472 'screen_function' => 'bp_members_screen_change_avatar', 473 'position' => 30, 474 'user_has_access' => false, 475 'user_has_access_callback' => 'bp_core_can_edit_settings', 476 'generate' => buddypress()->avatar->show_avatars, 477 ); 478 479 $sub_nav[] = array( 480 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ), 481 'slug' => 'change-cover-image', 482 'parent_slug' => $slug, 483 'screen_function' => 'bp_members_screen_change_cover_image', 484 'position' => 40, 485 'user_has_access' => false, 486 'user_has_access_callback' => 'bp_core_can_edit_settings', 487 'generate' => bp_displayed_user_use_cover_image_header(), 488 ); 489 490 parent::register_nav( $main_nav, $sub_nav ); 571 491 } 572 492 … … 577 497 * 578 498 * @since 2.6.0 499 * @deprecated 12.0.0 579 500 */ 580 501 public function setup_profile_nav() { 581 if ( empty( $this->main_nav ) || empty( $this->sub_nav ) ) { 582 return; 583 } 584 585 // Add the main nav 586 bp_core_new_nav_item( $this->main_nav, 'members' ); 587 588 // Add the sub nav item. 589 bp_core_new_subnav_item( $this->sub_nav, 'members' ); 590 591 // Get the Avatar and cover image subnavs. 592 $this->setup_xprofile_nav(); 502 _deprecated_function( __METHOD__, '12.0.0' ); 593 503 } 594 504 … … 597 507 * 598 508 * @since 6.0.0 509 * @deprecated 12.0.0 599 510 */ 600 511 public function setup_xprofile_nav() { 601 // Get the Avatar and cover image subnavs. 602 $items = $this->get_avatar_cover_image_subnavs(); 603 604 foreach ( $items as $item ) { 605 bp_core_new_subnav_item( $item, 'members' ); 606 } 512 _deprecated_function( __METHOD__, '12.0.0' ); 607 513 } 608 514 -
trunk/src/bp-messages/classes/class-bp-messages-component.php
r13442 r13450 190 190 191 191 /** 192 * Set up navigation for user pages. 193 * 194 * @param array $main_nav See {BP_Component::setup_nav()} for details. 195 * @param array $sub_nav See {BP_Component::setup_nav()} for details. 192 * Register component navigation. 193 * 194 * @since 12.0.0 195 * 196 * @param array $main_nav See `BP_Component::register_nav()` for details. 197 * @param array $sub_nav See `BP_Component::register_nav()` for details. 198 */ 199 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 200 $slug = bp_get_messages_slug(); 201 202 // Add 'Messages' to the main navigation. 203 $main_nav = array( 204 'name' => __( 'Messages', 'buddypress' ), 205 'slug' => $slug, 206 'position' => 50, 207 'show_for_displayed_user' => false, 208 'screen_function' => 'messages_screen_inbox', 209 'default_subnav_slug' => 'inbox', 210 'item_css_id' => $this->id, 211 'user_has_access_callback' => 'bp_core_can_edit_settings', 212 ); 213 214 // Add the subnav items to the profile. 215 $sub_nav[] = array( 216 'name' => __( 'Inbox', 'buddypress' ), 217 'slug' => 'inbox', 218 'parent_slug' => $slug, 219 'screen_function' => 'messages_screen_inbox', 220 'position' => 10, 221 'user_has_access' => false, 222 'user_has_access_callback' => 'bp_core_can_edit_settings', 223 ); 224 225 if ( bp_is_active( $this->id, 'star' ) ) { 226 $sub_nav[] = array( 227 'name' => __( 'Starred', 'buddypress' ), 228 'slug' => bp_get_messages_starred_slug(), 229 'parent_slug' => $slug, 230 'screen_function' => 'bp_messages_star_screen', 231 'position' => 11, 232 'user_has_access' => false, 233 'user_has_access_callback' => 'bp_core_can_edit_settings', 234 ); 235 } 236 237 $sub_nav[] = array( 238 'name' => __( 'Sent', 'buddypress' ), 239 'slug' => 'sentbox', 240 'parent_slug' => $slug, 241 'screen_function' => 'messages_screen_sentbox', 242 'position' => 20, 243 'user_has_access' => false, 244 'user_has_access_callback' => 'bp_core_can_edit_settings', 245 ); 246 247 // Show "Compose" on the logged-in user's profile only. 248 $sub_nav[] = array( 249 'name' => __( 'Compose', 'buddypress' ), 250 'slug' => 'compose', 251 'parent_slug' => $slug, 252 'screen_function' => 'messages_screen_compose', 253 'position' => 30, 254 'user_has_access' => false, 255 'user_has_access_callback' => 'bp_is_my_profile', 256 ); 257 258 // Show "Notices" to community admins only. 259 $sub_nav[] = array( 260 'name' => __( 'Notices', 'buddypress' ), 261 'slug' => 'notices', 262 'parent_slug' => $slug, 263 'screen_function' => 'messages_screen_notices', 264 'position' => 90, 265 'user_has_access' => false, 266 'user_has_access_callback' => 'bp_current_user_can_moderate', 267 ); 268 269 parent::register_nav( $main_nav, $sub_nav ); 270 } 271 272 /** 273 * Set up component navigation. 274 * 275 * @since 1.5.0 276 * @since 12.0.0 Used to customize the main navigation name. 277 * 278 * @see `BP_Component::setup_nav()` for a description of arguments. 279 * 280 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 281 * description. 282 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 283 * description. 196 284 */ 197 285 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 198 199 // Stop if there is no user displayed or logged in.200 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {201 return;202 }203 204 $access = bp_core_can_edit_settings();205 $slug = bp_get_messages_slug();206 207 286 // Only grab count if we're on a user page and current user has access. 208 if ( bp_is_user() && bp_user_has_access() ) {209 $count = bp_get_total_unread_messages_count( bp_displayed_user_id() );210 $class = ( 0 === $count ) ? 'no-count' : 'count';211 $ nav_name= sprintf(287 if ( isset( $this->main_nav['name'] ) && bp_is_user() && bp_user_has_access() ) { 288 $count = bp_get_total_unread_messages_count( bp_displayed_user_id() ); 289 $class = ( 0 === $count ) ? 'no-count' : 'count'; 290 $this->main_nav['name'] = sprintf( 212 291 /* translators: %s: Unread message count for the current user */ 213 292 __( 'Messages %s', 'buddypress' ), … … 218 297 ) 219 298 ); 220 } else { 221 $nav_name = __( 'Messages', 'buddypress' ); 222 } 223 224 // Add 'Messages' to the main navigation. 225 $main_nav = array( 226 'name' => $nav_name, 227 'slug' => $slug, 228 'position' => 50, 229 'show_for_displayed_user' => $access, 230 'screen_function' => 'messages_screen_inbox', 231 'default_subnav_slug' => 'inbox', 232 'item_css_id' => $this->id 233 ); 234 235 // Add the subnav items to the profile. 236 $sub_nav[] = array( 237 'name' => __( 'Inbox', 'buddypress' ), 238 'slug' => 'inbox', 239 'parent_slug' => $slug, 240 'screen_function' => 'messages_screen_inbox', 241 'position' => 10, 242 'user_has_access' => $access 243 ); 244 245 if ( bp_is_active( $this->id, 'star' ) ) { 246 $sub_nav[] = array( 247 'name' => __( 'Starred', 'buddypress' ), 248 'slug' => bp_get_messages_starred_slug(), 249 'parent_slug' => $slug, 250 'screen_function' => 'bp_messages_star_screen', 251 'position' => 11, 252 'user_has_access' => $access 253 ); 254 } 255 256 $sub_nav[] = array( 257 'name' => __( 'Sent', 'buddypress' ), 258 'slug' => 'sentbox', 259 'parent_slug' => $slug, 260 'screen_function' => 'messages_screen_sentbox', 261 'position' => 20, 262 'user_has_access' => $access 263 ); 264 265 // Show "Compose" on the logged-in user's profile only. 266 $sub_nav[] = array( 267 'name' => __( 'Compose', 'buddypress' ), 268 'slug' => 'compose', 269 'parent_slug' => $slug, 270 'screen_function' => 'messages_screen_compose', 271 'position' => 30, 272 'user_has_access' => bp_is_my_profile(), 273 ); 274 275 // Show "Notices" to community admins only. 276 $sub_nav[] = array( 277 'name' => __( 'Notices', 'buddypress' ), 278 'slug' => 'notices', 279 'parent_slug' => $slug, 280 'screen_function' => 'messages_screen_notices', 281 'position' => 90, 282 'user_has_access' => bp_current_user_can( 'bp_moderate' ) 283 ); 299 } 284 300 285 301 parent::setup_nav( $main_nav, $sub_nav ); -
trunk/src/bp-notifications/classes/class-bp-notifications-component.php
r13442 r13450 134 134 135 135 /** 136 * Register component navigation. 137 * 138 * @since 12.0.0 139 * 140 * @see `BP_Component::register_nav()` for a description of arguments. 141 * 142 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 143 * description. 144 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 145 * description. 146 */ 147 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 148 $slug = bp_get_notifications_slug(); 149 150 // Add 'Notifications' to the main navigation. 151 $main_nav = array( 152 'name' => _x( 'Notifications', 'Profile screen nav', 'buddypress' ), 153 'slug' => $slug, 154 'position' => 30, 155 'show_for_displayed_user' => false, 156 'screen_function' => 'bp_notifications_screen_unread', 157 'default_subnav_slug' => 'unread', 158 'item_css_id' => $this->id, 159 'user_has_access_callback' => 'bp_core_can_edit_settings', 160 ); 161 162 // Add the subnav items to the notifications nav item. 163 $sub_nav[] = array( 164 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), 165 'slug' => 'unread', 166 'parent_slug' => $slug, 167 'screen_function' => 'bp_notifications_screen_unread', 168 'position' => 10, 169 'item_css_id' => 'notifications-my-notifications', 170 'user_has_access' => false, 171 'user_has_access_callback' => 'bp_core_can_edit_settings', 172 ); 173 174 $sub_nav[] = array( 175 'name' => _x( 'Read', 'Notification screen nav', 'buddypress' ), 176 'slug' => 'read', 177 'parent_slug' => $slug, 178 'screen_function' => 'bp_notifications_screen_read', 179 'position' => 20, 180 'user_has_access' => false, 181 'user_has_access_callback' => 'bp_core_can_edit_settings', 182 ); 183 184 parent::register_nav( $main_nav, $sub_nav ); 185 } 186 187 /** 136 188 * Set up component navigation. 137 189 * 138 190 * @since 1.9.0 139 * 140 * @see BP_Component::setup_nav() for a description of arguments. 141 * 142 * @param array $main_nav Optional. See BP_Component::setup_nav() for 191 * @since 12.0.0 Used to customize the main navigation name. 192 * 193 * @see `BP_Component::setup_nav()` for a description of arguments. 194 * 195 * @param array $main_nav Optional. See `BP_Component::setup_nav()` for 143 196 * description. 144 * @param array $sub_nav Optional. See BP_Component::setup_nav()for197 * @param array $sub_nav Optional. See `BP_Component::setup_nav()` for 145 198 * description. 146 199 */ 147 200 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 148 149 // Stop if there is no user displayed or logged in.150 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {151 return;152 }153 154 $access = bp_core_can_edit_settings();155 $slug = bp_get_notifications_slug();156 157 201 // Only grab count if we're on a user page and current user has access. 158 if ( bp_is_user() && bp_user_has_access() ) {159 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );160 $class = ( 0 === $count ) ? 'no-count' : 'count';161 $ nav_name= sprintf(202 if ( isset( $this->main_nav['name'] ) && bp_is_user() && bp_user_has_access() ) { 203 $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() ); 204 $class = ( 0 === $count ) ? 'no-count' : 'count'; 205 $this->main_nav['name'] = sprintf( 162 206 /* translators: %s: Unread notification count for the current user */ 163 207 _x( 'Notifications %s', 'Profile screen nav', 'buddypress' ), … … 168 212 ) 169 213 ); 170 } else { 171 $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' ); 172 } 173 174 // Add 'Notifications' to the main navigation. 175 $main_nav = array( 176 'name' => $nav_name, 177 'slug' => $slug, 178 'position' => 30, 179 'show_for_displayed_user' => $access, 180 'screen_function' => 'bp_notifications_screen_unread', 181 'default_subnav_slug' => 'unread', 182 'item_css_id' => $this->id, 183 ); 184 185 // Add the subnav items to the notifications nav item. 186 $sub_nav[] = array( 187 'name' => _x( 'Unread', 'Notification screen nav', 'buddypress' ), 188 'slug' => 'unread', 189 'parent_slug' => $slug, 190 'screen_function' => 'bp_notifications_screen_unread', 191 'position' => 10, 192 'item_css_id' => 'notifications-my-notifications', 193 'user_has_access' => $access, 194 ); 195 196 $sub_nav[] = array( 197 'name' => _x( 'Read', 'Notification screen nav', 'buddypress' ), 198 'slug' => 'read', 199 'parent_slug' => $slug, 200 'screen_function' => 'bp_notifications_screen_read', 201 'position' => 20, 202 'user_has_access' => $access, 203 ); 214 } 204 215 205 216 parent::setup_nav( $main_nav, $sub_nav ); -
trunk/src/bp-settings/bp-settings-functions.php
r13140 r13450 362 362 <?php 363 363 } 364 365 /** 366 * Whether a user can delete self account from front-end. 367 * 368 * @since 12.0.0 369 * 370 * @return boolean True if user can delete self account from front-end. False otherwise. 371 */ 372 function bp_settings_can_delete_self_account() { 373 return ! user_can( bp_displayed_user_id(), 'delete_users' ); 374 } 375 376 /** 377 * Whether to show the Delete account front-end nav. 378 * 379 * @since 12.0.0 380 * 381 * @return boolean True if user can be shown the Delete account nav. False otherwise. 382 */ 383 function bp_settings_show_delete_account_nav() { 384 return ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ); 385 } 386 387 /** 388 * Whether to show the Capability front-end nav. 389 * 390 * @since 12.0.0 391 * 392 * @return boolean True if user can be shown the Capability nav. False otherwise. 393 */ 394 function bp_settings_show_capability_nav() { 395 return ! bp_is_my_profile(); 396 } -
trunk/src/bp-settings/classes/class-bp-settings-component.php
r13442 r13450 120 120 121 121 /** 122 * Set upnavigation.123 * 124 * @since 1 .5.0125 * 126 * @see BP_Component::setup_nav()for a description of arguments.127 * 128 * @param array $main_nav Optional. See BP_Component::setup_nav()for122 * Register component navigation. 123 * 124 * @since 12.0.0 125 * 126 * @see `BP_Component::register_nav()` for a description of arguments. 127 * 128 * @param array $main_nav Optional. See `BP_Component::register_nav()` for 129 129 * description. 130 * @param array $sub_nav Optional. See BP_Component::setup_nav()for130 * @param array $sub_nav Optional. See `BP_Component::register_nav()` for 131 131 * description. 132 132 */ 133 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 134 135 // Stop if there is no user displayed or logged in. 136 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 137 return; 138 } 139 140 $access = bp_core_can_edit_settings(); 133 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 141 134 $slug = bp_get_settings_slug(); 142 135 143 136 // Add the settings navigation item. 144 137 $main_nav = array( 145 'name' => __( 'Settings', 'buddypress' ),146 'slug' => $slug,147 'position' => 100,148 's how_for_displayed_user' => $access,149 ' screen_function' => 'bp_settings_screen_general',150 ' default_subnav_slug' => 'general',138 'name' => __( 'Settings', 'buddypress' ), 139 'slug' => $slug, 140 'position' => 100, 141 'screen_function' => 'bp_settings_screen_general', 142 'default_subnav_slug' => 'general', 143 'user_has_access_callback' => 'bp_core_can_edit_settings', 151 144 ); 152 145 153 146 // Add General Settings nav item. 154 147 $sub_nav[] = array( 155 'name' => __( 'General', 'buddypress' ), 156 'slug' => 'general', 157 'parent_slug' => $slug, 158 'screen_function' => 'bp_settings_screen_general', 159 'position' => 10, 160 'user_has_access' => $access, 148 'name' => __( 'General', 'buddypress' ), 149 'slug' => 'general', 150 'parent_slug' => $slug, 151 'screen_function' => 'bp_settings_screen_general', 152 'position' => 10, 153 'user_has_access' => false, 154 'user_has_access_callback' => 'bp_core_can_edit_settings', 161 155 ); 162 156 … … 164 158 // retain the old slug and function names for backward compat. 165 159 $sub_nav[] = array( 166 'name' => __( 'Email', 'buddypress' ), 167 'slug' => 'notifications', 168 'parent_slug' => $slug, 169 'screen_function' => 'bp_settings_screen_notification', 170 'position' => 20, 171 'user_has_access' => $access, 172 ); 173 174 // Add Spam Account nav item. 175 if ( bp_current_user_can( 'bp_moderate' ) ) { 176 $sub_nav[] = array( 177 'name' => __( 'Capabilities', 'buddypress' ), 178 'slug' => 'capabilities', 179 'parent_slug' => $slug, 180 'screen_function' => 'bp_settings_screen_capabilities', 181 'position' => 80, 182 'user_has_access' => ! bp_is_my_profile(), 183 ); 184 } 160 'name' => __( 'Email', 'buddypress' ), 161 'slug' => 'notifications', 162 'parent_slug' => $slug, 163 'screen_function' => 'bp_settings_screen_notification', 164 'position' => 20, 165 'user_has_access' => false, 166 'user_has_access_callback' => 'bp_core_can_edit_settings', 167 ); 168 169 $sub_nav[] = array( 170 'name' => _x( 'Profile Visibility', 'Profile settings sub nav', 'buddypress' ), 171 'slug' => 'profile', 172 'parent_slug' => $slug, 173 'screen_function' => 'bp_xprofile_screen_settings', 174 'position' => 30, 175 'user_has_access' => false, 176 'user_has_access_callback' => 'bp_core_can_edit_settings', 177 ); 178 179 $sub_nav[] = array( 180 'name' => __( 'Capabilities', 'buddypress' ), 181 'slug' => 'capabilities', 182 'parent_slug' => $slug, 183 'screen_function' => 'bp_settings_screen_capabilities', 184 'position' => 80, 185 'user_has_access' => false, 186 'user_has_access_callback' => 'bp_settings_show_capability_nav', 187 'generate' => bp_current_user_can( 'bp_moderate' ), 188 ); 185 189 186 190 /** … … 196 200 if ( true === $show_data_page ) { 197 201 $sub_nav[] = array( 198 'name' => __( 'Export Data', 'buddypress' ), 199 'slug' => 'data', 200 'parent_slug' => $slug, 201 'screen_function' => 'bp_settings_screen_data', 202 'position' => 89, 203 'user_has_access' => $access, 202 'name' => __( 'Export Data', 'buddypress' ), 203 'slug' => 'data', 204 'parent_slug' => $slug, 205 'screen_function' => 'bp_settings_screen_data', 206 'position' => 89, 207 'user_has_access' => false, 208 'user_has_access_callback' => 'bp_core_can_edit_settings', 204 209 ); 205 210 } 206 211 207 212 // Add Delete Account nav item. 208 if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) {209 $sub_nav[] = array(210 'name' => __( 'Delete Account', 'buddypress' ),211 'slug' => 'delete-account',212 'parent_slug' => $slug,213 'screen_function' => 'bp_settings_screen_delete_account',214 'position' => 90,215 'user_has_access' => ! user_can( bp_displayed_user_id(), 'delete_users' ),216 );217 }218 219 parent:: setup_nav( $main_nav, $sub_nav );213 $sub_nav[] = array( 214 'name' => __( 'Delete Account', 'buddypress' ), 215 'slug' => 'delete-account', 216 'parent_slug' => $slug, 217 'screen_function' => 'bp_settings_screen_delete_account', 218 'position' => 90, 219 'user_has_access' => false, 220 'user_has_access_callback' => 'bp_settings_can_delete_self_account', 221 'generate' => 'bp_settings_show_delete_account_nav', 222 ); 223 224 parent::register_nav( $main_nav, $sub_nav ); 220 225 } 221 226 … … 225 230 * @since 1.5.0 226 231 * 227 * @see BP_Component::setup_nav()for a description of the $wp_admin_nav232 * @see `BP_Component::setup_admin_bar()` for a description of the $wp_admin_nav 228 233 * parameter array. 229 234 * 230 * @param array $wp_admin_nav See BP_Component::setup_admin_bar()for a235 * @param array $wp_admin_nav See `BP_Component::setup_admin_bar()` for a 231 236 * description. 232 237 */ -
trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php
r13442 r13450 221 221 222 222 /** 223 * Set up navigation. 224 * 225 * @since 1.5.0 226 * 227 * @param array $main_nav Array of main nav items to set up. 228 * @param array $sub_nav Array of sub nav items to set up. 229 */ 230 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 231 232 // Stop if there is no user displayed or logged in. 233 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 234 return; 235 } 236 237 $access = bp_core_can_edit_settings(); 238 $slug = bp_get_profile_slug(); 223 * Register component navigation. 224 * 225 * @since 12.0.0 226 * 227 * @param array $main_nav See `BP_Component::register_nav()` for details. 228 * @param array $sub_nav See `BP_Component::register_nav()` for details. 229 */ 230 public function register_nav( $main_nav = array(), $sub_nav = array() ) { 231 $slug = bp_get_profile_slug(); 239 232 240 233 // Add 'Profile' to the main navigation. … … 259 252 // Edit Profile. 260 253 $sub_nav[] = array( 261 'name' => _x( 'Edit','Profile header sub menu', 'buddypress' ), 262 'slug' => 'edit', 263 'parent_slug' => $slug, 264 'screen_function' => 'xprofile_screen_edit_profile', 265 'position' => 20, 266 'user_has_access' => $access, 267 ); 268 269 // The Settings > Profile nav item can only be set up after 270 // the Settings component has run its own nav routine. 271 add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) ); 272 273 parent::setup_nav( $main_nav, $sub_nav ); 254 'name' => _x( 'Edit','Profile header sub menu', 'buddypress' ), 255 'slug' => 'edit', 256 'parent_slug' => $slug, 257 'screen_function' => 'xprofile_screen_edit_profile', 258 'position' => 20, 259 'user_has_access' => false, 260 'user_has_access_callback' => 'bp_core_can_edit_settings', 261 ); 262 263 parent::register_nav( $main_nav, $sub_nav ); 274 264 } 275 265 … … 281 271 * 282 272 * @since 2.1.0 273 * @deprecated 12.0.0 283 274 */ 284 275 public function setup_settings_nav() { 285 if ( ! bp_is_active( 'settings' ) ) { 286 return; 287 } 288 289 // Stop if there is no user displayed or logged in. 290 if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) { 291 return; 292 } 293 294 // Get the settings slug. 295 $settings_slug = bp_get_settings_slug(); 296 297 bp_core_new_subnav_item( array( 298 'name' => _x( 'Profile Visibility', 'Profile settings sub nav', 'buddypress' ), 299 'slug' => 'profile', 300 'parent_slug' => $settings_slug, 301 'screen_function' => 'bp_xprofile_screen_settings', 302 'position' => 30, 303 'user_has_access' => bp_core_can_edit_settings(), 304 ), 'members' ); 276 _deprecated_function( __METHOD__, '12.0.0' ); 305 277 } 306 278
Note: See TracChangeset
for help on using the changeset viewer.