Make WordPress Core

Changeset 28405


Ignore:
Timestamp:
05/15/2014 02:17:52 AM (12 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in wp_list_bookmarks().

See #22400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/bookmark-template.php

    r28404 r28405  
    139139                        );
    140140                }
    141                 $output .= $r['$after'] . "\n";
     141                $output .= $r['after'] . "\n";
    142142        } // end while
    143143
     
    211211 *              Default is not return anything.
    212212 */
    213 function wp_list_bookmarks($args = '') {
     213function wp_list_bookmarks( $args = '' ) {
    214214        $defaults = array(
    215215                'orderby' => 'name', 'order' => 'ASC',
     
    225225
    226226        $r = wp_parse_args( $args, $defaults );
    227         extract( $r, EXTR_SKIP );
    228227
    229228        $output = '';
    230229
    231         if ( $categorize ) {
    232                 $cats = get_terms( 'link_category', array( 'name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0 ) );
    233                 if ( empty( $cats ) )
     230        if ( $r['categorize'] ) {
     231                $cats = get_terms( 'link_category', array(
     232                        'name__like' => $r['category_name'],
     233                        'include' => $r['category'],
     234                        'exclude' => $r['exclude_category'],
     235                        'orderby' => $r['category_orderby'],
     236                        'order' => $r['category_order'],
     237                        'hierarchical' => 0
     238                ) );
     239                if ( empty( $cats ) ) {
    234240                        $categorize = false;
     241                }
    235242        }
    236243
     
    238245                // Split the bookmarks into ul's for each category
    239246                foreach ( (array) $cats as $cat ) {
    240                         $params = array_merge($r, array('category'=>$cat->term_id));
    241                         $bookmarks = get_bookmarks($params);
    242                         if ( empty($bookmarks) )
     247                        $params = array_merge( $r, array( 'category' => $cat->term_id ) );
     248                        $bookmarks = get_bookmarks( $params );
     249                        if ( empty( $bookmarks ) ) {
    243250                                continue;
    244                         $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
     251                        }
     252                        $output .= str_replace(
     253                                array( '%id', '%class' ),
     254                                array( "linkcat-$cat->term_id", $r['class'] ),
     255                                $r['category_before']
     256                        );
    245257                        /**
    246258                         * Filter the bookmarks category name.
     
    252264                        $catname = apply_filters( 'link_category', $cat->name );
    253265
    254                         $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
    255                         $output .= _walk_bookmarks($bookmarks, $r);
    256                         $output .= "\n\t</ul>\n$category_after\n";
     266                        $output .= $r['title_before'];
     267                        $output .= $catname;
     268                        $output .= $r['title_after'];
     269                        $output .= "\n\t<ul class='xoxo blogroll'>\n";
     270                        $output .= _walk_bookmarks( $bookmarks, $r );
     271                        $output .= "\n\t</ul>\n";
     272                        $output .= $r['category_after'] . "\n";
    257273                }
    258274        } else {
    259275                //output one single list using title_li for the title
    260                 $bookmarks = get_bookmarks($r);
    261 
    262                 if ( !empty($bookmarks) ) {
    263                         if ( !empty( $title_li ) ){
    264                                 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
    265                                 $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
    266                                 $output .= _walk_bookmarks($bookmarks, $r);
    267                                 $output .= "\n\t</ul>\n$category_after\n";
     276                $bookmarks = get_bookmarks( $r );
     277
     278                if ( ! empty( $bookmarks ) ) {
     279                        if ( ! empty( $r['title_li'] ) ) {
     280                                $output .= str_replace(
     281                                        array( '%id', '%class' ),
     282                                        array( "linkcat-" . $r['category'], $r['class'] ),
     283                                        $r['category_before']
     284                                );
     285                                $output .= $r['title_before'];
     286                                $output .= $r['title_li'];
     287                                $output .= $r['title_after'];
     288                                $output .= "\n\t<ul class='xoxo blogroll'>\n";
     289                                $output .= _walk_bookmarks( $bookmarks, $r );
     290                                $output .= "\n\t</ul>\n";
     291                                $output .= $r['category_after'] . "\n";
    268292                        } else {
    269                                 $output .= _walk_bookmarks($bookmarks, $r);
     293                                $output .= _walk_bookmarks( $bookmarks, $r );
    270294                        }
    271295                }
     
    277301         * @since 2.5.0
    278302         *
    279          * @param string $output The HTML list of bookmarks.
     303         * @param string $html The HTML list of bookmarks.
    280304         */
    281         $output = apply_filters( 'wp_list_bookmarks', $output );
    282 
    283         if ( !$echo )
    284                 return $output;
    285         echo $output;
     305        $html = apply_filters( 'wp_list_bookmarks', $output );
     306
     307        if ( ! $r['echo'] ) {
     308                return $html;
     309        }
     310        echo $html;
    286311}
Note: See TracChangeset for help on using the changeset viewer.