WordPress.org

Make WordPress Core

Changeset 33022


Ignore:
Timestamp:
07/01/2015 12:53:05 PM (5 years ago)
Author:
boonebgorges
Message:

Don't allow $field param to be passed to get_term_link().

The new parameter creates inconsistencies in the signatures of the various
functions for fetching term links (get_term_feed_link(),
get_edit_term_link(), etc.).

Reverts [32553].

See #14156.

Location:
trunk
Files:
2 edited

Legend:

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

    r32933 r33022  
    44384438 *
    44394439 * @since 2.5.0
    4440  * @since 4.3.0 Introduced `$field` argument.
    44414440 *
    44424441 * @global WP_Rewrite $wp_rewrite
     
    44444443 * @param object|int|string $term     The term object, ID, or slug whose link will be retrieved.
    44454444 * @param string            $taxonomy Optional. Taxonomy. Default empty.
    4446  * @param string            $field    Optional. The term field that should be matched by the `$term` argument. Accepts
    4447  *                                    any `$field` values accepted by `get_term_by()`: 'slug', 'name',
    4448  *                                    'term_taxonomy_id', or 'id'. Default is 'slug', unless `$term` is an integer, in
    4449  *                                    which case it's asssumed to be an ID.
    44504445 * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
    44514446 */
    4452 function get_term_link( $term, $taxonomy = '', $field = null ) {
     4447function get_term_link( $term, $taxonomy = '' ) {
    44534448    global $wp_rewrite;
    44544449
    44554450    if ( !is_object($term) ) {
    4456         if ( is_null( $field ) ) {
    4457             $field = is_int( $term ) ? 'id' : 'slug';
    4458         }
    4459 
    4460         $term = get_term_by( $field, $term, $taxonomy );
     4451        if ( is_int( $term ) ) {
     4452            $term = get_term( $term, $taxonomy );
     4453        } else {
     4454            $term = get_term_by( 'slug', $term, $taxonomy );
     4455        }
    44614456    }
    44624457
  • trunk/tests/phpunit/tests/term/getTermLink.php

    r32553 r33022  
    4444
    4545    public function test_numeric_string_should_be_interpreted_as_term_slug() {
    46         $t1 = $this->factory->term->create( array(
    47             'taxonomy' => 'wptests_tax',
    48             'name' => 'foo',
    49         ) );
    50         $t2 = $this->factory->term->create( array(
    51             'taxonomy' => 'wptests_tax',
    52             'slug' => $t1,
    53         ) );
    54 
    55         $term = (string) $t1;
    56 
    57         $actual = get_term_link( $term, 'wptests_tax', 'id' );
    58         $this->assertContains( 'wptests_tax=foo', $actual );
    59     }
    60 
    61     /**
    62      * @ticket 14156
    63      */
    64     public function test_should_match_field_by_name() {
    65         $t = $this->factory->term->create( array(
    66             'taxonomy' => 'wptests_tax',
    67             'slug' => 'foo',
    68             'name' => 'Bar Term',
    69         ) );
    70 
    71         $actual = get_term_link( 'Bar Term', 'wptests_tax', 'name' );
    72         $this->assertContains( 'wptests_tax=foo', $actual );
    73     }
    74 
    75     /**
    76      * @ticket 14156
    77      */
    78     public function test_should_match_field_by_tt_id() {
    79         $t = $this->factory->term->create( array(
    80             'taxonomy' => 'wptests_tax',
    81             'slug' => 'foo',
    82             'name' => 'Bar Term',
    83         ) );
    84 
    85         $actual = get_term_link( 'Bar Term', 'wptests_tax', 'name' );
    86         $this->assertContains( 'wptests_tax=foo', $actual );
    87     }
    88 
    89     /**
    90      * @ticket 14156
    91      */
    92     public function test_numeric_string_should_be_interpreted_as_term_id_if_id_field_is_specified() {
    9346        $t1 = $this->factory->term->create( array(
    9447            'taxonomy' => 'wptests_tax',
Note: See TracChangeset for help on using the changeset viewer.