WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#35842 new enhancement

Register Post Type function label default

Reported by: moshiezz Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: 2nd-opinion
Focuses: Cc:
PR Number:

Description

When registering a Post type if the label or labels arguments are not set the label takes on a default of 'Posts' and not the Post type's name.

It states in the documentation that the label takes on the name of the Post type passed in as the first argument.

I believe the fix is as simple as updating the defaults variable in wp-includes/post.php on line 1017 with the label argument set to the post_type variable.

<?php
        $defaults = array(
                'label'                => $post_type,
                'labels'               => array(),
                'description'          => '',
                'public'               => false,
                'hierarchical'         => false,
                'exclude_from_search'  => null,
                'publicly_queryable'   => null,
                'show_ui'              => null,
                'show_in_menu'         => null,
                'show_in_nav_menus'    => null,
                'show_in_admin_bar'    => null,
                'menu_position'        => null,
                'menu_icon'            => null,
                'capability_type'      => 'post',
                'capabilities'         => array(),
                'map_meta_cap'         => null,
                'supports'             => array(),
                'register_meta_box_cb' => null,
                'taxonomies'           => array(),
                'has_archive'          => false,
                'rewrite'              => true,
                'query_var'            => true,
                'can_export'           => true,
                'delete_with_user'     => null,
                '_builtin'             => false,
                '_edit_link'           => 'post.php?post=%d',
        );

Change History (2)

#1 @moshiezz
4 years ago

I have just noticed that the labels are all lowercase perhaps:

<?php
    ucfirst($post_type);
Last edited 4 years ago by moshiezz (previous) (diff)

#2 @dd32
4 years ago

  • Keywords 2nd-opinion added
  • Type changed from defect (bug) to enhancement
  • Version 4.4.2 deleted

It states in the documentation that the label takes on the name of the Post type passed in as the first argument.

This is a bug in the codex documentation, rather than something WordPress should support IMHO (due to translation requirements)

I've updated the Codex Community Documentation to reflect the official reference.
I've updated this ticket to reflect this as a enhancement request rather than a bug.

Note: See TracTickets for help on using tickets.