get_post_type_labels

Builds an object with all post type labels out of a post type object.

Description

(object) get_post_type_labels( (object|WP_Post_Type) $post_type_object ); 

Accepted keys of the label array in the post type object:

- name - General name for the post type, usually plural. The same and overridden by $post_type_object->label.. Default is Posts / Pages,. - singular_name - Name for one object of this post type. Default is Post / Page. - add_new - Default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a matching your post type. Example: '_x( Add New, product, textdomain );'. - add_new_item - Label for adding a new singular item. Default is Add New Post / Add New Page. - edit_item - Label for editing a singular item. Default is Edit Post / Edit Page. - new_item - Label for the new item page title. Default is New Post / New Page. - view_item - Label for viewing a singular item. Default is View Post / View Page. - view_items - Label for viewing post type archives. Default is View Posts / View Pages. - search_items - Label for searching plural items. Default is Search Posts / Search Pages. - not_found - Label used when no items are found. Default is No posts found / No pages found. - not_found_in_trash - Label used when no items are in the trash. Default is No posts found in Trash / No pages found in Trash. - parent_item_colon - Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is Parent Page:. - all_items - Label to signify all items in a submenu link. Default is All Posts / All Pages. - archives - Label for archives in nav menus. Default is Post Archives / Page Archives. - attributes - Label for the attributes meta box. Default is Post Attributes / Page Attributes. - insert_into_item - Label for the media frame button. Default is Insert into post / Insert into page. - uploaded_to_this_item - Label for the media frame filter. Default is Uploaded to this post / Uploaded to this page. - featured_image - Label for the Featured Image meta box title. Default is Featured Image. - set_featured_image - Label for setting the featured image. Default is Set featured image. - remove_featured_image - Label for removing the featured image. Default is Remove featured image. - use_featured_image - Label in the media frame for using a featured image. Default is Use as featured image. - menu_name - Label for the menu name. Default is the same as name . - filter_items_list - Label for the table views hidden heading. Default is Filter posts list / Filter pages list. - items_list_navigation - Label for the table pagination hidden heading. Default is Posts list navigation / Pages list navigation. - items_list - Label for the table hidden heading. Default is Posts list / Pages list.

Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages).

Note: To set labels used in post type admin notices, see the filter.

Returns (object)

Object with all the labels as member variables.

Parameters (1)

0. $post_type_object (object|WP_Post_Type)
The post type object.

Usage

  1. if ( !function_exists( 'get_post_type_labels' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // The post type object. 
  5. $post_type_object = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_type_labels($post_type_object); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function get_post_type_labels( $post_type_object ) { 
  2. $nohier_vs_hier_defaults = array( 
  3. 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),  
  4. 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),  
  5. 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),  
  6. 'add_new_item' => array( __('Add New Post'), __('Add New Page') ),  
  7. 'edit_item' => array( __('Edit Post'), __('Edit Page') ),  
  8. 'new_item' => array( __('New Post'), __('New Page') ),  
  9. 'view_item' => array( __('View Post'), __('View Page') ),  
  10. 'view_items' => array( __('View Posts'), __('View Pages') ),  
  11. 'search_items' => array( __('Search Posts'), __('Search Pages') ),  
  12. 'not_found' => array( __('No posts found.'), __('No pages found.') ),  
  13. 'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),  
  14. 'parent_item_colon' => array( null, __('Parent Page:') ),  
  15. 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),  
  16. 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),  
  17. 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),  
  18. 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),  
  19. 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),  
  20. 'featured_image' => array( __( 'Featured Image' ), __( 'Featured Image' ) ),  
  21. 'set_featured_image' => array( __( 'Set featured image' ), __( 'Set featured image' ) ),  
  22. 'remove_featured_image' => array( __( 'Remove featured image' ), __( 'Remove featured image' ) ),  
  23. 'use_featured_image' => array( __( 'Use as featured image' ), __( 'Use as featured image' ) ),  
  24. 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),  
  25. 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),  
  26. 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ),  
  27. ); 
  28. $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; 
  29.  
  30. $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); 
  31.  
  32. $post_type = $post_type_object->name; 
  33.  
  34. $default_labels = clone $labels; 
  35.  
  36. /** 
  37. * Filters the labels of a specific post type. 
  38. * The dynamic portion of the hook name, `$post_type`, refers to 
  39. * the post type slug. 
  40. * @since 3.5.0 
  41. * @see get_post_type_labels() for the full list of labels. 
  42. * @param object $labels Object with labels for the post type as member variables. 
  43. */ 
  44. $labels = apply_filters( "post_type_labels_{$post_type}", $labels ); 
  45.  
  46. // Ensure that the filtered labels contain all required default values. 
  47. $labels = (object) array_merge( (array) $default_labels, (array) $labels ); 
  48.  
  49. return $labels;