[wp-trac] [WordPress Trac] #49089: hook_suffix is undefined in WP_Screen class

WordPress Trac noreply at wordpress.org
Mon Jul 12 05:15:30 UTC 2021


#49089: hook_suffix is undefined in WP_Screen class
----------------------------+------------------------------
 Reporter:  splendorstudio  |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:  5.3.1
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:
----------------------------+------------------------------

Comment (by htdat):

 When working on plugin Edit Flow, we came across this error
 https://github.com/Automattic/Edit-Flow/issues/654

 Here is what we've got so far:

 == To replicate this issue with core

 - Add this file under wp-content/mu-plugins or wp-content/plugins
 https://gist.github.com/htdat/06d77ea326d53cb1ae1e6b68c96aa0c3
 - Visit wp-admin/edit.php
 - Try to edit a post with "Quick Edit" to trigger the ajax action
 - Check PHP error log (debug.log)

 Error with track trace:

 > [12-Jul-2021 04:28:47 UTC] PHP Notice:  Undefined index: hook_suffix in
 /var/www/html/wp-admin/includes/class-wp-screen.php on line 223
 > [12-Jul-2021 04:28:47 UTC] PHP Stack trace:
 > [12-Jul-2021 04:28:47 UTC] PHP   1. {main}() /var/www/html/wp-admin
 /admin-ajax.php:0
 > [12-Jul-2021 04:28:47 UTC] PHP   2. do_action() /var/www/html/wp-admin
 /admin-ajax.php:187
 > [12-Jul-2021 04:28:47 UTC] PHP   3. WP_Hook->do_action() /var/www/html
 /wp-includes/plugin.php:484
 > [12-Jul-2021 04:28:47 UTC] PHP   4. WP_Hook->apply_filters()
 /var/www/html/wp-includes/class-wp-hook.php:316
 > [12-Jul-2021 04:28:47 UTC] PHP   5. {closure:/var/www/html/wp-content
 /mu-plugins/trac-49089.php:11-24}() /var/www/html/wp-includes/class-wp-
 hook.php:292
 > [12-Jul-2021 04:28:47 UTC] PHP   6. WP_List_Table->__construct()
 /var/www/html/wp-content/mu-plugins/trac-49089.php:14
 > [12-Jul-2021 04:28:47 UTC] PHP   7. convert_to_screen() /var/www/html
 /wp-admin/includes/class-wp-list-table.php:149
 > [12-Jul-2021 04:28:47 UTC] PHP   8. WP_Screen::get() /var/www/html/wp-
 admin/includes/template.php:2571

 == Root cause

 The error happens around this line
 http://github.com/WordPress/WordPress/blob/9f91305af2bd18c914096cc5e5cc1d6882163200
 /wp-admin/includes/class-wp-screen.php#L223-L223
 {{{#!php
                         $id = $GLOBALS['hook_suffix'];
 }}}


 admin-ajax.php requests do not load file wp-admin/admin.php, which is
 loaded when admins browse wp-admin pages.
 Then `global $hook_suffix` is not added and defined, hence, the PHP error
 `Undefined index: hook_suffix` happens.

 A side note here: I searched `hook_suffix` and `$hook_suffix` across
 WordPress core and found out that this global `$hook_suffix` var is set up
 in file wp-admin/admin.php:

 -
 http://github.com/WordPress/WordPress/blob/9f91305af2bd18c914096cc5e5cc1d6882163200
 /wp-admin/admin.php#L203-L210

 == Solution

 I think the ultimate solution here is to change the way we handle
 `$GLOBALS['hook_suffix']` and property `id` of class `WP_List_Table`.

 That's why I proposed assigning a value for property `id` with the
 `wp_ajax_` prefix for this case in PR: https://github.com/WordPress
 /wordpress-develop/pull/1490

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


More information about the wp-trac mailing list