Advertisement
Guest User

Untitled

a guest
May 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. function get_post_type_labels( $post_type_object ) {
  2.     return _get_custom_object_labels( $post_type_object );
  3. }
  4.  
  5. function _get_custom_object_labels( $object ) {
  6.     if ( isset( $object->label ) ) {
  7.         $object->labels['name'] = $object->label;
  8.     }
  9.    
  10.     if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
  11.         $object->labels['singular_name'] = $object->labels['name'];
  12.     }
  13.     $nohier_vs_hier_defaults = array(
  14.         'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),
  15.         'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),
  16.         'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),
  17.         'add_new_item' => array( __('Add New Post'), __('Add New Page') ),
  18.         'edit_item' => array( __('Edit Post'), __('Edit Page') ),
  19.         'new_item' => array( __('New Post'), __('New Page') ),
  20.         'view_item' => array( __('View Post'), __('View Page') ),
  21.         'search_items' => array( __('Search '.(isset($object->labels['name'])?$object->labels['name']:'Posts')), __('Search '.(isset($object->labels['name'])?$object->labels['name']:'Pages')) ),
  22.         'not_found' => array( __('No posts found'), __('No pages found') ),
  23.         'not_found_in_trash' => array( __('No posts found in Trash'), __('No pages found in Trash') ),
  24.         'view' => array( __('View Post'), __('View Page') ),
  25.         'parent_item_colon' => array( null, __('Parent Page:') )
  26.     );
  27.     $defaults = array_map( create_function( '$x', $object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
  28.     $labels = array_merge( $defaults, $object->labels );
  29.     return (object)$labels;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement