Make WordPress Core

Changeset 35028


Ignore:
Timestamp:
10/12/2015 04:13:25 AM (9 years ago)
Author:
boonebgorges
Message:

Don't require a $taxonomy to be specified in get_term_field().

After [34997], the $taxonomy parameter of get_term() is optional. This
changeset brings get_term_field() in line with the new usage.

Adds unit tests for get_term_field().

Props DrewAPicture.
See #34245.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r34999 r35028  
    921921 * Get sanitized Term field.
    922922 *
    923  * Does checks for $term, based on the $taxonomy. The function is for contextual
    924  * reasons and for simplicity of usage. See sanitize_term_field() for more
    925  * information.
     923 * The function is for contextual reasons and for simplicity of usage.
    926924 *
    927925 * @since 2.3.0
    928  *
    929  * @param string $field    Term field to fetch.
    930  * @param int    $term     Term ID.
    931  * @param string $taxonomy Taxonomy Name.
     926 * @since 4.4.0 The `$taxonomy` parameter was made optional. `$term` can also now accept a WP_Term object.
     927 *
     928 * @see sanitize_term_field()
     929 *
     930 * @param string $field Term field to fetch.
     931 * @param int|WP_Term $term Term ID or object.
     932 * @param string $taxonomy Optional. Taxonomy Name. Default empty.
    932933 * @param string $context  Optional, default is display. Look at sanitize_term_field() for available options.
    933934 * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term.
    934935 */
    935 function get_term_field( $field, $term, $taxonomy, $context = 'display' ) {
    936     $term = (int) $term;
     936function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
    937937    $term = get_term( $term, $taxonomy );
    938938    if ( is_wp_error($term) )
     
    945945        return '';
    946946
    947     return sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);
     947    return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
    948948}
    949949
Note: See TracChangeset for help on using the changeset viewer.