Make WordPress Core


Ignore:
Timestamp:
05/15/2014 03:50:46 AM (11 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in get_the_taxonomies(). Adds unit test.

See #22400.

File:
1 edited

Legend:

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

    r28241 r28415  
    37133713 * @return array
    37143714 */
    3715 function get_the_taxonomies($post = 0, $args = array() ) {
     3715function get_the_taxonomies( $post = 0, $args = array() ) {
    37163716    $post = get_post( $post );
    37173717
     
    37193719        'template' => '%s: %l.',
    37203720    ) );
    3721     extract( $args, EXTR_SKIP );
    37223721
    37233722    $taxonomies = array();
    37243723
    3725     if ( !$post )
     3724    if ( ! $post ) {
    37263725        return $taxonomies;
    3727 
    3728     foreach ( get_object_taxonomies($post) as $taxonomy ) {
    3729         $t = (array) get_taxonomy($taxonomy);
    3730         if ( empty($t['label']) )
     3726    }
     3727
     3728    foreach ( get_object_taxonomies( $post ) as $taxonomy ) {
     3729        $t = (array) get_taxonomy( $taxonomy );
     3730        if ( empty( $t['label'] ) ) {
    37313731            $t['label'] = $taxonomy;
    3732         if ( empty($t['args']) )
     3732        }
     3733        if ( empty( $t['args'] ) ) {
    37333734            $t['args'] = array();
    3734         if ( empty($t['template']) )
    3735             $t['template'] = $template;
    3736 
    3737         $terms = get_object_term_cache($post->ID, $taxonomy);
    3738         if ( false === $terms )
    3739             $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
    3740 
     3735        }
     3736        if ( empty( $t['template'] ) ) {
     3737            $t['template'] = $args['template'];
     3738        }
     3739
     3740        $terms = get_object_term_cache( $post->ID, $taxonomy );
     3741        if ( false === $terms ) {
     3742            $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
     3743        }
    37413744        $links = array();
    37423745
    3743         foreach ( $terms as $term )
    3744             $links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
    3745 
    3746         if ( $links )
    3747             $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
     3746        foreach ( $terms as $term ) {
     3747            $links[] = "<a href='" . esc_attr( get_term_link( $term ) ) . "'>$term->name</a>";
     3748        }
     3749        if ( $links ) {
     3750            $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
     3751        }
    37483752    }
    37493753    return $taxonomies;
Note: See TracChangeset for help on using the changeset viewer.