Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#36634 new defect (bug)

`register_post_status()` default causes notices in post list table

Reported by: dlh's profile dlh Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: administration Cc:

Description

The default value for the $label_count parameter in register_post_status() is an "array of $label, twice." As far as I can see, $label_count is used only once in core: in WP_Posts_List_Table::get_views(), where it's passed to translate_nooped_plural().

However, translate_nooped_plural() assumes the array it receives was generated through _n_noop() or similar. So the default $label_count value leads to undefined-index notices for each of the expected array keys when viewing the list table.

To replicate, register a post status with these args, assign a post the 'test' status, and view the post list table:

add_action( 'init', function () {
    register_post_status( 'test', array( 'label' => 'Test', 'show_in_admin_status_list' => true ) );
} );

The attached patch would fix the notices by checking the $nooped_plural keys in translate_nooped_plural() and attempting to return a fallback value.

Also, even though $label_count is an optional argument, it looks to me like developers are expected to register it as the list table expects. So, the patch would add a _doing_it_wrong() call to register_post_status() when no $label_count is included. This does, however, also flag the auto-draft and inherit statuses.

Attachments (1)

36634.patch (1.4 KB) - added by dlh 8 years ago.

Download all attachments as: .zip

Change History (2)

@dlh
8 years ago

#1 @Phyrax
8 years ago

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.