Make WordPress Core

Changeset 14571


Ignore:
Timestamp:
05/11/2010 07:52:50 PM (14 years ago)
Author:
nbachiyski
Message:

I18n for custom post type labels. Props demetris, dimadin. Fixes #12968

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit.php

    r14374 r14571  
    138138}
    139139
    140 $title = sprintf(__('Edit %s'), $post_type_object->label);
    141 
    142140wp_enqueue_script('inline-edit-post');
    143141
     
    166164<div class="wrap">
    167165<?php screen_icon(); ?>
    168 <h2><?php echo esc_html( $title ); ?> <a href="<?php echo $post_new_file ?>" class="button add-new-h2"><?php echo esc_html_x('Add New', 'post'); ?></a> <?php
     166<h2><?php echo esc_html( $post_type_object->labels->edit_item ); ?> <a href="<?php echo $post_new_file ?>" class="button add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a> <?php
    169167if ( isset($_GET['s']) && $_GET['s'] )
    170168    printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() ); ?>
     
    263261
    264262<p class="search-box">
    265     <label class="screen-reader-text" for="post-search-input"><?php printf( _x('Search %s', '%s: post type name'), $post_type_object->label ); ?>:</label>
     263    <label class="screen-reader-text" for="post-search-input"><?php echo $post_type_object->labels->search_items; ?>:</label>
    266264    <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
    267     <input type="submit" value="<?php echo esc_attr( sprintf( _x('Search %s', '%s: post type name'), $post_type_object->label ) ); ?>" class="button" />
     265    <input type="submit" value="<?php echo esc_attr( $post_type_object->labels->search_items ); ?>" class="button" />
    268266</p>
    269267
     
    411409<p><?php
    412410if ( isset($_GET['post_status']) && 'trash' == $_GET['post_status'] )
    413     printf( __( 'No %s found in the Trash.' ), $post_type_object->label );
     411    echo $post_type_object->labels->not_found_in_trash;
    414412else
    415     printf( __( 'No %s found.' ), $post_type_object->label );
     413    echo $post_type_object->labels->not_found;
    416414?></p>
    417415<?php } ?>
  • trunk/wp-admin/export.php

    r14509 r14571  
    113113    <option value="all" selected="selected"><?php _e('All Content'); ?></option>
    114114    <?php foreach ( get_post_types( array( 'public' => true, 'can_export' => true ), 'objects' ) as $post_type_obj ) { ?>
    115         <option value="<?php echo $post_type_obj->name; ?>"><?php echo $post_type_obj->label; ?></option>
     115        <option value="<?php echo $post_type_obj->name; ?>"><?php echo $post_type_obj->labels->name; ?></option>
    116116    <?php } ?>
    117117</select>
  • trunk/wp-admin/includes/nav-menu.php

    r14569 r14571  
    6060        }
    6161        ?>
    62         <li id="menu-item-<?php echo $item_id; ?>" class="menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo strtolower(esc_attr( $item->append )); ?>">
     62        <li id="menu-item-<?php echo $item_id; ?>" class="menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo esc_attr( $item->object ); ?>">
    6363            <dl class="menu-item-bar <?php
    6464                if ( isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] )
     
    7070                    <span class="item-title"><?php echo esc_html( $item->title ); ?></span>
    7171                    <span class="item-controls">
    72                         <span class="item-type"><?php echo esc_html( $item->append ); ?></span>
     72                        <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
    7373                        <span class="item-order">
    7474                            <a href="<?php
     
    162162                <div class="menu-item-actions description-wide submitbox">
    163163                    <?php if( 'custom' != $item->type ) : ?>
    164                         <p class="link-to-original"><?php
    165                             _e('Original ');
    166                             echo esc_html( $item->append );
    167                             echo ":"; ?>
     164                        <p class="link-to-original">
     165                            <?php _e('Original:'); ?>
    168166                            <a href="<?php echo esc_attr( $item->url ); ?>">
    169167                                <?php echo esc_html($original_title); ?>
     
    185183                </div>
    186184
    187                 <input class="menu-item-data-append" type="hidden" name="menu-item-append[<?php echo $item_id; ?>]" value="<?php echo $item->append; ?>" />
    188185                <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" />
    189186                <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
     
    375372        if ( $post_type ) {
    376373            $id = $post_type->name;
    377             add_meta_box( "add-{$id}", $post_type->label, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
     374            add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
    378375        }
    379376    }
     
    545542
    546543    if ( !$posts )
    547         $error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>';
     544        $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>';
    548545
    549546    $current_tab = 'all';
     
    866863                'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ),
    867864                'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ),
    868                 'menu-item-append' => ( isset( $_item_object_data['menu-item-append'] ) ? $_item_object_data['menu-item-append'] : '' ),
    869865                'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ),
    870866                'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ),
  • trunk/wp-admin/includes/post.php

    r14551 r14571  
    10801080
    10811081    if ( 'publish' == $post->post_status ) {
    1082         if ( 'post' == $post->post_type ) {
    1083             $view_post = __('View Post');
    1084         } elseif ( 'page' == $post->post_type ) {
    1085             $view_post = __('View Page');
    1086         } else {
    1087             $ptype = get_post_type_object($post->post_type);
    1088             $view_post = sprintf(__('View %s'), $ptype->singular_label);
    1089         }
     1082        $ptype = get_post_type_object($post->post_type);
     1083        $view_post = $ptype->labels->view_item;
    10901084        $title = __('Click to edit this part of the permalink');
    10911085    } else {
  • trunk/wp-admin/includes/template.php

    r14524 r14571  
    1414 * @since 2.7
    1515 *
    16  * Outputs the HTML for the hidden table rows used in Categories, Link Categories and Tags quick edit.
    17  *
    18  * @param string $type "edit-tags", "categories" or "edit-link-categories"
     16 * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit.
     17 *
     18 * @param string $type "edit-tags", "categoried" or "edit-link-categories"
    1919 * @param string $taxonomy The taxonomy of the row.
    2020 * @return
     
    15671567        $edit_link = get_edit_post_link( $page->ID );
    15681568        ?>
    1569         <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
     1569        <td <?php echo $attributes ?>><strong><?php if ( current_user_can($post_type_object->edit_cap, $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . $post_type_object->labels->parent . ' ' . esc_html($parent_name) : ''; ?></strong>
    15701570        <?php
    15711571        $actions = array();
     
    33293329        switch ( $screen->id ) {
    33303330            case $post_type_object->name:
    3331                 $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));
     3331                $default_action = array('edit.php?post_type=' . $post_type_object->name => array($post_type_object->labels->edit_item, $post_type_object->edit_type_cap));
    33323332                break;
    33333333            case "edit-{$post_type_object->name}":
    3334                 $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));
     3334                $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));
    33353335                break;
    33363336        }
     
    37473747                $post_type = $_GET['post_type'];
    37483748            $post_type_object = get_post_type_object($post_type);
    3749             $per_page_label = $post_type_object->label;
     3749            $per_page_label = $post_type_object->labels->name;
    37503750            break;
    37513751        case 'ms-sites':
  • trunk/wp-admin/js/nav-menu.dev.js

    r14531 r14571  
    810810                'menu-item-position',
    811811                'menu-item-type',
    812                 'menu-item-append',
    813812                'menu-item-title',
    814813                'menu-item-url',
  • trunk/wp-admin/menu.php

    r14299 r14571  
    130130        $ptype_menu_position++;
    131131
    132     $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 );
    133     $submenu["edit.php?post_type=$ptype"][5]  = array( __('Edit'), $ptype_obj->edit_type_cap,  "edit.php?post_type=$ptype");
    134     /* translators: add new custom post type */
    135     $submenu["edit.php?post_type=$ptype"][10]  = array( _x('Add New', 'post'), $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" );
     132    $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 );
     133    $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->edit, $ptype_obj->edit_type_cap,  "edit.php?post_type=$ptype");
     134    $submenu["edit.php?post_type=$ptype"][10]  = array( $ptype_obj->labels->add_new, $ptype_obj->edit_type_cap, "post-new.php?post_type=$ptype" );
    136135
    137136    $i = 15;
  • trunk/wp-admin/nav-menus.php

    r14562 r14571  
    300300            if ( ! is_wp_error( $_menu_object ) ) {
    301301                $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
    302                 $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' );
     302                $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' );
    303303                wp_defer_term_counting(true);
    304304                // Loop through all the menu items' POST variables
  • trunk/wp-admin/post-new.php

    r14107 r14571  
    2727$post_type_object = get_post_type_object($post_type);
    2828
    29 $title = sprintf(__('Add New %s'), $post_type_object->singular_label);
     29$title = $post_type_object->labels->add_new_item;
    3030
    3131$editing = true;
  • trunk/wp-admin/post.php

    r14167 r14571  
    178178    }
    179179
    180     $title = sprintf(__('Edit %s'), $post_type_object->singular_label);
     180    $title = $post_type_object->labels->edit_item;
    181181    $post = get_post_to_edit($post_id);
    182182
  • trunk/wp-includes/nav-menu-template.php

    r14559 r14571  
    156156        $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />';
    157157        $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
    158         $output .= '<input type="hidden" class="menu-item-append" name="menu-item[' . $possible_object_id . '][menu-item-append]" value="'. esc_attr( $item->append ) .'" />';
    159158        $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
    160159        $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
    161         $output .= '<input type="hidden" class="menu-item-append" name="menu-item[' . $possible_object_id . '][menu-item-append]" value="'. esc_attr( $item->append ) .'" />';
    162160        $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
    163161        $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
  • trunk/wp-includes/nav-menu.php

    r14560 r14571  
    232232        'menu-item-position' => 0,
    233233        'menu-item-type' => 'custom',
    234         'menu-item-append' => 'custom',
    235234        'menu-item-title' => '',
    236235        'menu-item-url' => '',
     
    278277
    279278            if ( 'trash' == get_post_status( $args['menu-item-object-id'] ) ) {
    280                 $post_type_object = get_post_type_object( $args['menu-item-object'] );
    281                 if ( isset( $post_type_object->singular_label ) )
    282                     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 ) );
    283                 else
    284                     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'] ) );
     279                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'] ) );
    285280            }
    286281        }
     
    486481 * - type:      The family of objects originally represented, such as "post_type" or "taxonomy."
    487482 * - object:        The type of object originally represented, such as "category," "post", or "attachment."
    488  * - append:        The singular label used to describe this type of menu item.
     483 * - type_label:    The singular label used to describe this type of menu item.
    489484 * - post_parent:   The DB ID of the original object's parent object, if any (0 otherwise).
    490485 * - menu_item_parent:  The DB ID of the nav_menu_item that is this item's menu parent, if any.  0 otherwise.
     
    513508            if ( 'post_type' == $menu_item->type ) {
    514509                $object = get_post_type_object( $menu_item->object );
    515                 $menu_item->append = $object->singular_label;
     510                $menu_item->type_label = $object->labels->singular_name;
    516511                $menu_item->url = get_permalink( $menu_item->object_id );
    517512
     
    522517            } elseif ( 'taxonomy' == $menu_item->type ) {
    523518                $object = get_taxonomy( $menu_item->object );
    524                 $menu_item->append = $object->singular_label;
     519                $menu_item->type_label = $object->singular_label;
    525520                $menu_item->url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
    526521
     
    529524
    530525            } else {
    531                 $menu_item->append = __('Custom');
     526                $menu_item->type_label = __('Custom');
    532527                $menu_item->title = $menu_item->post_title;
    533528                $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
     
    549544            $object = get_post_type_object( $menu_item->post_type );
    550545            $menu_item->object = $object->name;
    551             $menu_item->append = strtolower( $object->singular_label );
     546            $menu_item->type_label = $object->labels->singular_name;
    552547
    553548            $menu_item->title = $menu_item->post_title;
     
    570565        $object = get_taxonomy( $menu_item->taxonomy );
    571566        $menu_item->object = $object->name;
    572         $menu_item->append = strtolower( $object->singular_label );
     567        $menu_item->type_label = $object->singular_label;
    573568
    574569        $menu_item->title = $menu_item->name;
  • trunk/wp-includes/post.php

    r14561 r14571  
    1717function create_initial_post_types() {
    1818    register_post_type( 'post', array(
    19         'label' => __( 'Posts' ),
    20         'singular_label' => __( 'Post' ),
    2119        'public'  => true,
    2220        'show_ui' => false,
     
    3129
    3230    register_post_type( 'page', array(
    33         'label' => __( 'Pages' ),
    34         'singular_label' => __( 'Page' ),
    3531        'public' => true,
    3632        'show_ui' => false,
     
    770766 * Optional $args contents:
    771767 *
    772  * label - A (plural) descriptive name for the post type marked for translation. Defaults to $post_type.
    773  * singular_label - A (singular) descriptive name for the post type marked for translation. Defaults to $label.
    774  * description - A short descriptive summary of what the post type is. Defaults to blank.
    775  * public - Whether posts of this type should be shown in the admin UI. Defaults to false.
    776  * 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.
    777  * publicly_queryable - Whether post_type queries can be performed from the front page.  Defaults to whatever public is set as.
    778  * 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.
    779  * menu_position - The position in the menu order the post type should appear. Defaults to the bottom.
    780  * menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
    781  * inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none.
    782  * capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
    783  * edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post).
    784  * edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts).
    785  * 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).
    786  * publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts).
    787  * read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post).
    788  * delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post).
    789  * hierarchical - Whether the post type is hierarchical. Defaults to false.
    790  * supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
    791  * 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.
    792  * 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().
    793  *
    794  * @package WordPress
    795  * @subpackage Post
     768 * - description - A short descriptive summary of what the post type is. Defaults to blank.
     769 * - public - Whether posts of this type should be shown in the admin UI. Defaults to false.
     770 * - 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.
     771 * - publicly_queryable - Whether post_type queries can be performed from the front page.  Defaults to whatever public is set as.
     772 * - 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.
     773 * - menu_position - The position in the menu order the post type should appear. Defaults to the bottom.
     774 * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
     775 * - inherit_type - The post type from which to inherit the edit link and capability type. Defaults to none.
     776 * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
     777 * - edit_cap - The capability that controls editing a particular object of this post type. Defaults to "edit_$capability_type" (edit_post).
     778 * - edit_type_cap - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts).
     779 * - 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).
     780 * - publish_others_cap - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts).
     781 * - read_cap - The capability that controls reading a particular object of this post type. Defaults to "read_$capability_type" (read_post).
     782 * - delete_cap - The capability that controls deleting a particular object of this post type. Defaults to "delete_$capability_type" (delete_post).
     783 * - hierarchical - Whether the post type is hierarchical. Defaults to false.
     784 * - supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
     785 * - 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.
     786 * - 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().
     787 * - 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.
     788 *
    796789 * @since 2.9.0
    797790 * @uses $wp_post_types Inserts new post type object into the list
     
    799792 * @param string $post_type Name of the post type.
    800793 * @param array|string $args See above description.
     794 * @return object the registered post type object
    801795 */
    802796function register_post_type($post_type, $args = array()) {
     
    807801
    808802    // Args prefixed with an underscore are reserved for internal use.
    809     $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 );
     803    $defaults = array(
     804        'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
     805        '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false,
     806        'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null,
     807        'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
     808        'permalink_epmask' => EP_PERMALINK, 'can_export' => true,
     809    );
    810810    $args = wp_parse_args($args, $defaults);
    811811    $args = (object) $args;
     
    825825    if ( null === $args->exclude_from_search )
    826826        $args->exclude_from_search = !$args->public;
    827 
    828     if ( false === $args->label )
    829         $args->label = $post_type;
    830 
    831     if ( false === $args->singular_label )
    832         $args->singular_label = $args->label;
    833827
    834828    if ( empty($args->capability_type) )
     
    881875        add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
    882876
     877    $args->labels = get_post_type_labels( $args );
     878   
     879    // we keep these two only for backwards compatibility
     880    // TODO: remove in 3.1 
     881    $args->label = $args->labels->name;
     882    $args->singular_label = $args->labels->singular_name;
     883
    883884    $wp_post_types[$post_type] = $args;
    884885
     
    890891
    891892    return $args;
     893}
     894
     895/**
     896 * Builds an object with all post type labels out of a post type object
     897 *
     898 * Accepted keys of the label array in the post type object:
     899 * - name - general name for the post type, usually plural. Default is Posts/Pages
     900 * - singular_name - name for one object of this post type. Default is Post/Page
     901 * - 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: <code>_x('Add New', 'product');</code>
     902 * - add_new_item - Default is Add New Post/Add New Page
     903 * - edit_item - Default is Edit Post/Edit Page
     904 * - 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: <code>_x('Edit', 'product');</code>
     905 * - new_item - Default is New Post/New Page
     906 * - view_item - Default is View Post/View Page
     907 * - search_items - Default is Search Posts/Search Pages
     908 * - not_found - Default is No posts found/No pages found
     909 * - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash
     910 * - parent - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
     911 *
     912 * Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages.)
     913 *
     914 * @since 3.0.0
     915 * @param object $post_type_object
     916 * @return object object with all the labels as member variables
     917 */
     918function get_post_type_labels( $post_type_object ) {
     919    $nohier_vs_hier_defaults = array(
     920        'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),
     921        'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),
     922        'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),
     923        'add_new_item' => array( __('Add New Post'), __('Add New Page') ),
     924        'edit_item' => array( __('Edit Post'), __('Edit Page') ),
     925        'edit' => array( _x('Edit', 'post'), _x('Edit', 'page') ),
     926        'new_item' => array( __('New Post'), __('New Page') ),
     927        'view_item' => array( __('View Post'), __('View Page') ),
     928        'search_items' => array( __('Search Posts'), __('Search Pages') ),
     929        'not_found' => array( __('No posts found'), __('No pages found') ),
     930        'not_found_in_trash' => array( __('No posts found in Trash'), __('No pages found in Trash') ),
     931        'view' => array( __('View Post'), __('View Page') ),
     932        'parent' => array( null, __('Parent Page:') )
     933    );
     934   
     935    // try to get missing (singular_)?name from older style (singular_)?label member variables
     936    // we keep that for backwards compatibility
     937    // TODO: remove in 3.1
     938    if ( !isset( $post_type_object->labels['name'] ) && isset( $post_type_object->label ) ) {
     939        $post_type_object->labels['name'] = $post_type_object->label;
     940    }
     941    if ( !isset( $post_type_object->labels['singular_name'] ) && isset( $post_type_object->singular_label ) ) {
     942        $post_type_object->labels['singular_name'] = $post_type_object->singular_label;
     943    }
     944   
     945    $defaults = array_map( create_function( '$x', $post_type_object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
     946    $labels = array_merge( $defaults, $post_type_object->labels );
     947    return (object)$labels;
    892948}
    893949
Note: See TracChangeset for help on using the changeset viewer.