diff --git a/wp-admin/edit.php b/wp-admin/edit.php index dcc1b0b02..2bfc09d2a 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -137,8 +137,6 @@ if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delet exit; } -$title = sprintf(__('Edit %s'), $post_type_object->label); - wp_enqueue_script('inline-edit-post'); $user_posts = false; @@ -165,7 +163,7 @@ else
-

labels->edit_item ); ?> labels->add_new); ?> ' . __('Search results for “%s”') . '', get_search_query() ); ?>

@@ -262,9 +260,9 @@ endif; @@ -410,9 +408,9 @@ if ( $page_links )

label ); + echo $post_type_object->labels->not_found_in_trash; else - printf( __( 'No %s found.' ), $post_type_object->label ); + echo $post_type_object->labels->not_found; ?>

diff --git a/wp-admin/export.php b/wp-admin/export.php index c107497dd..acc8d7977 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -112,7 +112,7 @@ foreach ( (array) $authors as $author ) { diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 9e513717b..e96ef58c9 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -59,7 +59,7 @@ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { $original_title = $original_object->post_title; } ?> -
- @@ -374,7 +371,7 @@ function wp_nav_menu_post_type_meta_boxes() { $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); if ( $post_type ) { $id = $post_type->name; - add_meta_box( "add-{$id}", $post_type->label, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); + add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type ); } } } @@ -544,7 +541,7 @@ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { )); if ( !$posts ) - $error = '
  • '. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'
  • '; + $error = '
  • '. $post_type['args']->labels->not_found .'
  • '; $current_tab = 'all'; if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { @@ -865,7 +862,6 @@ function wp_save_nav_menu_item( $menu_id = 0, $menu_data = array() ) { 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), - 'menu-item-append' => ( isset( $_item_object_data['menu-item-append'] ) ? $_item_object_data['menu-item-append'] : '' ), 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index bf5ceb1cd..80765854f 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1079,14 +1079,8 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); if ( 'publish' == $post->post_status ) { - if ( 'post' == $post->post_type ) { - $view_post = __('View Post'); - } elseif ( 'page' == $post->post_type ) { - $view_post = __('View Page'); - } else { - $ptype = get_post_type_object($post->post_type); - $view_post = sprintf(__('View %s'), $ptype->singular_label); - } + $ptype = get_post_type_object($post->post_type); + $view_post = $ptype->labels->view_item; $title = __('Click to edit this part of the permalink'); } else { $title = __('Temporary permalink. Click to edit this part.'); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index cfcc48178..8a9190b72 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -13,9 +13,9 @@ * * @since 2.7 * - * Outputs the HTML for the hidden table rows used in Categories, Link Categories and Tags quick edit. + * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit. * - * @param string $type "edit-tags", "categories" or "edit-link-categories" + * @param string $type "edit-tags", "categoried" or "edit-link-categories" * @param string $taxonomy The taxonomy of the row. * @return */ @@ -1566,7 +1566,7 @@ foreach ( $posts_columns as $column_name => $column_display_name ) { $attributes = 'class="post-title page-title column-title"' . $style; $edit_link = get_edit_post_link( $page->ID ); ?> - >edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?> + >edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?>labels->parent . ' ' . esc_html($parent_name) : ''; ?> edit_cap, $page->ID) && $post->post_status != 'trash' ) { @@ -3328,10 +3328,10 @@ function favorite_actions( $screen = null ) { if ( isset($post_type_object) ) { switch ( $screen->id ) { case $post_type_object->name: - $default_action = array('edit.php?post_type=' . $post_type_object->name => array(sprintf(__('Edit %s'), $post_type_object->label), $post_type_object->edit_type_cap)); + $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->edit_type_cap)); break; case "edit-{$post_type_object->name}": - $default_action = array('post-new.php?post_type=' . $post_type_object->name => array(sprintf(__('New %s'), $post_type_object->singular_label), $post_type_object->edit_type_cap)); + $default_action = array('post-new.php?post_type=' . $post_type_object->name => array($post_type_object->labels->new_item, $post_type_object->edit_type_cap)); break; } } @@ -3746,7 +3746,7 @@ function screen_options($screen) { if ( isset($_GET['post_type']) && in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) ) $post_type = $_GET['post_type']; $post_type_object = get_post_type_object($post_type); - $per_page_label = $post_type_object->label; + $per_page_label = $post_type_object->labels->name; break; case 'ms-sites': $per_page_label = __('Sites'); diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js index 6fd34b723..c7f98d46e 100644 --- a/wp-admin/js/nav-menu.dev.js +++ b/wp-admin/js/nav-menu.dev.js @@ -809,7 +809,6 @@ var wpNavMenu; 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', - 'menu-item-append', 'menu-item-title', 'menu-item-url', 'menu-item-description', diff --git a/wp-admin/menu.php b/wp-admin/menu.php index 60e19c1bb..ef6a27044 100644 --- a/wp-admin/menu.php +++ b/wp-admin/menu.php @@ -129,10 +129,9 @@ foreach ( (array) get_post_types( array('show_ui' => true) ) as $ptype ) { while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) ) $ptype_menu_position++; - $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->label ), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-' . $ptype_class, $menu_icon ); - $submenu["edit.php?post_type=$ptype"][5] = array( __('Edit'), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype"); - /* translators: add new custom post type */ - $submenu["edit.php?post_type=$ptype"][10] = array( _x('Add New', 'post'), $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" ); + $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->name ), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-' . $ptype_class, $menu_icon ); + $submenu["edit.php?post_type=$ptype"][5] = array( $ptype_obj->labels->edit, $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype"); + $submenu["edit.php?post_type=$ptype"][10] = array( $ptype_obj->labels->add_new, $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" ); $i = 15; foreach ( $wp_taxonomies as $tax ) { diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index f1d04e8c3..d5f544319 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -299,7 +299,7 @@ switch ( $action ) { if ( ! is_wp_error( $_menu_object ) ) { $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); - $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-append', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); + $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); wp_defer_term_counting(true); // Loop through all the menu items' POST variables if ( ! empty( $_POST['menu-item-db-id'] ) ) { diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 7a84026aa..91619ccdf 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -26,7 +26,7 @@ if ( 'post' != $post_type ) { $post_type_object = get_post_type_object($post_type); -$title = sprintf(__('Add New %s'), $post_type_object->singular_label); +$title = $post_type_object->labels->add_new_item; $editing = true; diff --git a/wp-admin/post.php b/wp-admin/post.php index d9827e2ed..a8da2b26b 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -177,7 +177,7 @@ case 'edit': wp_enqueue_script('autosave'); } - $title = sprintf(__('Edit %s'), $post_type_object->singular_label); + $title = $post_type_object->labels->edit_item; $post = get_post_to_edit($post_id); if ( post_type_supports($post_type, 'comments') ) { diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index d4a6e6c6a..ee47a496c 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -155,10 +155,8 @@ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { $output .= ''; $output .= ''; $output .= ''; - $output .= ''; $output .= ''; $output .= ''; - $output .= ''; $output .= ''; $output .= ''; $output .= ''; diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 9725f7889..4b4a347ba 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -231,7 +231,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => 'custom', - 'menu-item-append' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', @@ -277,11 +276,7 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $original_title = $original_object->post_title; if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) { - $post_type_object = get_post_type_object( $args['menu-item-object'] ); - if ( isset( $post_type_object->singular_label ) ) - return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to a %2$s that is in the trash, so it cannot be updated.'), $args['menu-item-title'], $post_type_object->singular_label ) ); - else - return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to something that is in the trash, so it cannot be updated.'), $args['menu-item-title'] ) ); + return new WP_Error('update_nav_menu_item_failed', sprintf(__('The menu item "%1$s" belongs to something that is in the trash, so it cannot be updated.'), $args['menu-item-title'] ) ); } } @@ -485,7 +480,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) { * - object_id: The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories. * - type: The family of objects originally represented, such as "post_type" or "taxonomy." * - object: The type of object originally represented, such as "category," "post", or "attachment." - * - append: The singular label used to describe this type of menu item. + * - type_label: The singular label used to describe this type of menu item. * - post_parent: The DB ID of the original object's parent object, if any (0 otherwise). * - menu_item_parent: The DB ID of the nav_menu_item that is this item's menu parent, if any. 0 otherwise. * - url: The URL to which this menu item points. @@ -512,7 +507,7 @@ function wp_setup_nav_menu_item( $menu_item ) { if ( 'post_type' == $menu_item->type ) { $object = get_post_type_object( $menu_item->object ); - $menu_item->append = $object->singular_label; + $menu_item->type_label = $object->labels->singular_name; $menu_item->url = get_permalink( $menu_item->object_id ); $original_object = get_post( $menu_item->object_id ); @@ -521,14 +516,14 @@ function wp_setup_nav_menu_item( $menu_item ) { } elseif ( 'taxonomy' == $menu_item->type ) { $object = get_taxonomy( $menu_item->object ); - $menu_item->append = $object->singular_label; + $menu_item->type_label = $object->singular_label; $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object ); $original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' ); $menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title; } else { - $menu_item->append = __('Custom'); + $menu_item->type_label = __('Custom'); $menu_item->title = $menu_item->post_title; $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); } @@ -548,7 +543,7 @@ function wp_setup_nav_menu_item( $menu_item ) { $object = get_post_type_object( $menu_item->post_type ); $menu_item->object = $object->name; - $menu_item->append = strtolower( $object->singular_label ); + $menu_item->type_label = $object->labels->singular_name; $menu_item->title = $menu_item->post_title; $menu_item->url = get_permalink( $menu_item->ID ); @@ -569,7 +564,7 @@ function wp_setup_nav_menu_item( $menu_item ) { $object = get_taxonomy( $menu_item->taxonomy ); $menu_item->object = $object->name; - $menu_item->append = strtolower( $object->singular_label ); + $menu_item->type_label = $object->singular_label; $menu_item->title = $menu_item->name; $menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy ); diff --git a/wp-includes/post.php b/wp-includes/post.php index d69e0fb4e..f2e66fc4c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -16,8 +16,6 @@ */ function create_initial_post_types() { register_post_type( 'post', array( - 'label' => __( 'Posts' ), - 'singular_label' => __( 'Post' ), 'public' => true, 'show_ui' => false, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ @@ -30,8 +28,6 @@ function create_initial_post_types() { ) ); register_post_type( 'page', array( - 'label' => __( 'Pages' ), - 'singular_label' => __( 'Page' ), 'public' => true, 'show_ui' => false, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ @@ -769,35 +765,33 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) * * Optional $args contents: * - * label - A (plural) descriptive name for the post type marked for translation. Defaults to $post_type. - * singular_label - A (singular) descriptive name for the post type marked for translation. Defaults to $label. - * description - A short descriptive summary of what the post type is. Defaults to blank. - * public - Whether posts of this type should be shown in the admin UI. Defaults to false. - * exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public. - * publicly_queryable - Whether post_type queries can be performed from the front page. Defaults to whatever public is set as. - * show_ui - Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public. - * menu_position - The position in the menu order the post type should appear. Defaults to the bottom. - * menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon. - * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. - * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". - * edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post). - * edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts). - * edit_others_cap - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s" (edit_others_posts). - * publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts). - * read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post). - * delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post). - * hierarchical - Whether the post type is hierarchical. Defaults to false. - * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none. - * register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback. - * taxonomies - An array of taxonomy identifiers that will be registered for the post type. Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type(). - * - * @package WordPress - * @subpackage Post + * - description - A short descriptive summary of what the post type is. Defaults to blank. + * - public - Whether posts of this type should be shown in the admin UI. Defaults to false. + * - exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public. + * - publicly_queryable - Whether post_type queries can be performed from the front page. Defaults to whatever public is set as. + * - show_ui - Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public. + * - menu_position - The position in the menu order the post type should appear. Defaults to the bottom. + * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon. + * - inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none. + * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post". + * - edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post). + * - edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts). + * - edit_others_cap - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s" (edit_others_posts). + * - publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts). + * - read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post). + * - delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post). + * - hierarchical - Whether the post type is hierarchical. Defaults to false. + * - supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none. + * - register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback. + * - taxonomies - An array of taxonomy identifiers that will be registered for the post type. Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type(). + * - labels - An array of labels for this post type. You can see accepted values in {@link get_post_type_labels()}. By default post labels are used for non-hierarchical types and page labels for hierarchical ones. + * * @since 2.9.0 * @uses $wp_post_types Inserts new post type object into the list * * @param string $post_type Name of the post type. * @param array|string $args See above description. + * @return object the registered post type object */ function register_post_type($post_type, $args = array()) { global $wp_post_types, $wp_rewrite, $wp; @@ -806,7 +800,13 @@ function register_post_type($post_type, $args = array()) { $wp_post_types = array(); // Args prefixed with an underscore are reserved for internal use. - $defaults = array('label' => false, 'singular_label' => false, 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 'permalink_epmask' => EP_PERMALINK, 'can_export' => true ); + $defaults = array( + 'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null, + '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, + 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null, + 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, + 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, + ); $args = wp_parse_args($args, $defaults); $args = (object) $args; @@ -825,12 +825,6 @@ function register_post_type($post_type, $args = array()) { if ( null === $args->exclude_from_search ) $args->exclude_from_search = !$args->public; - if ( false === $args->label ) - $args->label = $post_type; - - if ( false === $args->singular_label ) - $args->singular_label = $args->label; - if ( empty($args->capability_type) ) $args->capability_type = 'post'; if ( empty($args->edit_cap) ) @@ -880,6 +874,13 @@ function register_post_type($post_type, $args = array()) { if ( $args->register_meta_box_cb ) add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1); + $args->labels = get_post_type_labels( $args ); + + // we keep these two only for backwards compatibility + // TODO: remove in 3.1 + $args->label = $args->labels->name; + $args->singular_label = $args->labels->singular_name; + $wp_post_types[$post_type] = $args; add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 ); @@ -891,6 +892,61 @@ function register_post_type($post_type, $args = array()) { return $args; } +/** + * Builds an object with all post type labels out of a post type object + * + * Accepted keys of the label array in the post type object: + * - name - general name for the post type, usually plural. 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 {@link http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context gettext context} matching your post type. Example: _x('Add New', 'product'); + * - add_new_item - Default is Add New Post/Add New Page + * - edit_item - Default is Edit Post/Edit Page + * - edit - Default is Edit. When internationalizing this string, please use a {@link http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context gettext context} matching your post type. Example: _x('Edit', 'product'); + * - new_item - Default is New Post/New Page + * - view_item - Default is View Post/View Page + * - search_items - Default is Search Posts/Search Pages + * - not_found - Default is No posts found/No pages found + * - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash + * - parent - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page: + * + * Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages.) + * + * @since 3.0.0 + * @param object $post_type_object + * @return object object with all the labels as member variables + */ +function get_post_type_labels( $post_type_object ) { + $nohier_vs_hier_defaults = array( + 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ), + 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ), + 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ), + 'add_new_item' => array( __('Add New Post'), __('Add New Page') ), + 'edit_item' => array( __('Edit Post'), __('Edit Page') ), + 'edit' => array( _x('Edit', 'post'), _x('Edit', 'page') ), + 'new_item' => array( __('New Post'), __('New Page') ), + 'view_item' => array( __('View Post'), __('View Page') ), + 'search_items' => array( __('Search Posts'), __('Search Pages') ), + 'not_found' => array( __('No posts found'), __('No pages found') ), + 'not_found_in_trash' => array( __('No posts found in Trash'), __('No pages found in Trash') ), + 'view' => array( __('View Post'), __('View Page') ), + 'parent' => array( null, __('Parent Page:') ) + ); + + // try to get missing (singular_)?name from older style (singular_)?label member variables + // we keep that for backwards compatibility + // TODO: remove in 3.1 + if ( !isset( $post_type_object->labels['name'] ) && isset( $post_type_object->label ) ) { + $post_type_object->labels['name'] = $post_type_object->label; + } + if ( !isset( $post_type_object->labels['singular_name'] ) && isset( $post_type_object->singular_label ) ) { + $post_type_object->labels['singular_name'] = $post_type_object->singular_label; + } + + $defaults = array_map( create_function( '$x', $post_type_object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults ); + $labels = array_merge( $defaults, $post_type_object->labels ); + return (object)$labels; +} + /** * Register support of certain features for a post type. *