• I’m missing something basic here in plugin setup regarding the hood_suffix but I haven’t been able to find out exactly what is wrong.

    I get a lot of hook_suffix undefined errors with my test_plugin while using WP_List_Table.

    [04-Apr-2022 19:10:26 UTC] PHP Warning:  Undefined array key "hook_suffix" in /var/www/html/wp-admin/includes/class-wp-screen.php on line 223
    [04-Apr-2022 19:10:26 UTC] PHP Stack trace:
    [04-Apr-2022 19:10:26 UTC] PHP   1. {main}() /var/www/html/wp-admin/admin-ajax.php:0
    [04-Apr-2022 19:10:26 UTC] PHP   2. do_action($hook_name = 'admin_init') /var/www/html/wp-admin/admin-ajax.php:45
    [04-Apr-2022 19:10:26 UTC] PHP   3. WP_Hook->do_action($args = [0 => '']) /var/www/html/wp-includes/plugin.php:474
    [04-Apr-2022 19:10:26 UTC] PHP   4. WP_Hook->apply_filters($value = '', $args = [0 => '']) /var/www/html/wp-includes/class-wp-hook.php:331
    [04-Apr-2022 19:10:26 UTC] PHP   5. Test_plugin_Admin_Settings->initialize_members('') /var/www/html/wp-includes/class-wp-hook.php:307
    [04-Apr-2022 19:10:26 UTC] PHP   6. Test_plugin_Table->__construct($plugin_name = 'test_plugin', $version = '1.0.0') /var/www/html/wp-content/plugins/test_plugin/admin/class-test_plugin-admin-settings.php:318
    [04-Apr-2022 19:10:26 UTC] PHP   7. Test_plugin_Table->__construct($args = ['singular' => 'item', 'plural' => 'items', 'ajax' => FALSE]) /var/www/html/wp-content/plugins/test_plugin/admin/class-test_plugin-admin-tables.php:24
    [04-Apr-2022 19:10:26 UTC] PHP   8. convert_to_screen($hook_name = NULL) /var/www/html/wp-admin/includes/class-wp-list-table.php:149
    [04-Apr-2022 19:10:26 UTC] PHP   9. WP_Screen::get($hook_name = NULL) /var/www/html/wp-admin/includes/template.php:2583

    The plugin has been working for some time successfully, but I’ve been unable to figure out the source of this warning.

    Any help in understanding where to look or what to try would be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Look at the source code where the error occurs. If $hook_name is not passed to the function, it relies upon global $hook_suffix to set the screen ID. It seems your admin screen doesn’t have a screen ID. (Any screen using WP_List_Table is presumed to be an admin screen) While you could have your code explicitly set the global, you may be better off using set_current_screen(). You may pass any distinct string value you like to this function.

    Thread Starter EricB50

    (@ericb50)

    Thanks for help. It’s not clear to me where this should be defined. Should my constructor just call set_current_screen and set it to a value?

    I have not seen an example with wp_list_table that does this either. I do have problems sometimes with trying to use wp_list_table with tabs and pagination. Perhaps I should be setting up current screens for each tab?

    If you have any more information on this it would be appreciated. I’d love to get this sorted out for my plugins.

    Moderator bcworkz

    (@bcworkz)

    In my only plugin I set the screen in the callback that generates output for the admin screen. But it’s a real admin screen and it doesn’t use WP_List_Table. From the error trace it looks like your class constructor would be the logical place.

    If the tabs are all output within the same code sequence, calling it once for all should suffice. I don’t think it matters if multiple tables are under the same screen name or if the same name is re-set. But for pagination where a new request is initiated, then set_current_screen() does need to be called each time. Being within the constructor will accomplish that. The name doesn’t need to be unique for every page.

    The only pertinent information I can point to is the WP source code for set_current_screen(), which basically calls WP_Sctreen:get(). You can see there that $GLOBALS[‘hook_suffix’] is assigned the passed value if a screen object does not already exist. The remainder of the function is probably not applicable.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Undefined array key “hook_suffix” and WP_List_Table’ is closed to new replies.