Skip to:
Content

BuddyPress.org

Ticket #6503: 6503-remove-extract.patch

File 6503-remove-extract.patch, 10.6 KB (added by dcavins, 11 years ago)

Remove extract() from bp_core_new_nav_item.

Also 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.

  • src/bp-core/bp-core-buddybar.php

    diff --git a/src/bp-core/bp-core-buddybar.php b/src/bp-core/bp-core-buddybar.php
    index ca87d9a..ebcd9e7 100644
    a b function bp_core_new_nav_item( $args = '' ) { 
    5050        );
    5151
    5252        $r = wp_parse_args( $args, $defaults );
    53         extract( $r, EXTR_SKIP );
    5453
    5554        // If we don't have the required info we need, don't create this subnav item
    56         if ( empty( $name ) || empty( $slug ) )
     55        if ( empty( $r['name'] ) || empty( $r['slug'] ) ) {
    5756                return false;
     57        }
    5858
    5959        // If this is for site admins only and the user is not one, don't create the subnav item
    60         if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
     60        if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    6161                return false;
     62        }
     63
     64        if ( empty( $r['item_css_id'] ) ) {
     65                $r['item_css_id'] = $r['slug'];
     66        }
    6267
    63         if ( empty( $item_css_id ) )
    64                 $item_css_id = $slug;
    65 
    66         $bp->bp_nav[$slug] = array(
    67                 'name'                    => $name,
    68                 'slug'                    => $slug,
    69                 'link'                    => trailingslashit( bp_loggedin_user_domain() . $slug ),
    70                 'css_id'                  => $item_css_id,
    71                 'show_for_displayed_user' => $show_for_displayed_user,
    72                 'position'                => $position,
    73                 'screen_function'         => &$screen_function,
    74                 'default_subnav_slug'     => $default_subnav_slug
     68        $bp->bp_nav[$r['slug']] = array(
     69                'name'                    => $r['name'],
     70                'slug'                    => $r['slug'],
     71                'link'                    => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ),
     72                'css_id'                  => $r['item_css_id'],
     73                'show_for_displayed_user' => $r['show_for_displayed_user'],
     74                'position'                => $r['position'],
     75                'screen_function'         => &$r['screen_function'],
     76                'default_subnav_slug'     => $r['default_subnav_slug']
    7577        );
    7678
    7779        /**
    function bp_core_new_nav_item( $args = '' ) { 
    7981         * the logged in user is not the displayed user
    8082         * looking at their own profile, don't create the nav item.
    8183         */
    82         if ( empty( $show_for_displayed_user ) && !bp_user_has_access() )
     84        if ( empty( $r['show_for_displayed_user'] ) && ! bp_user_has_access() ) {
    8385                return false;
     86        }
    8487
    8588        /**
    8689         * If the nav item is visible, we are not viewing a user, and this is a root
    8790         * component, don't attach the default subnav function so we can display a
    8891         * directory or something else.
    8992         */
    90         if ( ( -1 != $position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() )
     93        if ( ( -1 != $r['position'] ) && bp_is_root_component( $r['slug'] ) && ! bp_displayed_user_id() ) {
    9194                return;
     95        }
    9296
    9397        // Look for current component
    94         if ( bp_is_current_component( $slug ) || bp_is_current_item( $slug ) ) {
     98        if ( bp_is_current_component( $r['slug'] ) || bp_is_current_item( $r['slug'] ) ) {
    9599
    96100                // The requested URL has explicitly included the default subnav
    97101                // (eg: http://example.com/members/membername/activity/just-me/)
    98102                // The canonical version will not contain this subnav slug.
    99                 if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) && !bp_action_variable( 0 ) ) {
     103                if ( ! empty( $r['default_subnav_slug'] ) && bp_is_current_action( $r['default_subnav_slug'] ) && !bp_action_variable( 0 ) ) {
    100104                        unset( $bp->canonical_stack['action'] );
    101105                } elseif ( ! bp_current_action() ) {
    102106
    103107                        // Add our screen hook if screen function is callable
    104                         if ( is_callable( $screen_function ) ) {
    105                                 add_action( 'bp_screens', $screen_function, 3 );
     108                        if ( is_callable( $r['screen_function'] ) ) {
     109                                add_action( 'bp_screens', $r['screen_function'], 3 );
    106110                        }
    107111
    108                         if ( !empty( $default_subnav_slug ) ) {
     112                        if ( ! empty( $r['default_subnav_slug'] ) ) {
    109113
    110114                                /**
    111115                                 * Filters the default component subnav item.
    function bp_core_new_nav_item( $args = '' ) { 
    116120                                 *                                    to select when clicked.
    117121                                 * @param array  $r                   Parsed arguments for the nav item.
    118122                                 */
    119                                 $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
     123                                $bp->current_action = apply_filters( 'bp_default_component_subnav', $r['default_subnav_slug'], $r );
    120124                        }
    121125                }
    122126        }
    function bp_core_new_nav_default( $args = '' ) { 
    154158        );
    155159
    156160        $r = wp_parse_args( $args, $defaults );
    157         extract( $r, EXTR_SKIP );
    158161
    159         if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
     162        if ( $function = $bp->bp_nav[$r['parent_slug']]['screen_function'] ) {
    160163                // Remove our screen hook if screen function is callable
    161164                if ( is_callable( $function ) ) {
    162165                        remove_action( 'bp_screens', $function, 3 );
    163166                }
    164167        }
    165168
    166         $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;
     169        $bp->bp_nav[$r['parent_slug']]['screen_function'] = &$r['screen_function'];
    167170
    168         if ( bp_is_current_component( $parent_slug ) ) {
     171        if ( bp_is_current_component( $r['parent_slug'] ) ) {
    169172
    170173                // The only way to tell whether to set the subnav is to peek at the unfiltered_uri
    171174                // Find the component
    172                 $component_uri_key = array_search( $parent_slug, $bp->unfiltered_uri );
     175                $component_uri_key = array_search( $r['parent_slug'], $bp->unfiltered_uri );
    173176
    174177                if ( false !== $component_uri_key ) {
    175                         if ( !empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
     178                        if ( ! empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
    176179                                $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1];
    177180                        }
    178181                }
    179182
    180183                // No subnav item has been requested in the URL, so set a new nav default
    181184                if ( empty( $unfiltered_action ) ) {
    182                         if ( !bp_is_current_action( $subnav_slug ) ) {
    183                                 if ( is_callable( $screen_function ) ) {
    184                                         add_action( 'bp_screens', $screen_function, 3 );
     185                        if ( ! bp_is_current_action( $r['subnav_slug'] ) ) {
     186                                if ( is_callable( $r['screen_function'] ) ) {
     187                                        add_action( 'bp_screens', $r['screen_function'], 3 );
    185188                                }
    186189
    187                                 $bp->current_action = $subnav_slug;
     190                                $bp->current_action = $r['subnav_slug'];
    188191                                unset( $bp->canonical_stack['action'] );
    189192                        }
    190193
    191194                // The URL is explicitly requesting the new subnav item, but should be
    192195                // directed to the canonical URL
    193                 } elseif ( $unfiltered_action == $subnav_slug ) {
     196                } elseif ( $unfiltered_action == $r['subnav_slug'] ) {
    194197                        unset( $bp->canonical_stack['action'] );
    195198
    196199                // In all other cases (including the case where the original subnav item
    function bp_core_new_nav_default( $args = '' ) { 
    215218function bp_core_sort_nav_items() {
    216219        $bp = buddypress();
    217220
    218         if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
     221        if ( empty( $bp->bp_nav ) || ! is_array( $bp->bp_nav ) ) {
    219222                return false;
     223        }
    220224
    221225        $temp = array();
    222226
    223227        foreach ( (array) $bp->bp_nav as $slug => $nav_item ) {
    224                 if ( empty( $temp[$nav_item['position']]) ) {
     228                if ( empty( $temp[$nav_item['position']] ) ) {
    225229                        $temp[$nav_item['position']] = $nav_item;
    226230                } else {
    227231                        // increase numbers here to fit new items in.
    228232                        do {
    229233                                $nav_item['position']++;
    230                         } while ( !empty( $temp[$nav_item['position']] ) );
     234                        } while ( ! empty( $temp[$nav_item['position']] ) );
    231235
    232236                        $temp[$nav_item['position']] = $nav_item;
    233237                }
    function bp_core_new_subnav_item( $args = '' ) { 
    288292                'show_in_admin_bar' => false, // Show the Manage link in the current group's "Edit" Admin Bar menu
    289293        ) );
    290294
    291         extract( $r, EXTR_SKIP );
    292 
    293295        // If we don't have the required info we need, don't create this subnav item
    294         if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
     296        if ( empty( $r['name'] ) || empty( $r['slug'] ) || empty( $r['parent_slug'] ) || empty( $r['parent_url'] ) || empty( $r['screen_function'] ) )
    295297                return false;
    296298
    297299        // Link was not forced, so create one
    298         if ( empty( $link ) ) {
    299                 $link = trailingslashit( $parent_url . $slug );
     300        if ( empty( $r['link'] ) ) {
     301                $r['link'] = trailingslashit( $r['parent_url'] . $r['slug'] );
    300302
    301303                // If this sub item is the default for its parent, skip the slug
    302                 if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {
    303                         $link = trailingslashit( $parent_url );
     304                if ( ! empty( $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) && $r['slug'] == $bp->bp_nav[$r['parent_slug']]['default_subnav_slug'] ) {
     305                        $r['link'] = trailingslashit( $r['parent_url'] );
    304306                }
    305307        }
    306308
    307309        // If this is for site admins only and the user is not one, don't create the subnav item
    308         if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
     310        if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    309311                return false;
     312        }
    310313
    311         if ( empty( $item_css_id ) )
    312                 $item_css_id = $slug;
     314        if ( empty( $r['item_css_id'] ) ) {
     315                $r['item_css_id'] = $r['slug'];
     316        }
    313317
    314318        $subnav_item = array(
    315                 'name'              => $name,
    316                 'link'              => $link,
    317                 'slug'              => $slug,
    318                 'css_id'            => $item_css_id,
    319                 'position'          => $position,
    320                 'user_has_access'   => $user_has_access,
    321                 'no_access_url'     => $no_access_url,
    322                 'screen_function'   => &$screen_function,
     319                'name'              => $r['name'],
     320                'link'              => $r['link'],
     321                'slug'              => $r['slug'],
     322                'css_id'            => $r['item_css_id'],
     323                'position'          => $r['position'],
     324                'user_has_access'   => $r['user_has_access'],
     325                'no_access_url'     => $r['no_access_url'],
     326                'screen_function'   => &$r['screen_function'],
    323327                'show_in_admin_bar' => (bool) $r['show_in_admin_bar'],
    324328        );
    325329
    326         $bp->bp_options_nav[$parent_slug][$slug] = $subnav_item;
     330        $bp->bp_options_nav[$r['parent_slug']][$r['slug']] = $subnav_item;
    327331
    328332        /**
    329333         * The last step is to hook the screen function for the added subnav item. But this only
    function bp_core_new_subnav_item( $args = '' ) { 
    343347         */
    344348
    345349        // If we *don't* meet condition (1), return
    346         if ( ! bp_is_current_component( $parent_slug ) && ! bp_is_current_item( $parent_slug ) )
     350        if ( ! bp_is_current_component( $r['parent_slug'] ) && ! bp_is_current_item( $r['parent_slug'] ) ) {
    347351                return;
     352        }
    348353
    349354        // If we *do* meet condition (2), then the added subnav item is currently being requested
    350         if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) {
     355        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'] ) ) ) {
    351356
    352357                $hooked = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
    353358
    function bp_core_new_subnav_item( $args = '' ) { 
    356361                        bp_core_no_access( $hooked['redirect_args'] );
    357362                }
    358363        }
     364
    359365}
    360366
    361367/**