Make WordPress Core

Changeset 31581


Ignore:
Timestamp:
02/27/2015 08:30:13 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce 'get_object_terms' filter in wp_get_object_terms().

The existing 'wp_get_object_terms' filter accepts a parameter $taxonomies,
which is a list of taxonomy names formatted for direct use in a MySQL IN clause.
This formatting makes it difficult to make use of the taxonomy list in filter
callbacks. However, changing the parameters passed to the existing filter
raises backward compatibility concerns, so we introduce a new filter that
receives a structured $taxonomy_array parameter.

We also take this opportunity to correct and clean up some of the documentation
on the 'wp_get_object_terms' filter.

Props postpostmodern, doublesharp, wonderboymusic, nacin.
Fixes #18828.

File:
1 edited

Legend:

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

    r31532 r31581  
    26942694        $order = 'ASC';
    26952695
     2696    $taxonomy_array = $taxonomies;
    26962697    $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    26972698    $object_ids = implode(', ', $object_ids);
     
    27632764        $terms = array_values( array_unique( $terms ) );
    27642765    }
     2766
    27652767    /**
    27662768     * Filter the terms for a given object or objects.
    27672769     *
     2770     * @since 4.2.0
     2771     *
     2772     * @param array     $terms          An array of terms for the given object or objects.
     2773     * @param int|array $object_ids     Object ID or array of IDs.
     2774     * @param array     $taxonomy_array Array of taxonomies from which `$terms` were retrieved.
     2775     * @param array     $args           An array of arguments for retrieving terms for the given object(s).
     2776     *                                  See {@see wp_get_object_terms()} for details.
     2777     */
     2778    $terms = apply_filters( 'get_object_terms', $terms, $object_ids, $taxonomy_array, $args );
     2779
     2780    /**
     2781     * Filter the terms for a given object or objects.
     2782     *
     2783     * The `$taxonomies` parameter passed to this filter is formatted as a SQL fragment. The
     2784     * {@see 'get_object_terms'} filter is recommended as an alternative.
     2785     *
    27682786     * @since 2.8.0
    27692787     *
    2770      * @param array        $terms      An array of terms for the given object or objects.
    2771      * @param array|int    $object_ids Object ID or array of IDs.
    2772      * @param array|string $taxonomies A taxonomy or array of taxonomies.
    2773      * @param array        $args       An array of arguments for retrieving terms for
    2774      *                                 the given object(s).
     2788     * @param array     $terms      An array of terms for the given object or objects.
     2789     * @param int|array $object_ids Object ID or array of IDs.
     2790     * @param string    $taxonomies SQL-formatted (comma-separated and quoted) list of taxonomy names.
     2791     * @param array     $args       An array of arguments for retrieving terms for the given object(s).
     2792     *                              See {@see wp_get_object_terms()} for details.
    27752793     */
    27762794    return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args );
Note: See TracChangeset for help on using the changeset viewer.