Opened 8 years ago
Closed 8 years ago
#38686 closed defect (bug) (fixed)
Incorrect fallback value for label_count when registering a custom post status
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | good-first-bug has-patch has-unit-tests |
Focuses: | administration | Cc: |
Description
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)
Change History (8)
#1
@
8 years ago
- Keywords has-patch added; needs-patch removed
With the attached patch i cannot reproduce the issue anymore.
#2
@
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
/srv/www/wordpress-develop/src/wp-admin/includes/class-wp-posts-list-table.php:283
/srv/www/wordpress-develop/src/wp-admin/includes/class-wp-list-table.php:240
/srv/www/wordpress-develop/tests/phpunit/tests/admin/includesListTable.php:259
ERRORS!
Tests: 10, Assertions: 26, Errors: 1.
#5
@
8 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.".
use _n_noop() on fallback