Ticket #3419: 3419.03.patch
| File 3419.03.patch, 42.5 KB (added by , 10 years ago) |
|---|
-
src/bp-activity/classes/class-bp-activity-component.php
172 172 'position' => 10, 173 173 'screen_function' => 'bp_activity_screen_my_activity', 174 174 'default_subnav_slug' => 'just-me', 175 'item_css_id' => $this->id 175 'item_css_id' => $this->id, 176 176 ); 177 177 178 178 // Add the subnav items to the activity nav item if we are using a theme that supports this. … … 182 182 'parent_url' => $activity_link, 183 183 'parent_slug' => $slug, 184 184 'screen_function' => 'bp_activity_screen_my_activity', 185 'position' => 10 185 'position' => 10, 186 186 ); 187 187 188 188 // Check @mentions. … … 194 194 'parent_slug' => $slug, 195 195 'screen_function' => 'bp_activity_screen_mentions', 196 196 'position' => 20, 197 'item_css_id' => 'activity-mentions' 197 'item_css_id' => 'activity-mentions', 198 198 ); 199 199 } 200 200 … … 207 207 'parent_slug' => $slug, 208 208 'screen_function' => 'bp_activity_screen_favorites', 209 209 'position' => 30, 210 'item_css_id' => 'activity-favs' 210 'item_css_id' => 'activity-favs', 211 211 ); 212 212 } 213 213 … … 220 220 'parent_slug' => $slug, 221 221 'screen_function' => 'bp_activity_screen_friends', 222 222 'position' => 40, 223 'item_css_id' => 'activity-friends' 223 'item_css_id' => 'activity-friends', 224 224 ) ; 225 225 } 226 226 … … 233 233 'parent_slug' => $slug, 234 234 'screen_function' => 'bp_activity_screen_groups', 235 235 'position' => 50, 236 'item_css_id' => 'activity-groups' 236 'item_css_id' => 'activity-groups', 237 237 ); 238 238 } 239 239 … … 244 244 * Set up the component entries in the WordPress Admin Bar. 245 245 * 246 246 * @since 1.5.0 247 * @since 2.7.0 Sync the WP Admin Nav with BP Nav items having the `show_in_admin_bar` property set to true. 247 248 * 248 249 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 249 250 * parameter array. … … 252 253 * description. 253 254 */ 254 255 public function setup_admin_bar( $wp_admin_nav = array() ) { 256 if ( ! is_user_logged_in() ) { 257 return; 258 } 255 259 256 // Menus for logged in user. 257 if ( is_user_logged_in() ) { 258 259 // Setup the logged in user variables. 260 $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() ); 261 262 // Unread message count. 263 if ( bp_activity_do_mentions() ) { 264 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); 265 if ( !empty( $count ) ) { 266 $title = sprintf( 267 /* translators: %s: Unread mention count for the current user */ 268 _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ), 269 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 270 ); 271 } else { 272 $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' ); 273 } 274 } 275 276 // Add the "Activity" sub menu. 277 $wp_admin_nav[] = array( 278 'parent' => buddypress()->my_account_menu_id, 279 'id' => 'my-account-' . $this->id, 280 'title' => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ), 281 'href' => $activity_link 282 ); 283 284 // Personal. 285 $wp_admin_nav[] = array( 286 'parent' => 'my-account-' . $this->id, 287 'id' => 'my-account-' . $this->id . '-personal', 288 'title' => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ), 289 'href' => $activity_link, 290 'position' => 10 291 ); 292 293 // Mentions. 294 if ( bp_activity_do_mentions() ) { 295 $wp_admin_nav[] = array( 296 'parent' => 'my-account-' . $this->id, 297 'id' => 'my-account-' . $this->id . '-mentions', 298 'title' => $title, 299 'href' => trailingslashit( $activity_link . 'mentions' ), 300 'position' => 20 301 ); 302 } 303 304 // Favorite activity items. 305 if ( bp_activity_can_favorite() ) { 306 $wp_admin_nav[] = array( 307 'parent' => 'my-account-' . $this->id, 308 'id' => 'my-account-' . $this->id . '-favorites', 309 'title' => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ), 310 'href' => trailingslashit( $activity_link . 'favorites' ), 311 'position' => 30 312 ); 313 } 314 315 // Friends? 316 if ( bp_is_active( 'friends' ) ) { 317 $wp_admin_nav[] = array( 318 'parent' => 'my-account-' . $this->id, 319 'id' => 'my-account-' . $this->id . '-friends', 320 'title' => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ), 321 'href' => trailingslashit( $activity_link . bp_get_friends_slug() ), 322 'position' => 40 323 ); 324 } 260 // Get nav with 'show_in_admin_bar' support. 261 $nav = buddypress()->members->nav->get_admin_nav( array( 262 'parent_slug' => bp_get_activity_slug(), 263 ) ); 325 264 326 // Groups? 327 if ( bp_is_active( 'groups' ) ) { 328 $wp_admin_nav[] = array( 329 'parent' => 'my-account-' . $this->id, 330 'id' => 'my-account-' . $this->id . '-groups', 331 'title' => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ), 332 'href' => trailingslashit( $activity_link . bp_get_groups_slug() ), 333 'position' => 50 334 ); 265 // Override some nav items for the admin bar. 266 if ( ! empty( $nav['children'] ) ) { 267 foreach ( $nav['children'] as $key => $sub_nav ) { 268 // Override title for "Mentions" nav to add count. 269 if ( 'mentions' === $sub_nav->slug && bp_activity_do_mentions() ) { 270 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ); 271 if ( ! empty( $count ) ) { 272 $nav['children'][$key]->name = sprintf( 273 /* translators: %s: Unread mention count for the current user */ 274 _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ), 275 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 276 ); 277 } 278 } 335 279 } 336 280 } 337 281 338 parent::setup_admin_bar( $wp_admin_nav ); 282 // Configure nav array for setup_admin_bar() method. 283 $nav = $this->setup_admin_nav( $nav, array( 284 'default_subnav_id' => 'personal' 285 ) ); 286 287 // Setup the admin bar. 288 parent::setup_admin_bar( $nav ); 339 289 } 340 290 341 291 /** -
src/bp-core/bp-core-buddybar.php
32 32 * @type callable $screen_function The callback function that will run when the nav item is clicked. 33 33 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 34 34 * item is clicked. 35 * @type bool $show_in_admin_bar Optional. Whether to add this nav item to the WP Admin Bar. 36 * Default: true. 35 37 * } 36 38 * @param string $component The component the navigation is attached to. Defaults to 'members'. 37 39 * @return bool|null Returns false on failure. … … 49 51 'site_admin_only' => false, // Can only site admins see this nav item? 50 52 'position' => 99, // Index of where this nav item should be positioned. 51 53 'screen_function' => false, // The name of the function to run when clicked. 52 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 54 'default_subnav_slug' => false, // The slug of the default subnav item to select when clicked. 55 'show_in_admin_bar' => true, // Whether to add this nav item to the WP Admin Bar. 53 56 ); 54 57 55 58 $r = wp_parse_args( $args, $defaults ); … … 106 109 * @type callable $screen_function The callback function that will run when the nav item is clicked. 107 110 * @type bool|string $default_subnav_slug Optional. The slug of the default subnav item to select when the nav 108 111 * item is clicked. 112 * @type bool $show_in_admin_bar Optional. Whether to add this nav item to the WP Admin Bar. 113 * Default: true. 109 114 * } 110 115 * @param string $component Optional. Component that the nav belongs to. 111 116 * @return bool|BP_Nav_Item Returns false on failure, new nav item on success. … … 121 126 'site_admin_only' => false, // Can only site admins see this nav item? 122 127 'position' => 99, // Index of where this nav item should be positioned. 123 128 'screen_function' => false, // The name of the function to run when clicked. 124 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. 129 'default_subnav_slug' => false, // The slug of the default subnav item to select when clicked. 130 'show_in_admin_bar' => true, // Whether to add this nav item to the WP Admin Bar. 125 131 ); 126 132 127 133 $r = wp_parse_args( $args, $defaults ); … … 148 154 'show_for_displayed_user' => $r['show_for_displayed_user'], 149 155 'position' => $r['position'], 150 156 'screen_function' => &$r['screen_function'], 151 'default_subnav_slug' => $r['default_subnav_slug'] 157 'default_subnav_slug' => $r['default_subnav_slug'], 158 'show_in_admin_bar' => $r['show_in_admin_bar'], 152 159 ); 153 160 154 161 // Add the item to the nav. … … 392 399 * @type string $link Optional. The URL that the subnav item should point to. Defaults to a value 393 400 * generated from the `$parent_url` + `$slug`. 394 401 * @type bool $show_in_admin_bar Optional. Whether the nav item should be added into the group's "Edit" 395 * Admin Bar menu for group admins. Default: false.402 * Admin Bar menu for group admins. Default: true. 396 403 * } 397 404 * @param string $component The component the navigation is attached to. Defaults to 'members'. 398 405 * @return bool|null Returns false on failure. … … 472 479 * to. Defaults to a value generated from the $parent_url + $slug. 473 480 * @type bool $show_in_admin_bar Optional. Whether the nav item should be added into 474 481 * the group's "Edit" Admin Bar menu for group admins. 475 * Default: false.482 * Default: true. 476 483 * } 477 484 * @param string $component The component the navigation is attached to. Defaults to 'members'. 478 485 * @return bool|object Returns false on failure, new BP_Nav_Item instance on success. … … 492 499 'position' => 90, // Index of where this nav item should be positioned. 493 500 'screen_function' => false, // The name of the function to run when clicked. 494 501 'link' => '', // The link for the subnav item; optional, not usually required. 495 'show_in_admin_bar' => false,// Show the Manage link in the current group's "Edit" Admin Bar menu.502 'show_in_admin_bar' => true, // Show the Manage link in the current group's "Edit" Admin Bar menu. 496 503 ) ); 497 504 498 505 // If we don't have the required info we need, don't create this subnav item. … … 568 575 * Defaults to a value generated from the $parent_url + $slug. 569 576 * @type bool $show_in_admin_bar Optional. Whether the nav item should be added into 570 577 * the group's "Edit" Admin Bar menu for group admins. 571 * Default: false.578 * Default: true. 572 579 * } 573 580 * @param string $component The component the navigation is attached to. Defaults to 'members'. 574 581 * @return bool|null Returns false on failure. -
src/bp-core/classes/class-bp-component.php
505 505 } 506 506 507 507 /** 508 * Helper method to configure nav array for setup_admin_bar() method. 509 * 510 * @since 2.7.0 511 * 512 * @param array $nav Nav from BP_Core_Nav::get_admin_nav(). 513 * @param array $args { 514 * Arguments for configuring the nav array. 515 * @type string $parent_title Title for the parent nav. 516 * @type string $default_subnav_id Subnav ID for the default subnav. 517 * } 518 * @return array 519 */ 520 public function setup_admin_nav( $nav = array(), $args = array() ) { 521 if ( ! isset( buddypress()->members->nav ) ) { 522 return array(); 523 } 524 525 $wp_admin_nav = array(); 526 527 if ( ! empty( $nav['parent'] ) ) { 528 // Add the parent menu. 529 $wp_admin_nav[] = array( 530 'parent' => buddypress()->my_account_menu_id, 531 'id' => 'my-account-' . $this->id, 532 'title' => isset( $args['parent_title'] ) ? $args['parent_title'] : $nav['parent']->name, 533 'href' => $nav['parent']->link 534 ); 535 } 536 537 if ( ! empty( $nav['children'] ) ) { 538 foreach ( $nav['children'] as $key => $sub_nav ) { 539 if ( isset( $nav['parent']->default_subnav_slug ) && $sub_nav->slug !== $nav['parent']->default_subnav_slug ) { 540 $sub_nav_id = sprintf( 'my-account-%s-%s', $this->id, $sub_nav->slug ); 541 } elseif ( isset( $nav['parent']->default_subnav_slug ) && $sub_nav->slug === $nav['parent']->default_subnav_slug ) { 542 $sub_nav_id = sprintf( 'my-account-%s-%s', $this->id, isset( $args['default_subnav_id'] ) ? $args['default_subnav_id'] : $sub_nav->slug ); 543 } 544 545 // Add the sub nav items. 546 $wp_admin_nav[] = array( 547 'parent' => 'my-account-' . $this->id, 548 'id' => $sub_nav_id, 549 'title' => $sub_nav->name, 550 'href' => $sub_nav->link, 551 'position' => $sub_nav->position, 552 ); 553 } 554 } 555 556 return $wp_admin_nav; 557 } 558 559 /** 508 560 * Set up the component entries in the WordPress Admin Bar. 509 561 * 510 562 * @since 1.5.0 -
src/bp-core/classes/class-bp-core-nav.php
399 399 400 400 return $primary_nav_items; 401 401 } 402 403 /** 404 * Get the Nav Items to display in the WP Admin Bar 405 * 406 * @since 2.7.0 407 * 408 * @param array $args Filters to select the specific items. See wp_list_filter(). 409 * @return array An associative array containing the parent nav and its children. 410 */ 411 public function get_admin_nav( $args = array() ) { 412 $admin_nav = array(); 413 414 $params = wp_parse_args( $args, array( 'show_in_admin_bar' => true ) ); 415 416 // We need the parent slug, and this is a WP Admin Nav! 417 if ( empty( $params['parent_slug'] ) || empty( $params['show_in_admin_bar'] ) ) { 418 return $admin_nav; 419 } 420 421 // Validate the primary nav item 422 $primary_nav_item = $this->get( $params['parent_slug'] ); 423 424 if ( ! $primary_nav_item || empty( $primary_nav_item->show_in_admin_bar ) ) { 425 return $admin_nav; 426 } 427 428 $admin_nav['parent'] = $primary_nav_item; 429 $secondary_nav_items = $this->get_secondary( $params ); 430 431 if ( ! $secondary_nav_items ) { 432 return $admin_nav; 433 } 434 435 return array_merge( $admin_nav, array( 'children' => $secondary_nav_items ) ); 436 } 402 437 } -
src/bp-friends/classes/class-bp-friends-component.php
198 198 * for description. 199 199 */ 200 200 public function setup_admin_bar( $wp_admin_nav = array() ) { 201 if ( ! is_user_logged_in() ) { 202 return; 203 } 201 204 202 // Menus for logged in user. 203 if ( is_user_logged_in() ) { 204 205 // Setup the logged in user variables. 206 $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() ); 207 208 // Pending friend requests. 209 $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) ); 210 if ( !empty( $count ) ) { 211 $title = sprintf( 212 /* translators: %s: Pending friend request count for the current user */ 213 _x( 'Friends %s', 'My Account Friends menu', 'buddypress' ), 214 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 215 ); 216 $pending = sprintf( 217 /* translators: %s: Pending friend request count for the current user */ 218 _x( 'Pending Requests %s', 'My Account Friends menu sub nav', 'buddypress' ), 219 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 220 ); 221 } else { 222 $title = _x( 'Friends', 'My Account Friends menu', 'buddypress' ); 223 $pending = _x( 'No Pending Requests','My Account Friends menu sub nav', 'buddypress' ); 224 } 205 // Get nav with 'show_in_admin_bar' support. 206 $nav = buddypress()->members->nav->get_admin_nav( array( 207 'parent_slug' => bp_get_friends_slug(), 208 ) ); 225 209 226 // Add the "My Account" sub menus. 227 $wp_admin_nav[] = array( 228 'parent' => buddypress()->my_account_menu_id, 229 'id' => 'my-account-' . $this->id, 230 'title' => $title, 231 'href' => $friends_link 210 // Pending friend requests. 211 $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) ); 212 if ( !empty( $count ) ) { 213 $title = sprintf( 214 /* translators: %s: Pending friend request count for the current user */ 215 _x( 'Friends %s', 'My Account Friends menu', 'buddypress' ), 216 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 232 217 ); 233 234 // My Friends. 235 $wp_admin_nav[] = array( 236 'parent' => 'my-account-' . $this->id, 237 'id' => 'my-account-' . $this->id . '-friendships', 238 'title' => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ), 239 'href' => $friends_link, 240 'position' => 10 218 $pending = sprintf( 219 /* translators: %s: Pending friend request count for the current user */ 220 _x( 'Pending Requests %s', 'My Account Friends menu sub nav', 'buddypress' ), 221 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 241 222 ); 223 } else { 224 $title = _x( 'Friends', 'My Account Friends menu', 'buddypress' ); 225 $pending = _x( 'No Pending Requests','My Account Friends menu sub nav', 'buddypress' ); 226 } 242 227 243 // Requests.244 $wp_admin_nav[] = array(245 'parent' => 'my-account-' . $this->id,246 'id' => 'my-account-' . $this->id . '-requests',247 'title' => $pending,248 'href' => trailingslashit( $friends_link . 'requests' ),249 'position' => 20250 );228 // Override some nav items for the admin bar. 229 if ( ! empty( $nav['children'] ) ) { 230 foreach ( $nav['children'] as $key => $sub_nav ) { 231 // Override title for "Requests" nav to add count. 232 if ( 'requests' === $sub_nav->slug ) { 233 $nav['children'][$key]->name = $pending; 234 } 235 } 251 236 } 252 237 253 parent::setup_admin_bar( $wp_admin_nav ); 238 // Configure nav array for setup_admin_bar() method. 239 $nav = $this->setup_admin_nav( $nav, array( 240 'parent_title' => $title 241 ) ); 242 243 // Setup the admin bar. 244 parent::setup_admin_bar( $nav ); 254 245 } 255 246 256 247 /** -
src/bp-groups/classes/class-bp-groups-component.php
724 724 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description. 725 725 */ 726 726 public function setup_admin_bar( $wp_admin_nav = array() ) { 727 if ( ! is_user_logged_in() ) { 728 return; 729 } 727 730 728 // Menus for logged in user. 729 if ( is_user_logged_in() ) { 731 // Get nav with 'show_in_admin_bar' support. 732 $nav = buddypress()->members->nav->get_admin_nav( array( 733 'parent_slug' => bp_get_groups_slug(), 734 ) ); 730 735 731 // Setup the logged in user variables. 732 $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 736 // Pending group invites. 737 $count = groups_get_invite_count_for_user(); 738 $title = _x( 'Groups', 'My Account Groups', 'buddypress' ); 739 $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' ); 733 740 734 // Pending group invites. 735 $count = groups_get_invite_count_for_user(); 736 $title = _x( 'Groups', 'My Account Groups', 'buddypress' ); 737 $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' ); 741 if ( ! empty( $count['total'] ) ) { 742 $title = sprintf( 743 /* translators: %s: Group invitation count for the current user */ 744 _x( 'Groups %s', 'My Account Groups nav', 'buddypress' ), 745 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 746 ); 738 747 739 if ( ! empty( $count['total'] ) ) {740 $title = sprintf(741 /* translators: %s: Group invitation count for the current user */742 _x( 'Groups %s', 'My Account Groups nav', 'buddypress' ),743 '<span class="count">' . bp_core_number_format( $count ) . '</span>'744 );748 $pending = sprintf( 749 /* translators: %s: Group invitation count for the current user */ 750 _x( 'Pending Invites %s', 'My Account Groups sub nav', 'buddypress' ), 751 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 752 ); 753 } 745 754 746 $pending = sprintf( 747 /* translators: %s: Group invitation count for the current user */ 748 _x( 'Pending Invites %s', 'My Account Groups sub nav', 'buddypress' ), 749 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 750 ); 755 // Override some nav items for the admin bar. 756 if ( ! empty( $nav['children'] ) ) { 757 foreach ( $nav['children'] as $key => $sub_nav ) { 758 // Override title for "Invites". 759 if ( 'invites' === $sub_nav->slug ) { 760 $nav['children'][$key]->name = $pending; 761 } 751 762 } 763 } 752 764 753 // Add the "My Account" sub menus. 754 $wp_admin_nav[] = array( 755 'parent' => buddypress()->my_account_menu_id, 756 'id' => 'my-account-' . $this->id, 757 'title' => $title, 758 'href' => $groups_link 759 ); 760 761 // My Groups. 762 $wp_admin_nav[] = array( 763 'parent' => 'my-account-' . $this->id, 764 'id' => 'my-account-' . $this->id . '-memberships', 765 'title' => _x( 'Memberships', 'My Account Groups sub nav', 'buddypress' ), 766 'href' => $groups_link, 767 'position' => 10 768 ); 765 // Configure nav array for setup_admin_bar() method. 766 $nav = $this->setup_admin_nav( $nav, array( 767 'parent_title' => $title 768 ) ); 769 769 770 // Invitations. 771 $wp_admin_nav[] = array( 770 // Create a Group. 771 if ( bp_user_can_create_groups() ) { 772 $nav[] = array( 772 773 'parent' => 'my-account-' . $this->id, 773 'id' => 'my-account-' . $this->id . '- invites',774 'title' => $pending,775 'href' => trailingslashit( $groups_link . 'invites' ),776 'position' => 30774 'id' => 'my-account-' . $this->id . '-create', 775 'title' => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ), 776 'href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ), 777 'position' => 90 777 778 ); 778 779 // Create a Group.780 if ( bp_user_can_create_groups() ) {781 $wp_admin_nav[] = array(782 'parent' => 'my-account-' . $this->id,783 'id' => 'my-account-' . $this->id . '-create',784 'title' => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ),785 'href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),786 'position' => 90787 );788 }789 779 } 790 780 791 parent::setup_admin_bar( $wp_admin_nav ); 781 // Setup the admin bar. 782 parent::setup_admin_bar( $nav ); 792 783 } 793 784 794 785 /** -
src/bp-messages/classes/class-bp-messages-component.php
172 172 'show_for_displayed_user' => $access, 173 173 'screen_function' => 'messages_screen_inbox', 174 174 'default_subnav_slug' => 'inbox', 175 'item_css_id' => $this->id 175 'item_css_id' => $this->id, 176 176 ); 177 177 178 178 // Add the subnav items to the profile. … … 183 183 'parent_slug' => $slug, 184 184 'screen_function' => 'messages_screen_inbox', 185 185 'position' => 10, 186 'user_has_access' => $access 186 'user_has_access' => $access, 187 187 ); 188 188 189 189 if ( bp_is_active( $this->id, 'star' ) ) { … … 194 194 'parent_slug' => $slug, 195 195 'screen_function' => 'bp_messages_star_screen', 196 196 'position' => 11, 197 'user_has_access' => $access 197 'user_has_access' => $access, 198 198 ); 199 199 } 200 200 … … 205 205 'parent_slug' => $slug, 206 206 'screen_function' => 'messages_screen_sentbox', 207 207 'position' => 20, 208 'user_has_access' => $access 208 'user_has_access' => $access, 209 209 ); 210 210 211 211 $sub_nav[] = array( … … 215 215 'parent_slug' => $slug, 216 216 'screen_function' => 'messages_screen_compose', 217 217 'position' => 30, 218 'user_has_access' => $access 218 'user_has_access' => $access, 219 219 ); 220 220 221 221 if ( bp_current_user_can( 'bp_moderate' ) ) { … … 226 226 'parent_slug' => $slug, 227 227 'screen_function' => 'messages_screen_notices', 228 228 'position' => 90, 229 'user_has_access' => true 229 'user_has_access' => true, 230 230 ); 231 231 } 232 232 … … 239 239 * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} for details. 240 240 */ 241 241 public function setup_admin_bar( $wp_admin_nav = array() ) { 242 if ( ! is_user_logged_in() ) { 243 return; 244 } 242 245 243 // Menus for logged in user. 244 if ( is_user_logged_in() ) { 245 246 // Setup the logged in user variables. 247 $messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ); 248 249 // Unread message count. 250 $count = messages_get_unread_count(); 251 if ( !empty( $count ) ) { 252 $title = sprintf( 253 /* translators: %s: Unread message count for the current user */ 254 __( 'Messages %s', 'buddypress' ), 255 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 256 ); 257 $inbox = sprintf( 258 /* translators: %s: Unread message count for the current user */ 259 __( 'Inbox %s', 'buddypress' ), 260 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 261 ); 262 } else { 263 $title = __( 'Messages', 'buddypress' ); 264 $inbox = __( 'Inbox', 'buddypress' ); 265 } 266 267 // Add main Messages menu. 268 $wp_admin_nav[] = array( 269 'parent' => buddypress()->my_account_menu_id, 270 'id' => 'my-account-' . $this->id, 271 'title' => $title, 272 'href' => $messages_link 273 ); 274 275 // Inbox. 276 $wp_admin_nav[] = array( 277 'parent' => 'my-account-' . $this->id, 278 'id' => 'my-account-' . $this->id . '-inbox', 279 'title' => $inbox, 280 'href' => $messages_link, 281 'position' => 10 282 ); 283 284 // Starred. 285 if ( bp_is_active( $this->id, 'star' ) ) { 286 $wp_admin_nav[] = array( 287 'parent' => 'my-account-' . $this->id, 288 'id' => 'my-account-' . $this->id . '-starred', 289 'title' => __( 'Starred', 'buddypress' ), 290 'href' => trailingslashit( $messages_link . bp_get_messages_starred_slug() ), 291 'position' => 11 292 ); 293 } 294 295 // Sent Messages. 296 $wp_admin_nav[] = array( 297 'parent' => 'my-account-' . $this->id, 298 'id' => 'my-account-' . $this->id . '-sentbox', 299 'title' => __( 'Sent', 'buddypress' ), 300 'href' => trailingslashit( $messages_link . 'sentbox' ), 301 'position' => 20 302 ); 246 // Get nav with 'show_in_admin_bar' support. 247 $nav = buddypress()->members->nav->get_admin_nav( array( 248 'parent_slug' => bp_get_messages_slug(), 249 ) ); 303 250 304 // Compose Message.305 $wp_admin_nav[] = array(306 'parent' => 'my-account-' . $this->id,307 'id' => 'my-account-' . $this->id . '-compose',308 'title' => __( 'Compose', 'buddypress' ),309 'href' => trailingslashit( $messages_link . 'compose' ),310 ' position' => 30251 // Set 'Inbox' subnav title. 252 $count = messages_get_unread_count(); 253 if ( !empty( $count ) ) { 254 $inbox = sprintf( 255 /* translators: %s: Unread message count for the current user */ 256 __( 'Inbox %s', 'buddypress' ), 257 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 311 258 ); 259 } else { 260 $inbox = __( 'Inbox', 'buddypress' ); 261 } 312 262 313 // Site Wide Notices. 314 if ( bp_current_user_can( 'bp_moderate' ) ) { 315 $wp_admin_nav[] = array( 316 'parent' => 'my-account-' . $this->id, 317 'id' => 'my-account-' . $this->id . '-notices', 318 'title' => __( 'All Member Notices', 'buddypress' ), 319 'href' => trailingslashit( $messages_link . 'notices' ), 320 'position' => 90 321 ); 263 // Override some nav items for the admin bar. 264 if ( ! empty( $nav['children'] ) ) { 265 foreach ( $nav['children'] as $key => $sub_nav ) { 266 // Override title for "Inbox" nav to add count. 267 if ( 'inbox' === $sub_nav->slug ) { 268 $nav['children'][$key]->name = $inbox; 269 } 322 270 } 323 271 } 324 272 325 parent::setup_admin_bar( $wp_admin_nav ); 273 // Configure nav array for setup_admin_bar() method. 274 $nav = $this->setup_admin_nav( $nav ); 275 276 // Setup the admin bar. 277 parent::setup_admin_bar( $nav ); 326 278 } 327 279 328 280 /** -
src/bp-notifications/classes/class-bp-notifications-component.php
192 192 * description. 193 193 */ 194 194 public function setup_admin_bar( $wp_admin_nav = array() ) { 195 if ( ! is_user_logged_in() ) { 196 return; 197 } 195 198 196 // Menus for logged in user. 197 if ( is_user_logged_in() ) { 198 199 // Setup the logged in user variables. 200 $notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() ); 201 202 // Pending notification requests. 203 $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ); 204 if ( ! empty( $count ) ) { 205 $title = sprintf( 206 /* translators: %s: Unread notification count for the current user */ 207 _x( 'Notifications %s', 'My Account Notification pending', 'buddypress' ), 208 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 209 ); 210 $unread = sprintf( 211 /* translators: %s: Unread notification count for the current user */ 212 _x( 'Unread %s', 'My Account Notification pending', 'buddypress' ), 213 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 214 ); 215 } else { 216 $title = _x( 'Notifications', 'My Account Notification', 'buddypress' ); 217 $unread = _x( 'Unread', 'My Account Notification sub nav', 'buddypress' ); 218 } 219 220 // Add the "My Account" sub menus. 221 $wp_admin_nav[] = array( 222 'parent' => buddypress()->my_account_menu_id, 223 'id' => 'my-account-' . $this->id, 224 'title' => $title, 225 'href' => $notifications_link 226 ); 199 // Get nav with 'show_in_admin_bar' support. 200 $nav = buddypress()->members->nav->get_admin_nav( array( 201 'parent_slug' => bp_get_notifications_slug(), 202 ) ); 227 203 228 // Unread.229 $wp_admin_nav[] = array(230 'parent' => 'my-account-' . $this->id,231 'id' => 'my-account-' . $this->id . '-unread',232 'title' => $unread,233 'href' => $notifications_link,234 ' position' => 10204 // Set 'Unread' subnav title. 205 $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() ); 206 if ( ! empty( $count ) ) { 207 $unread = sprintf( 208 /* translators: %s: Unread notification count for the current user */ 209 _x( 'Unread %s', 'My Account Notification pending', 'buddypress' ), 210 '<span class="count">' . bp_core_number_format( $count ) . '</span>' 235 211 ); 212 } else { 213 $unread = _x( 'Unread', 'My Account Notification sub nav', 'buddypress' ); 214 } 236 215 237 // Read.238 $wp_admin_nav[] = array(239 'parent' => 'my-account-' . $this->id,240 'id' => 'my-account-' . $this->id . '-read',241 'title' => _x( 'Read', 'My Account Notification sub nav', 'buddypress' ),242 'href' => trailingslashit( $notifications_link . 'read' ),243 'position' => 20244 );216 // Override some nav items for the admin bar. 217 if ( ! empty( $nav['children'] ) ) { 218 foreach ( $nav['children'] as $key => $sub_nav ) { 219 // Override title for "Unread" nav to add count. 220 if ( 'unread' === $sub_nav->slug ) { 221 $nav['children'][$key]->name = $unread; 222 } 223 } 245 224 } 246 225 247 parent::setup_admin_bar( $wp_admin_nav ); 226 // Configure nav array for setup_admin_bar() method. 227 $nav = $this->setup_admin_nav( $nav ); 228 229 // Setup the admin bar. 230 parent::setup_admin_bar( $nav ); 248 231 } 249 232 250 233 /** -
src/bp-settings/classes/class-bp-settings-component.php
103 103 'position' => 100, 104 104 'show_for_displayed_user' => $access, 105 105 'screen_function' => 'bp_settings_screen_general', 106 'default_subnav_slug' => 'general' 106 'default_subnav_slug' => 'general', 107 107 ); 108 108 109 109 // Add General Settings nav item. … … 114 114 'parent_slug' => $slug, 115 115 'screen_function' => 'bp_settings_screen_general', 116 116 'position' => 10, 117 'user_has_access' => $access 117 'user_has_access' => $access, 118 118 ); 119 119 120 120 // Add Email nav item. Formerly called 'Notifications', we 121 121 // retain the old slug and function names for backward compat. 122 122 $sub_nav[] = array( 123 'name' => __( 'Email', 'buddypress' ), 124 'slug' => 'notifications', 125 'parent_url' => $settings_link, 126 'parent_slug' => $slug, 127 'screen_function' => 'bp_settings_screen_notification', 128 'position' => 20, 129 'user_has_access' => $access 123 'name' => __( 'Email', 'buddypress' ), 124 'slug' => 'notifications', 125 'parent_url' => $settings_link, 126 'parent_slug' => $slug, 127 'screen_function' => 'bp_settings_screen_notification', 128 'position' => 20, 129 'user_has_access' => $access, 130 'show_in_admin_bar' => false, 130 131 ); 131 132 132 133 // Add Spam Account nav item. 133 134 if ( bp_current_user_can( 'bp_moderate' ) ) { 134 135 $sub_nav[] = array( 135 'name' => __( 'Capabilities', 'buddypress' ), 136 'slug' => 'capabilities', 137 'parent_url' => $settings_link, 138 'parent_slug' => $slug, 139 'screen_function' => 'bp_settings_screen_capabilities', 140 'position' => 80, 141 'user_has_access' => ! bp_is_my_profile() 136 'name' => __( 'Capabilities', 'buddypress' ), 137 'slug' => 'capabilities', 138 'parent_url' => $settings_link, 139 'parent_slug' => $slug, 140 'screen_function' => 'bp_settings_screen_capabilities', 141 'position' => 80, 142 'user_has_access' => ! bp_is_my_profile(), 143 'show_in_admin_bar' => false, 142 144 ); 143 145 } 144 146 145 147 // Add Delete Account nav item. 146 148 if ( ( ! bp_disable_account_deletion() && bp_is_my_profile() ) || bp_current_user_can( 'delete_users' ) ) { 147 149 $sub_nav[] = array( 148 'name' => __( 'Delete Account', 'buddypress' ), 149 'slug' => 'delete-account', 150 'parent_url' => $settings_link, 151 'parent_slug' => $slug, 152 'screen_function' => 'bp_settings_screen_delete_account', 153 'position' => 90, 154 'user_has_access' => ! is_super_admin( bp_displayed_user_id() ) 150 'name' => __( 'Delete Account', 'buddypress' ), 151 'slug' => 'delete-account', 152 'parent_url' => $settings_link, 153 'parent_slug' => $slug, 154 'screen_function' => 'bp_settings_screen_delete_account', 155 'position' => 90, 156 'user_has_access' => ! is_super_admin( bp_displayed_user_id() ), 157 'show_in_admin_bar' => false, 155 158 ); 156 159 } 157 160 … … 166 169 * @param array $wp_admin_nav Array of Admin Bar items. 167 170 */ 168 171 public function setup_admin_bar( $wp_admin_nav = array() ) { 172 if ( ! is_user_logged_in() ) { 173 return; 174 } 169 175 170 // Menus for logged in user. 171 if ( is_user_logged_in() ) { 176 // Get nav with 'show_in_admin_bar' support. 177 $nav = buddypress()->members->nav->get_admin_nav( array( 178 'parent_slug' => bp_get_settings_slug(), 179 ) ); 172 180 173 // Setup the logged in user variables.174 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug());181 // Configure nav array for setup_admin_bar() method. 182 $nav = $this->setup_admin_nav( $nav ); 175 183 176 // Add main Settings menu. 177 $wp_admin_nav[] = array( 178 'parent' => buddypress()->my_account_menu_id, 179 'id' => 'my-account-' . $this->id, 180 'title' => __( 'Settings', 'buddypress' ), 181 'href' => $settings_link 182 ); 184 // Notifications - only add the tab when there is something to display there. 185 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 183 186 184 // General Account.185 $ wp_admin_nav[] = array(187 if ( has_action( 'bp_notification_settings' ) ) { 188 $nav[] = array( 186 189 'parent' => 'my-account-' . $this->id, 187 'id' => 'my-account-' . $this->id . '- general',188 'title' => __( ' General', 'buddypress' ),189 'href' => $settings_link,190 'position' => 10190 'id' => 'my-account-' . $this->id . '-notifications', 191 'title' => __( 'Email', 'buddypress' ), 192 'href' => trailingslashit( $settings_link . 'notifications' ), 193 'position' => 20 191 194 ); 195 } 192 196 193 // Notifications - only add the tab when there is something to display there. 194 if ( has_action( 'bp_notification_settings' ) ) { 195 $wp_admin_nav[] = array( 196 'parent' => 'my-account-' . $this->id, 197 'id' => 'my-account-' . $this->id . '-notifications', 198 'title' => __( 'Email', 'buddypress' ), 199 'href' => trailingslashit( $settings_link . 'notifications' ), 200 'position' => 20 201 ); 202 } 203 204 // Delete Account 205 if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { 206 $wp_admin_nav[] = array( 207 'parent' => 'my-account-' . $this->id, 208 'id' => 'my-account-' . $this->id . '-delete-account', 209 'title' => __( 'Delete Account', 'buddypress' ), 210 'href' => trailingslashit( $settings_link . 'delete-account' ), 211 'position' => 90 212 ); 213 } 197 // Delete Account 198 if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) { 199 $nav[] = array( 200 'parent' => 'my-account-' . $this->id, 201 'id' => 'my-account-' . $this->id . '-delete-account', 202 'title' => __( 'Delete Account', 'buddypress' ), 203 'href' => trailingslashit( $settings_link . 'delete-account' ), 204 'position' => 90 205 ); 214 206 } 215 207 216 parent::setup_admin_bar( $wp_admin_nav ); 208 // Setup the admin bar. 209 parent::setup_admin_bar( $nav ); 217 210 } 218 211 } -
src/bp-xprofile/classes/class-bp-xprofile-component.php
212 212 'position' => 20, 213 213 'screen_function' => 'xprofile_screen_display_profile', 214 214 'default_subnav_slug' => 'public', 215 'item_css_id' => $this->id 215 'item_css_id' => $this->id, 216 216 ); 217 217 218 218 // Add the subnav items to the profile. … … 222 222 'parent_url' => $profile_link, 223 223 'parent_slug' => $slug, 224 224 'screen_function' => 'xprofile_screen_display_profile', 225 'position' => 10 225 'position' => 10, 226 226 ); 227 227 228 228 // Edit Profile. … … 233 233 'parent_slug' => $slug, 234 234 'screen_function' => 'xprofile_screen_edit_profile', 235 235 'position' => 20, 236 'user_has_access' => $access 236 'user_has_access' => $access, 237 237 ); 238 238 239 239 // Change Avatar. … … 245 245 'parent_slug' => $slug, 246 246 'screen_function' => 'xprofile_screen_change_avatar', 247 247 'position' => 30, 248 'user_has_access' => $access 248 'user_has_access' => $access, 249 249 ); 250 250 } 251 251 … … 258 258 'parent_slug' => $slug, 259 259 'screen_function' => 'xprofile_screen_change_cover_image', 260 260 'position' => 40, 261 'user_has_access' => $access 261 'user_has_access' => $access, 262 262 ); 263 263 } 264 264 … … 301 301 'parent_slug' => $settings_slug, 302 302 'screen_function' => 'bp_xprofile_screen_settings', 303 303 'position' => 30, 304 'user_has_access' => bp_core_can_edit_settings() 304 'user_has_access' => bp_core_can_edit_settings(), 305 305 ), 'members' ); 306 306 } 307 307 … … 313 313 * @param array $wp_admin_nav Admin Bar items. 314 314 */ 315 315 public function setup_admin_bar( $wp_admin_nav = array() ) { 316 if ( ! is_user_logged_in() ) { 317 return; 318 } 316 319 317 // Menus for logged in user. 318 if ( is_user_logged_in() ) { 319 320 // Profile link. 321 $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() ); 322 323 // Add the "Profile" sub menu. 324 $wp_admin_nav[] = array( 325 'parent' => buddypress()->my_account_menu_id, 326 'id' => 'my-account-' . $this->id, 327 'title' => _x( 'Profile', 'My Account Profile', 'buddypress' ), 328 'href' => $profile_link 329 ); 330 331 // View Profile. 332 $wp_admin_nav[] = array( 333 'parent' => 'my-account-' . $this->id, 334 'id' => 'my-account-' . $this->id . '-public', 335 'title' => _x( 'View', 'My Account Profile sub nav', 'buddypress' ), 336 'href' => $profile_link, 337 'position' => 10 338 ); 339 340 // Edit Profile. 341 $wp_admin_nav[] = array( 342 'parent' => 'my-account-' . $this->id, 343 'id' => 'my-account-' . $this->id . '-edit', 344 'title' => _x( 'Edit', 'My Account Profile sub nav', 'buddypress' ), 345 'href' => trailingslashit( $profile_link . 'edit' ), 346 'position' => 20 347 ); 348 349 // Edit Avatar. 350 if ( buddypress()->avatar->show_avatars ) { 351 $wp_admin_nav[] = array( 352 'parent' => 'my-account-' . $this->id, 353 'id' => 'my-account-' . $this->id . '-change-avatar', 354 'title' => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ), 355 'href' => trailingslashit( $profile_link . 'change-avatar' ), 356 'position' => 30 357 ); 358 } 320 // Get nav with 'show_in_admin_bar' support. 321 $nav = buddypress()->members->nav->get_admin_nav( array( 322 'parent_slug' => bp_get_profile_slug(), 323 ) ); 359 324 360 if ( bp_displayed_user_use_cover_image_header() ) { 361 $wp_admin_nav[] = array( 362 'parent' => 'my-account-' . $this->id, 363 'id' => 'my-account-' . $this->id . '-change-cover-image', 364 'title' => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ), 365 'href' => trailingslashit( $profile_link . 'change-cover-image' ), 366 'position' => 40 367 ); 368 } 369 } 325 // Configure nav array for setup_admin_bar() method. 326 $nav = $this->setup_admin_nav( $nav ); 370 327 371 parent::setup_admin_bar( $wp_admin_nav ); 328 // Setup the admin bar. 329 parent::setup_admin_bar( $nav ); 372 330 } 373 331 374 332 /**