[wp-trac] [WordPress Trac] #36634: `register_post_status()` default causes notices in post list table

WordPress Trac noreply at wordpress.org
Fri Apr 22 15:14:09 UTC 2016


#36634: `register_post_status()` default causes notices in post list table
-------------------------------+-----------------------------
 Reporter:  dlh                |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:
  Focuses:  administration     |
-------------------------------+-----------------------------
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36634>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list