[wp-trac] [WordPress Trac] #20005: Use single and plural Label arguments to populate defaults for Labels in register_post_type

WordPress Trac wp-trac at lists.automattic.com
Sat Feb 11 03:38:19 UTC 2012


#20005: Use single and plural Label arguments to populate defaults for Labels in
register_post_type
-------------------------+-----------------------
 Reporter:  ericlewis    |       Owner:
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:
Component:  Post Types   |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  close        |
-------------------------+-----------------------
Changes (by ericlewis):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 Sorry if I'm being daft or unclear, but I'm referring to the use of "post"
 and "page" throughout the get_post_type_labels() function in
 post.php:1182.

 I'm wondering about the utility of the defaults here, other than to fill
 defaults for the "post" and "page" post types. I'm suggesting the
 arguments for the internationalization strings could be auto-populated.
 Wouldn't this still allow for internationalization of each label string?


 {{{
 function get_post_type_labels( $post_type_object ) {
         $nohier_singular = $post_type_object->labels['singular_name'] ?
 $post_type_object->labels['singular_name'] : "Post";
         $nohier_plural = $post_type_object->labels['name'] ?
 $post_type_object->labels['name'] : "Posts";
         $hier_singular = $post_type_object->labels['singular_name'] ?
 $post_type_object->labels['singular_name'] : "Page";
         $hier_plural = $post_type_object->labels['name'] ?
 $post_type_object->labels['name'] : "Pages";

         $nohier_vs_hier_defaults = array(
                 'name' => array( _x( $nohier_plural, 'post type general
 name'), _x($hier_plural, 'post type general name') ),
                 'singular_name' => array( _x( $nohier_singular, 'post type
 singular name'), _x($hier_singular, 'post type singular name') ),
                 'add_new' => array( _x('Add New', 'post'), _x('Add New',
 'page') ),
                 'add_new_item' => array( __('Add New ' . $nohier_singular
 ), __('Add New ' . $hier_singular) ),
                 'edit_item' => array( __('Edit ' . $nohier_singular),
 __('Edit ' . $hier_singular ) ),
                 'new_item' => array( __('New ' . $nohier_singular),
 __('New ' . $hier_singular ) ),
                 'view_item' => array( __('View ' . $nohier_singular),
 __('View ' . $hier_singular ) ),
                 'search_items' => array( __('Search ' . $nohier_plural ),
 __('Search ' . $hier_plural ) ),
                 'not_found' => array( __('No ' .
 strtolower($nohier_plural) . ' found.'), __('No ' .
 strtolower($hier_plural) . ' found.') ),
                 'not_found_in_trash' => array( __('No ' .
 strtolower($nohier_plural) . ' found in Trash.'), __('No ' .
 strtolower($hier_plural) . ' found in Trash.') ),
                 'parent_item_colon' => array( null, __('Parent ' .
 $hier_singular . ':') ),
                 'all_items' => array( __( 'All ' . $nohier_plural ), __(
 'All ' . $hier_plural ) )
         );
         $nohier_vs_hier_defaults['menu_name'] =
 $nohier_vs_hier_defaults['name'];
         return _get_custom_object_labels( $post_type_object,
 $nohier_vs_hier_defaults );
 }
 }}}

 So that registering a new post type would require a lot less code to get
 good labels throughout the admin section:

 {{{
 register_post_type(
         "bug-report",
         array( "labels" =>
                 array(
                         "name" => "Bug Reports",
                         "plural" => "Bug Report"
                 )
         )
 );
 }}}

 Sorry if I'm missing something.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20005#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list