[wp-trac] [WordPress Trac] #48599: Warning: count(): Parameter must be an array or an object that implements Countable in ../wp-admin/includes/plugin.php on line 1392

WordPress Trac noreply at wordpress.org
Thu Nov 14 23:03:34 UTC 2019


#48599: Warning: count(): Parameter must be an array or an object that implements
Countable in ../wp-admin/includes/plugin.php on line 1392
-------------------------------------------------+-------------------------
 Reporter:  ispreview                            |       Owner:
                                                 |  adamsilverstein
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  5.3.1
Component:  Administration                       |     Version:  5.3
 Severity:  normal                               |  Resolution:
 Keywords:  dev-feedback has-patch needs-        |     Focuses:  ui
  testing                                        |
-------------------------------------------------+-------------------------
Changes (by garrett-eclipse):

 * keywords:  needs-patch dev-feedback => dev-feedback has-patch needs-
               testing


Comment:

 Hi @adamsilverstein & @NextScripts

 Taking a quick glance I found the issue was less to do with the 7th
 `$position` parameter of the `add_submenu_page` but more that the same
 slug `testPlg` was used as both the `$parent_slug` and `$menu_slug` which
 caused `$submenu[ $parent_slug ]` to not be set leaving it undefined and
 as such non-countable.

 Speaking specifically about this code;
 `if ( ! isset( $submenu[ $parent_slug ] ) && $menu_slug != $parent_slug )
 {`
 Reference - https://github.com/WordPress/WordPress/blob/master/wp-
 admin/includes/plugin.php#L1363-L1375

 Two workarounds;
 1. Having the `$parent_slug` and `$menu_slug` for the `add_submenu_page`
 as unique avoids `$submenu[ $parent_slug ]` being undefined.
 2. Not providing the `$position` on the `add_submenu_page` call also
 avoids this as it avoids the reordering code where count is called here -
 https://github.com/WordPress/WordPress/blob/master/wp-
 admin/includes/plugin.php#L1393-L1412

 I've added
 [https://core.trac.wordpress.org/attachment/ticket/48599/48599.1.diff] to
 test this theory but would love someone with more experience with menus to
 review.

 Thanks

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48599#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list