Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#38686 closed defect (bug) (fixed)

Incorrect fallback value for label_count when registering a custom post status

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: good-first-bug has-patch has-unit-tests
Focuses: administration Cc:


When registering a custom post status, the label_count argument falls back to an array of the label names if it's not provided. This is incorrect and causes PHP notices on the post listing screen because the post status label expects a nooped plural. It should fallback to calling _n_noop().

Example code:

register_post_status( 'foo', [
	'label'                     => 'Foo',
	'show_in_admin_status_list' => true,
] );

PHP notices:

Undefined index: domain wp-includes/l10n.php:514
Undefined index: context wp-includes/l10n.php:517
Undefined index: singular wp-includes/l10n.php:520
Undefined index: plural wp-includes/l10n.php:520

Attachments (2)

38686.diff (477 bytes) - added by xrmx 8 years ago.
use _n_noop() on fallback
38686.2.diff (1.4 KB) - added by xrmx 8 years ago.
patch with failing tests

Download all attachments as: .zip

Change History (8)

8 years ago

use _n_noop() on fallback

#1 @xrmx
8 years ago

  • Keywords has-patch added; needs-patch removed

With the attached patch i cannot reproduce the issue anymore.

8 years ago

patch with failing tests

#2 @xrmx
8 years ago

The test is failing with this error, any hint would be helpful:

1) Tests_Admin_includesListTable::test_label_count_fallback_no_notices
Undefined property: stdClass::$trash


Tests: 10, Assertions: 26, Errors: 1.

#3 @johnbillion
7 years ago

#39412 was marked as a duplicate.

#4 @johnbillion
7 years ago

  • Milestone changed from Awaiting Review to 4.8

#5 @ocean90
7 years ago

  • Keywords has-unit-tests added

Technically, _n_noop() would be used incorrectly here because only literal strings should be passed to gettext functions, as noted by @dd32 in #39412, but in this case it should be fine. We do this already in wp_generate_tag_cloud() as a fallback "for the old-style single_text and multiple_text arguments.".

#6 @johnbillion
7 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 40516:

Posts, Post Types: Correct the fallback value for the label_count argument of register_post_status().

While using _n_noop() here is technically incorrect, it does correct the fallback value as its usage in translate_nooped_plural() expects a correctly formatted associative array.

Props xrmx

Fixes #38686

Note: See TracTickets for help on using tickets.