Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/05/2015 04:57:22 PM (11 years ago)
Author:
dcavins
Message:

Remove extract() from bp_core_new_nav_item.

Remove extract() and other formatting clean up
in bp_core_new_nav_item(),
bp_core_new_nav_default() and
bp_core_sort_nav_items(). Bracket if statements,
normalize white space.

See #6503.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-buddybar.php

    r9987 r9996  
    4747
    4848        $r = wp_parse_args( $args, $defaults );
    49         extract( $r, EXTR_SKIP );
    5049
    5150        // If we don't have the required info we need, don't create this subnav item
    52         if ( empty( $name ) || empty( $slug ) )
    53                 return false;
     51        if ( empty( $r['name'] ) || empty( $r['slug'] ) ) {
     52                return false;
     53        }
    5454
    5555        // If this is for site admins only and the user is not one, don't create the subnav item
    56         if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
    57                 return false;
    58 
    59         if ( empty( $item_css_id ) )
    60                 $item_css_id = $slug;
    61 
    62         $bp->bp_nav[$slug] = array(
    63                 'name'                    => $name,
    64                 'slug'                    => $slug,
    65                 'link'                    => trailingslashit( bp_loggedin_user_domain() . $slug ),
    66                 'css_id'                  => $item_css_id,
    67                 'show_for_displayed_user' => $show_for_displayed_user,
    68                 'position'                => $position,
    69                 'screen_function'         => &$screen_function,
    70                 'default_subnav_slug'     => $default_subnav_slug
     56        if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) {
     57                return false;
     58        }
     59
     60        if ( empty( $r['item_css_id'] ) ) {
     61                $r['item_css_id'] = $r['slug'];
     62        }
     63
     64        $bp->bp_nav[$r['slug']] = array(
     65                'name'                    => $r['name'],
     66                'slug'                    => $r['slug'],
     67                'link'                    => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ),
     68                'css_id'                  => $r['item_css_id'],
     69                'show_for_displayed_user' => $r['show_for_displayed_user'],
     70                'position'                => $r['position'],
     71                'screen_function'         => &$r['screen_function'],
     72                'default_subnav_slug'     => $r['default_subnav_slug']
    7173        );
    7274
    … …  
    7678         * looking at their own profile, don't create the nav item.
    7779         */
    78         if ( empty( $show_for_displayed_user ) && !bp_user_has_access() )
    79                 return false;
     80        if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) {
     81                return false;
     82        }
    8083
    8184        /**
    … …  
    8487         * directory or something else.
    8588         */
    86         if ( ( -1 != $position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() )
     89        if ( ( -1 != $r['position'] ) && bp_is_root_component( $r['slug'] ) && ! bp_displayed_user_id() ) {
    8790                return;
     91        }
    8892
    8993        // Look for current component
    90         if ( bp_is_current_component( $slug ) || bp_is_current_item( $slug ) ) {
     94        if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) {
    9195
    9296                // The requested URL has explicitly included the default subnav
    9397                // (eg: http://example.com/members/membername/activity/just-me/)
    9498                // The canonical version will not contain this subnav slug.
    95                 if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) && !bp_action_variable( 0 ) ) {
     99                if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && !bp_action_variable( 0 ) ) {
    96100                        unset( $bp->canonical_stack['action'] );
    97101                } elseif ( ! bp_current_action() ) {
    98102
    99103                        // Add our screen hook if screen function is callable
    100                         if ( is_callable( $screen_function ) ) {
    101                                 add_action( 'bp_screens', $screen_function, 3 );
     104                        if ( is_callable( $r['screen_function'] ) ) {
     105                                add_action( 'bp_screens', $r['screen_function'], 3 );
    102106                        }
    103107
    104                         if ( !empty( $default_subnav_slug ) ) {
     108                        if ( ! empty( $r['default_subnav_slug'] ) ) {
    105109
    106110                                /**
    … …  
    113117                                 * @param array  $r                   Parsed arguments for the nav item.
    114118                                 */
    115                                 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
     119                                $bp->current_action = apply_filters( 'bp_default_component_subnav', $r['default_subnav_slug'], $r );
    116120                        }
    117121                }
    … …  
    149153
    150154        $r = wp_parse_args( $args, $defaults );
    151         extract( $r, EXTR_SKIP );
    152 
    153         if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
     155
     156        if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) {
    154157                // Remove our screen hook if screen function is callable
    155158                if ( is_callable( $function ) ) {
    … …  
    158161        }
    159162
    160         $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;
    161 
    162         if ( bp_is_current_component( $parent_slug ) ) {
     163        $bp->bp_nav[$r['parent_slug']]['screen_function'] = &$r['screen_function'];
     164
     165        if ( bp_is_current_component( $r['parent_slug'] ) ) {
    163166
    164167                // The only way to tell whether to set the subnav is to peek at the unfiltered_uri
    165168                // Find the component
    166                 $component_uri_key = array_search( $parent_slug, $bp->unfiltered_uri );
     169                $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri );
    167170
    168171                if ( false !== $component_uri_key ) {
    169                         if ( !empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
     172                        if ( ! empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
    170173                                $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1];
    171174                        }
    … …  
    174177                // No subnav item has been requested in the URL, so set a new nav default
    175178                if ( empty( $unfiltered_action ) ) {
    176                         if ( !bp_is_current_action( $subnav_slug ) ) {
    177                                 if ( is_callable( $screen_function ) ) {
    178                                         add_action( 'bp_screens', $screen_function, 3 );
     179                        if ( ! bp_is_current_action( $r['subnav_slug'] ) ) {
     180                                if ( is_callable( $r['screen_function'] ) ) {
     181                                        add_action( 'bp_screens', $r['screen_function'], 3 );
    179182                                }
    180183
    181                                 $bp->current_action = $subnav_slug;
     184                                $bp->current_action = $r['subnav_slug'];
    182185                                unset( $bp->canonical_stack['action'] );
    183186                        }
    … …  
    185188                // The URL is explicitly requesting the new subnav item, but should be
    186189                // directed to the canonical URL
    187                 } elseif ( $unfiltered_action == $subnav_slug ) {
     190                } elseif ( $unfiltered_action == $r['subnav_slug'] ) {
    188191                        unset( $bp->canonical_stack['action'] );
    189192
    … …  
    210213        $bp = buddypress();
    211214
    212         if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
    213                 return false;
     215        if ( empty( $bp->bp_nav ) || ! is_array( $bp->bp_nav ) ) {
     216                return false;
     217        }
    214218
    215219        $temp = array();
    216220
    217221        foreach ( (array) $bp->bp_nav as $slug => $nav_item ) {
    218                 if ( empty( $temp[$nav_item['position']]) ) {
     222                if ( empty( $temp[$nav_item['position']] ) ) {
    219223                        $temp[$nav_item['position']] = $nav_item;
    220224                } else {
    … …  
    222226                        do {
    223227                                $nav_item['position']++;
    224                         } while ( !empty( $temp[$nav_item['position']] ) );
     228                        } while ( ! empty( $temp[$nav_item['position']] ) );
    225229
    226230                        $temp[$nav_item['position']] = $nav_item;
    … …  
    279283        ) );
    280284
    281         extract( $r, EXTR_SKIP );
    282 
    283285        // If we don't have the required info we need, don't create this subnav item
    284         if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
     286        if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) )
    285287                return false;
    286288
    287289        // Link was not forced, so create one
    288         if ( empty( $link ) ) {
    289                 $link = trailingslashit( $parent_url . $slug );
     290        if ( empty( $r['link'] ) ) {
     291                $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] );
    290292
    291293                // If this sub item is the default for its parent, skip the slug
    292                 if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {
    293                         $link = trailingslashit( $parent_url );
     294                if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) {
     295                        $r['link'] = trailingslashit( $r['parent_url'] );
    294296                }
    295297        }
    296298
    297299        // If this is for site admins only and the user is not one, don't create the subnav item
    298         if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
    299                 return false;
    300 
    301         if ( empty( $item_css_id ) )
    302                 $item_css_id = $slug;
     300        if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) {
     301                return false;
     302        }
     303
     304        if ( empty( $r['item_css_id'] ) ) {
     305                $r['item_css_id'] = $r['slug'];
     306        }
    303307
    304308        $subnav_item = array(
    305                 'name'              => $name,
    306                 'link'              => $link,
    307                 'slug'              => $slug,
    308                 'css_id'            => $item_css_id,
    309                 'position'          => $position,
    310                 'user_has_access'   => $user_has_access,
    311                 'no_access_url'     => $no_access_url,
    312                 'screen_function'   => &$screen_function,
     309                'name'              => $r['name'],
     310                'link'              => $r['link'],
     311                'slug'              => $r['slug'],
     312                'css_id'            => $r['item_css_id'],
     313                'position'          => $r['position'],
     314                'user_has_access'   => $r['user_has_access'],
     315                'no_access_url'     => $r['no_access_url'],
     316                'screen_function'   => &$r['screen_function'],
    313317                'show_in_admin_bar' => (bool) $r['show_in_admin_bar'],
    314318        );
    315319
    316         $bp->bp_options_nav[$parent_slug][$slug] = $subnav_item;
     320        $bp->bp_options_nav[$r['parent_slug']][$r['slug']] = $subnav_item;
    317321
    318322        /**
    … …  
    334338
    335339        // If we *don't* meet condition (1), return
    336         if ( ! bp_is_current_component( $parent_slug ) && ! bp_is_current_item( $parent_slug ) )
     340        if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) {
    337341                return;
     342        }
    338343
    339344        // If we *do* meet condition (2), then the added subnav item is currently being requested
    340         if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) {
     345        if ( ( bp_current_action() && bp_is_current_action( $r['slug'] ) ) || ( bp_is_user() && ! bp_current_action() && ( $r['screen_function'] == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) {
    341346
    342347                $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
Note: See TracChangeset for help on using the changeset viewer.