Skip to:
Content

BuddyPress.org

Ticket #3419: 3419.02.patch

File 3419.02.patch, 14.5 KB (added by imath, 10 years ago)
  • src/bp-activity/classes/class-bp-activity-component.php

    diff --git src/bp-activity/classes/class-bp-activity-component.php src/bp-activity/classes/class-bp-activity-component.php
    index 4f85efb..d112f17 100644
    class BP_Activity_Component extends BP_Component {  
    168168                        'position'            => 10,
    169169                        'screen_function'     => 'bp_activity_screen_my_activity',
    170170                        'default_subnav_slug' => 'just-me',
    171                         'item_css_id'         => $this->id
     171                        'item_css_id'         => $this->id,
     172                        'show_in_admin_bar'   => true,
    172173                );
    173174
    174175                // Add the subnav items to the activity nav item if we are using a theme that supports this.
    175176                $sub_nav[] = array(
    176                         'name'            => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ),
    177                         'slug'            => 'just-me',
    178                         'parent_url'      => $activity_link,
    179                         'parent_slug'     => $slug,
    180                         'screen_function' => 'bp_activity_screen_my_activity',
    181                         'position'        => 10
     177                        'name'              => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ),
     178                        'slug'              => 'just-me',
     179                        'parent_url'        => $activity_link,
     180                        'parent_slug'       => $slug,
     181                        'screen_function'   => 'bp_activity_screen_my_activity',
     182                        'position'          => 10,
     183                        'show_in_admin_bar' => true,
    182184                );
    183185
    184186                // Check @mentions.
    185187                if ( bp_activity_do_mentions() ) {
    186188                        $sub_nav[] = array(
    187                                 'name'            => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),
    188                                 'slug'            => 'mentions',
    189                                 'parent_url'      => $activity_link,
    190                                 'parent_slug'     => $slug,
    191                                 'screen_function' => 'bp_activity_screen_mentions',
    192                                 'position'        => 20,
    193                                 'item_css_id'     => 'activity-mentions'
     189                                'name'              => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),
     190                                'slug'              => 'mentions',
     191                                'parent_url'        => $activity_link,
     192                                'parent_slug'       => $slug,
     193                                'screen_function'   => 'bp_activity_screen_mentions',
     194                                'position'          => 20,
     195                                'item_css_id'       => 'activity-mentions',
     196                                'show_in_admin_bar' => true,
    194197                        );
    195198                }
    196199
    197200                // Favorite activity items.
    198201                if ( bp_activity_can_favorite() ) {
    199202                        $sub_nav[] = array(
    200                                 'name'            => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),
    201                                 'slug'            => 'favorites',
    202                                 'parent_url'      => $activity_link,
    203                                 'parent_slug'     => $slug,
    204                                 'screen_function' => 'bp_activity_screen_favorites',
    205                                 'position'        => 30,
    206                                 'item_css_id'     => 'activity-favs'
     203                                'name'              => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),
     204                                'slug'              => 'favorites',
     205                                'parent_url'        => $activity_link,
     206                                'parent_slug'       => $slug,
     207                                'screen_function'   => 'bp_activity_screen_favorites',
     208                                'position'          => 30,
     209                                'item_css_id'       => 'activity-favs',
     210                                'show_in_admin_bar' => true,
    207211                        );
    208212                }
    209213
    210214                // Additional menu if friends is active.
    211215                if ( bp_is_active( 'friends' ) ) {
    212216                        $sub_nav[] = array(
    213                                 'name'            => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ),
    214                                 'slug'            => bp_get_friends_slug(),
    215                                 'parent_url'      => $activity_link,
    216                                 'parent_slug'     => $slug,
    217                                 'screen_function' => 'bp_activity_screen_friends',
    218                                 'position'        => 40,
    219                                 'item_css_id'     => 'activity-friends'
     217                                'name'              => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ),
     218                                'slug'              => bp_get_friends_slug(),
     219                                'parent_url'        => $activity_link,
     220                                'parent_slug'       => $slug,
     221                                'screen_function'   => 'bp_activity_screen_friends',
     222                                'position'          => 40,
     223                                'item_css_id'       => 'activity-friends',
     224                                'show_in_admin_bar' => true,
    220225                        ) ;
    221226                }
    222227
    223228                // Additional menu if groups is active.
    224229                if ( bp_is_active( 'groups' ) ) {
    225230                        $sub_nav[] = array(
    226                                 'name'            => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ),
    227                                 'slug'            => bp_get_groups_slug(),
    228                                 'parent_url'      => $activity_link,
    229                                 'parent_slug'     => $slug,
    230                                 'screen_function' => 'bp_activity_screen_groups',
    231                                 'position'        => 50,
    232                                 'item_css_id'     => 'activity-groups'
     231                                'name'              => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ),
     232                                'slug'              => bp_get_groups_slug(),
     233                                'parent_url'        => $activity_link,
     234                                'parent_slug'       => $slug,
     235                                'screen_function'   => 'bp_activity_screen_groups',
     236                                'position'          => 50,
     237                                'item_css_id'       => 'activity-groups',
     238                                'show_in_admin_bar' => true,
    233239                        );
    234240                }
    235241
    … … class BP_Activity_Component extends BP_Component {  
    240246         * Set up the component entries in the WordPress Admin Bar.
    241247         *
    242248         * @since 1.5.0
     249         * @since 2.7.0 Sync the WP Admin Nav with BP Nav items having the `show_in_admin_bar` property set to true.
    243250         *
    244251         * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
    245252         *      parameter array.
    … … class BP_Activity_Component extends BP_Component {  
    251258
    252259                // Menus for logged in user.
    253260                if ( is_user_logged_in() ) {
     261                        $bp = buddypress();
    254262
    255263                        // Setup the logged in user variables.
    256264                        $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() );
    257265
    258                         // Unread message count.
    259                         if ( bp_activity_do_mentions() ) {
    260                                 $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
    261                                 if ( !empty( $count ) ) {
    262                                         $title = sprintf(
    263                                                 /* translators: %s: Unread mention count for the current user */
    264                                                 _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ),
    265                                                 '<span class="count">' . bp_core_number_format( $count ) . '</span>'
     266                        if ( isset( $bp->members->nav ) ) {
     267                                $nav = $bp->members->nav->get_admin_nav( array(
     268                                        'parent_slug' => bp_get_activity_slug(),
     269                                ) );
     270
     271                                if ( ! empty( $nav['parent'] ) ) {
     272                                        // Add the "Activity" sub menu.
     273                                        $wp_admin_nav[] = array(
     274                                                'parent' => buddypress()->my_account_menu_id,
     275                                                'id'     => 'my-account-' . $this->id,
     276                                                'title'  => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),
     277                                                'href'   => $activity_link
    266278                                        );
    267                                 } else {
    268                                         $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' );
    269279                                }
    270                         }
    271 
    272                         // Add the "Activity" sub menu.
    273                         $wp_admin_nav[] = array(
    274                                 'parent' => buddypress()->my_account_menu_id,
    275                                 'id'     => 'my-account-' . $this->id,
    276                                 'title'  => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),
    277                                 'href'   => $activity_link
    278                         );
    279 
    280                         // Personal.
    281                         $wp_admin_nav[] = array(
    282                                 'parent'   => 'my-account-' . $this->id,
    283                                 'id'       => 'my-account-' . $this->id . '-personal',
    284                                 'title'    => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ),
    285                                 'href'     => $activity_link,
    286                                 'position' => 10
    287                         );
    288280
    289                         // Mentions.
    290                         if ( bp_activity_do_mentions() ) {
    291                                 $wp_admin_nav[] = array(
    292                                         'parent'   => 'my-account-' . $this->id,
    293                                         'id'       => 'my-account-' . $this->id . '-mentions',
    294                                         'title'    => $title,
    295                                         'href'     => trailingslashit( $activity_link . 'mentions' ),
    296                                         'position' => 20
    297                                 );
    298                         }
    299 
    300                         // Favorite activity items.
    301                         if ( bp_activity_can_favorite() ) {
    302                                 $wp_admin_nav[] = array(
    303                                         'parent'   => 'my-account-' . $this->id,
    304                                         'id'       => 'my-account-' . $this->id . '-favorites',
    305                                         'title'    => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ),
    306                                         'href'     => trailingslashit( $activity_link . 'favorites' ),
    307                                         'position' => 30
    308                                 );
    309                         }
    310 
    311                         // Friends?
    312                         if ( bp_is_active( 'friends' ) ) {
    313                                 $wp_admin_nav[] = array(
    314                                         'parent'   => 'my-account-' . $this->id,
    315                                         'id'       => 'my-account-' . $this->id . '-friends',
    316                                         'title'    => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ),
    317                                         'href'     => trailingslashit( $activity_link . bp_get_friends_slug() ),
    318                                         'position' => 40
    319                                 );
    320                         }
    321 
    322                         // Groups?
    323                         if ( bp_is_active( 'groups' ) ) {
    324                                 $wp_admin_nav[] = array(
    325                                         'parent'   => 'my-account-' . $this->id,
    326                                         'id'       => 'my-account-' . $this->id . '-groups',
    327                                         'title'    => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ),
    328                                         'href'     => trailingslashit( $activity_link . bp_get_groups_slug() ),
    329                                         'position' => 50
    330                                 );
     281                                if ( ! empty( $nav['children'] ) ) {
     282                                        foreach ( $nav['children'] as $sub_nav ) {
     283                                                // Sub nav title defaults to its name.
     284                                                $sub_nav_title = $sub_nav->name;
     285
     286                                                if ( isset( $nav['parent']->default_subnav_slug ) && $sub_nav->slug !== $nav['parent']->default_subnav_slug ) {
     287                                                        $sub_nav_link  = trailingslashit( $activity_link . $sub_nav->slug );
     288                                                        $sub_nav_id    = sprintf( 'my-account-%s-%s', $this->id, $sub_nav->slug );
     289                                                } elseif ( isset( $nav['parent']->default_subnav_slug ) && $sub_nav->slug === $nav['parent']->default_subnav_slug ) {
     290                                                        $sub_nav_id    = sprintf( 'my-account-%s-personal', $this->id );
     291                                                        $sub_nav_link  = $activity_link;
     292                                                }
     293
     294                                                // Checking for unread mentions
     295                                                if ( 'mentions' === $sub_nav->slug && bp_activity_do_mentions() ) {
     296                                                        $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
     297                                                        if ( ! empty( $count ) ) {
     298                                                                $sub_nav_title = sprintf(
     299                                                                        /* translators: %s: Unread mention count for the current user */
     300                                                                        _x( 'Mentions %s', 'Toolbar Mention logged in user', 'buddypress' ),
     301                                                                        '<span class="count">' . bp_core_number_format( $count ) . '</span>'
     302                                                                );
     303                                                        }
     304                                                }
     305
     306                                                // Add the sub nav items
     307                                                $wp_admin_nav[] = array(
     308                                                        'parent'   => 'my-account-' . $this->id,
     309                                                        'id'       => $sub_nav_id,
     310                                                        'title'    => $sub_nav_title,
     311                                                        'href'     => $sub_nav_link,
     312                                                        'position' => $sub_nav->position,
     313                                                );
     314                                        }
     315                                }
    331316                        }
    332317                }
    333318
  • src/bp-core/bp-core-buddybar.php

    diff --git src/bp-core/bp-core-buddybar.php src/bp-core/bp-core-buddybar.php
    index 28f7a73..386a8c1 100644
    defined( 'ABSPATH' ) || exit;  
    3232 *     @type callable    $screen_function         The callback function that will run when the nav item is clicked.
    3333 *     @type bool|string $default_subnav_slug     Optional. The slug of the default subnav item to select when the nav
    3434 *                                                item is clicked.
     35 *     @type bool        $show_in_admin_bar       Optional. Whether to add this nav item to the WP Admin Bar.
     36 *                                                Default: False.
    3537 * }
    3638 * @param string       $component The component the navigation is attached to. Defaults to 'members'.
    3739 * @return bool|null Returns false on failure.
    … … function bp_core_new_nav_item( $args, $component = 'members' ) {  
    4951                'site_admin_only'         => false, // Can only site admins see this nav item?
    5052                'position'                => 99,    // Index of where this nav item should be positioned.
    5153                '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'       => false, // Whether to add this nav item to the WP Admin Bar.
    5356        );
    5457
    5558        $r = wp_parse_args( $args, $defaults );
    … … function bp_core_new_nav_item( $args, $component = 'members' ) {  
    106109 *     @type callable    $screen_function         The callback function that will run when the nav item is clicked.
    107110 *     @type bool|string $default_subnav_slug     Optional. The slug of the default subnav item to select when the nav
    108111 *                                                item is clicked.
     112 *     @type bool        $show_in_admin_bar       Optional. Whether to add this nav item to the WP Admin Bar.
     113 *                                                Default: False.
    109114 * }
    110115 * @param string       $component Optional. Component that the nav belongs to.
    111116 * @return bool|BP_Nav_Item Returns false on failure, new nav item on success.
    … … function bp_core_create_nav_link( $args = '', $component = 'members' ) {  
    121126                'site_admin_only'         => false, // Can only site admins see this nav item?
    122127                'position'                => 99,    // Index of where this nav item should be positioned.
    123128                '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'       => false, // Whether to add this nav item to the WP Admin Bar.
    125131        );
    126132
    127133        $r = wp_parse_args( $args, $defaults );
    … … function bp_core_create_nav_link( $args = '', $component = 'members' ) {  
    148154                'show_for_displayed_user' => $r['show_for_displayed_user'],
    149155                'position'                => $r['position'],
    150156                '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'],
    152159        );
    153160
    154161        // Add the item to the nav.
  • src/bp-core/classes/class-bp-core-nav.php

    diff --git src/bp-core/classes/class-bp-core-nav.php src/bp-core/classes/class-bp-core-nav.php
    index ed97c36..f0efd6f 100644
    class BP_Core_Nav {  
    399399
    400400                return $primary_nav_items;
    401401        }
     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        }
    402437}