From 9d6eeca0155519e237057072cf60754ab230ced0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 15 May 2014 02:18:16 +0000 Subject: [PATCH] Eliminate use of `extract()` in `wp_list_bookmarks()`. See #22400. Built from https://develop.svn.wordpress.org/trunk@28405 git-svn-id: http://core.svn.wordpress.org/trunk@28232 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/bookmark-template.php | 77 ++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/wp-includes/bookmark-template.php b/wp-includes/bookmark-template.php index cf0774b41e..adbe9611fa 100644 --- a/wp-includes/bookmark-template.php +++ b/wp-includes/bookmark-template.php @@ -138,7 +138,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) { 'display' ); } - $output .= $r['$after'] . "\n"; + $output .= $r['after'] . "\n"; } // end while return $output; @@ -210,7 +210,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) { * @return string|null Will only return if echo option is set to not echo. * Default is not return anything. */ -function wp_list_bookmarks($args = '') { +function wp_list_bookmarks( $args = '' ) { $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'exclude_category' => '', @@ -224,24 +224,36 @@ function wp_list_bookmarks($args = '') { ); $r = wp_parse_args( $args, $defaults ); - extract( $r, EXTR_SKIP ); $output = ''; - if ( $categorize ) { - $cats = get_terms( 'link_category', array( 'name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0 ) ); - if ( empty( $cats ) ) + if ( $r['categorize'] ) { + $cats = get_terms( 'link_category', array( + 'name__like' => $r['category_name'], + 'include' => $r['category'], + 'exclude' => $r['exclude_category'], + 'orderby' => $r['category_orderby'], + 'order' => $r['category_order'], + 'hierarchical' => 0 + ) ); + if ( empty( $cats ) ) { $categorize = false; + } } if ( $categorize ) { // Split the bookmarks into ul's for each category foreach ( (array) $cats as $cat ) { - $params = array_merge($r, array('category'=>$cat->term_id)); - $bookmarks = get_bookmarks($params); - if ( empty($bookmarks) ) + $params = array_merge( $r, array( 'category' => $cat->term_id ) ); + $bookmarks = get_bookmarks( $params ); + if ( empty( $bookmarks ) ) { continue; - $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before); + } + $output .= str_replace( + array( '%id', '%class' ), + array( "linkcat-$cat->term_id", $r['class'] ), + $r['category_before'] + ); /** * Filter the bookmarks category name. * @@ -251,22 +263,34 @@ function wp_list_bookmarks($args = '') { */ $catname = apply_filters( 'link_category', $cat->name ); - $output .= "$title_before$catname$title_after\n\t\n$category_after\n"; + $output .= $r['title_before']; + $output .= $catname; + $output .= $r['title_after']; + $output .= "\n\t\n"; + $output .= $r['category_after'] . "\n"; } } else { //output one single list using title_li for the title - $bookmarks = get_bookmarks($r); + $bookmarks = get_bookmarks( $r ); - if ( !empty($bookmarks) ) { - if ( !empty( $title_li ) ){ - $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before); - $output .= "$title_before$title_li$title_after\n\t\n$category_after\n"; + if ( ! empty( $bookmarks ) ) { + if ( ! empty( $r['title_li'] ) ) { + $output .= str_replace( + array( '%id', '%class' ), + array( "linkcat-" . $r['category'], $r['class'] ), + $r['category_before'] + ); + $output .= $r['title_before']; + $output .= $r['title_li']; + $output .= $r['title_after']; + $output .= "\n\t\n"; + $output .= $r['category_after'] . "\n"; } else { - $output .= _walk_bookmarks($bookmarks, $r); + $output .= _walk_bookmarks( $bookmarks, $r ); } } } @@ -276,11 +300,12 @@ function wp_list_bookmarks($args = '') { * * @since 2.5.0 * - * @param string $output The HTML list of bookmarks. + * @param string $html The HTML list of bookmarks. */ - $output = apply_filters( 'wp_list_bookmarks', $output ); + $html = apply_filters( 'wp_list_bookmarks', $output ); - if ( !$echo ) - return $output; - echo $output; + if ( ! $r['echo'] ) { + return $html; + } + echo $html; }