Eliminate use of `extract()` in `wp_terms_checklist()`.

See #22400.

Built from https://develop.svn.wordpress.org/trunk@28410


git-svn-id: http://core.svn.wordpress.org/trunk@28237 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-05-15 03:09:15 +00:00
parent a75f8137bc
commit 7ebab48f4c
1 changed files with 38 additions and 24 deletions

View File

@ -136,7 +136,7 @@ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $select
* @param int $post_id * @param int $post_id
* @param array $args * @param array $args
*/ */
function wp_terms_checklist($post_id = 0, $args = array()) { function wp_terms_checklist( $post_id = 0, $args = array() ) {
$defaults = array( $defaults = array(
'descendants_and_self' => 0, 'descendants_and_self' => 0,
'selected_cats' => false, 'selected_cats' => false,
@ -156,41 +156,55 @@ function wp_terms_checklist($post_id = 0, $args = array()) {
* @param array $args An array of arguments. * @param array $args An array of arguments.
* @param int $post_id The post ID. * @param int $post_id The post ID.
*/ */
$args = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
extract( wp_parse_args($args, $defaults), EXTR_SKIP ); $r = wp_parse_args( $params, $defaults );
if ( empty($walker) || !is_a($walker, 'Walker') ) if ( empty( $r['walker'] ) || ! is_a( $r['walker'], 'Walker' ) ) {
$walker = new Walker_Category_Checklist; $walker = new Walker_Category_Checklist;
} else {
$walker = $r['walker'];
}
$descendants_and_self = (int) $descendants_and_self; $taxonomy = $r['taxonomy'];
$descendants_and_self = (int) $r['descendants_and_self'];
$args = array('taxonomy' => $taxonomy); $args = array( 'taxonomy' => $taxonomy );
$tax = get_taxonomy($taxonomy); $tax = get_taxonomy( $taxonomy );
$args['disabled'] = !current_user_can($tax->cap->assign_terms); $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
if ( is_array( $selected_cats ) ) if ( is_array( $r['selected_cats'] ) ) {
$args['selected_cats'] = $selected_cats; $args['selected_cats'] = $r['selected_cats'];
elseif ( $post_id ) } elseif ( $post_id ) {
$args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
else } else {
$args['selected_cats'] = array(); $args['selected_cats'] = array();
}
if ( is_array( $popular_cats ) ) if ( is_array( $r['popular_cats'] ) ) {
$args['popular_cats'] = $popular_cats; $args['popular_cats'] = $r['popular_cats'];
else } else {
$args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); $args['popular_cats'] = get_terms( $taxonomy, array(
'fields' => 'ids',
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
'hierarchical' => false
) );
}
if ( $descendants_and_self ) { if ( $descendants_and_self ) {
$categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) ); $categories = (array) get_terms( $taxonomy, array(
'child_of' => $descendants_and_self,
'hierarchical' => 0,
'hide_empty' => 0
) );
$self = get_term( $descendants_and_self, $taxonomy ); $self = get_term( $descendants_and_self, $taxonomy );
array_unshift( $categories, $self ); array_unshift( $categories, $self );
} else { } else {
$categories = (array) get_terms($taxonomy, array('get' => 'all')); $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
} }
if ( $checked_ontop ) { if ( $r['checked_ontop'] ) {
// Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
$checked_categories = array(); $checked_categories = array();
$keys = array_keys( $categories ); $keys = array_keys( $categories );
@ -203,10 +217,10 @@ function wp_terms_checklist($post_id = 0, $args = array()) {
} }
// Put checked cats on top // Put checked cats on top
echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); echo call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
} }
// Then the rest of them // Then the rest of them
echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); echo call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
} }
/** /**