_get_custom_object_labels

Build an object with custom-something object (post type, taxonomy) labels out of a custom-something object.

Description

(object) _get_custom_object_labels( (object) $object, (array) $nohier_vs_hier_defaults ); 

Returns (object)

Object containing labels for the given custom-something object.

Parameters (2)

0. $object (object)
A custom-something object.
1. $nohier_vs_hier_defaults (array)
Hierarchical vs non-hierarchical default labels.

Usage

  1. if ( !function_exists( '_get_custom_object_labels' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // A custom-something object. 
  5. $object = null; 
  6.  
  7. // Hierarchical vs non-hierarchical default labels. 
  8. $nohier_vs_hier_defaults = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _get_custom_object_labels($object, $nohier_vs_hier_defaults); 
  12.  

Defined (1)

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

/wp-includes/post.php  
  1. function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) { 
  2. $object->labels = (array) $object->labels; 
  3.  
  4. if ( isset( $object->label ) && empty( $object->labels['name'] ) ) 
  5. $object->labels['name'] = $object->label; 
  6.  
  7. if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) 
  8. $object->labels['singular_name'] = $object->labels['name']; 
  9.  
  10. if ( ! isset( $object->labels['name_admin_bar'] ) ) 
  11. $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name; 
  12.  
  13. if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) 
  14. $object->labels['menu_name'] = $object->labels['name']; 
  15.  
  16. if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) 
  17. $object->labels['all_items'] = $object->labels['menu_name']; 
  18.  
  19. if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) { 
  20. $object->labels['archives'] = $object->labels['all_items']; 
  21.  
  22. $defaults = array(); 
  23. foreach ( $nohier_vs_hier_defaults as $key => $value ) { 
  24. $defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; 
  25. $labels = array_merge( $defaults, $object->labels ); 
  26. $object->labels = (object) $object->labels; 
  27.  
  28. return (object) $labels;