Make WordPress Core

Changeset 35504


Ignore:
Timestamp:
11/04/2015 04:02:12 PM (8 years ago)
Author:
DrewAPicture
Message:

Taxonomy: Introduce the dynamic taxonomy_labels_{$taxonomy} filter, which can be used to manipulate the labels for a given taxonomy.

The addition of this hook brings parity with the earlier-introduced post_type_labels_{$post_type} filter, which allows for similarly manipulating labels for a given post type.

Note: It isn't possible to unset or remove default labels via either of these hooks, only to overwrite. This is because WordPress relies on defaults being set for use in various UIs and admin experiences.

Props flixos90.
Fixes #34554.

File:
1 edited

Legend:

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

    r35377 r35504  
    541541    $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
    542542
    543     return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
     543    $labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
     544
     545    $taxonomy = $tax->name;
     546
     547    $default_labels = clone $labels;
     548
     549    /**
     550     * Filter the labels of a specific taxonomy.
     551     *
     552     * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
     553     *
     554     * @since 4.4.0
     555     *
     556     * @see get_taxonomy_labels() for the full list of taxonomy labels.
     557     *
     558     * @param object $labels Object with labels for the taxonomy as member variables.
     559     */
     560    $labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );
     561
     562    // Ensure that the filtered labels contain all required default values.
     563    $labels = (object) array_merge( (array) $default_labels, (array) $labels );
     564
     565    return $labels;
    544566}
    545567
Note: See TracChangeset for help on using the changeset viewer.