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.


git-svn-id: https://develop.svn.wordpress.org/trunk@35504 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes 2015-11-04 16:02:12 +00:00
parent ebfc39e754
commit 14cd5cf3ed
1 changed files with 23 additions and 1 deletions

View File

@ -540,7 +540,29 @@ function get_taxonomy_labels( $tax ) {
);
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
$labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
$taxonomy = $tax->name;
$default_labels = clone $labels;
/**
* Filter the labels of a specific taxonomy.
*
* The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
*
* @since 4.4.0
*
* @see get_taxonomy_labels() for the full list of taxonomy labels.
*
* @param object $labels Object with labels for the taxonomy as member variables.
*/
$labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );
// Ensure that the filtered labels contain all required default values.
$labels = (object) array_merge( (array) $default_labels, (array) $labels );
return $labels;
}
/**