get_taxonomy_labels

Builds an object with all taxonomy labels out of a taxonomy object.

Description

(object) get_taxonomy_labels( (WP_Taxonomy) $tax ); 

Accepted keys of the label array in the taxonomy object:

- name - general name for the taxonomy, usually plural. The same as and overridden by $tax->label. Default is Tags/Categories - singular_name - name for one object of this taxonomy. Default is Tag/Category - search_items - Default is Search Tags/Search Categories - popular_items - This string isn't used on hierarchical taxonomies. Default is Popular Tags - all_items - Default is All Tags/All Categories - parent_item - This string isn't used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category - parent_item_colon - The same as parent_item,, but with colon : in the end - edit_item - Default is Edit Tag/Edit Category - view_item - Default is View Tag/View Category - update_item - Default is Update Tag/Update Category - add_new_item - Default is Add New Tag/Add New Category - new_item_name - Default is New Tag Name/New Category Name - separate_items_with_commas - This string isn't used on hierarchical taxonomies. Default is Separate tags with commas, used in the meta box. - add_or_remove_items - This string isn't used on hierarchical taxonomies. Default is Add or remove tags, used in the meta box when JavaScript is disabled. - choose_from_most_used - This string isn't used on hierarchical taxonomies. Default is Choose from the most used tags, used in the meta box. - not_found - Default is No tags found/"No categories found", used in the meta box and taxonomy list table. - no_terms - Default is No tags/"No categories", used in the posts and media list tables. - items_list_navigation - String for the table pagination hidden heading. - items_list - String for the table hidden heading.

Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories).

Returns (object)

object with all the labels as member variables.

Parameters (1)

0. $tax (WP_Taxonomy)
Taxonomy object.

Usage

  1. if ( !function_exists( 'get_taxonomy_labels' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Taxonomy object. 
  5. $tax = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_taxonomy_labels($tax); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function get_taxonomy_labels( $tax ) { 
  2. $tax->labels = (array) $tax->labels; 
  3.  
  4. if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) 
  5. $tax->labels['separate_items_with_commas'] = $tax->helps; 
  6.  
  7. if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) 
  8. $tax->labels['not_found'] = $tax->no_tagcloud; 
  9.  
  10. $nohier_vs_hier_defaults = array( 
  11. 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),  
  12. 'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),  
  13. 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),  
  14. 'popular_items' => array( __( 'Popular Tags' ), null ),  
  15. 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),  
  16. 'parent_item' => array( null, __( 'Parent Category' ) ),  
  17. 'parent_item_colon' => array( null, __( 'Parent Category:' ) ),  
  18. 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),  
  19. 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ),  
  20. 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),  
  21. 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),  
  22. 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),  
  23. 'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),  
  24. 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ),  
  25. 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),  
  26. 'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ),  
  27. 'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ),  
  28. 'items_list_navigation' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),  
  29. 'items_list' => array( __( 'Tags list' ), __( 'Categories list' ) ),  
  30. ); 
  31. $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; 
  32.  
  33. $labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults ); 
  34.  
  35. $taxonomy = $tax->name; 
  36.  
  37. $default_labels = clone $labels; 
  38.  
  39. /** 
  40. * Filters the labels of a specific taxonomy. 
  41. * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. 
  42. * @since 4.4.0 
  43. * @see get_taxonomy_labels() for the full list of taxonomy labels. 
  44. * @param object $labels Object with labels for the taxonomy as member variables. 
  45. */ 
  46. $labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels ); 
  47.  
  48. // Ensure that the filtered labels contain all required default values. 
  49. $labels = (object) array_merge( (array) $default_labels, (array) $labels ); 
  50.  
  51. return $labels;