Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/08/2016 05:56:22 AM (8 years ago)
Author:
r-a-y
Message:

BP Component: Allow plugins to set a custom position when registering an admin bar subnav menu.

This commit allows plugins to set a 'position' key when registering a WP
Admin Bar subnav menu item in the setup_admin_bar() method.

Previously, plugins had to do all sorts of array shuffling in order to
register their subnav at a preferred position. For backward compatibility,
we do some 'position' key backfilling, so if a plugin isn't using the new
'position' key, their subnav should still display at the same location.

Fixes #6859.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-component.php

    r10526 r10555  
    549549        // Do we have Toolbar menus to add?
    550550        if ( !empty( $wp_admin_nav ) ) {
     551            // Fill in position if one wasn't passed for backpat.
     552            $pos = 0;
     553            $not_set_pos = 1;
     554            foreach( $wp_admin_nav as $key => $nav ) {
     555                if ( ! isset( $nav['position'] ) ) {
     556                    $wp_admin_nav[$key]['position'] = $pos + $not_set_pos;
     557
     558                    if ( 9 !== $not_set_pos ) {
     559                        ++$not_set_pos;
     560                    }
     561                } else {
     562                    $pos = $nav['position'];
     563
     564                    // Reset not set pos to 1
     565                    if ( $pos % 10 === 0 ) {
     566                        $not_set_pos = 1;
     567                    }
     568                }
     569            }
     570
     571            // Sort admin nav by position.
     572            $wp_admin_nav = bp_sort_by_key( $wp_admin_nav, 'position', 'num' );
    551573
    552574            // Set this objects menus.
Note: See TracChangeset for help on using the changeset viewer.