Screen Options with wp_list_table not picking up correct columns
-
I’ve been trying to get my screen options meta box to work but I’ve had no luck so far. Here’s what I’m doing in sequence of initialization of the table object (using WP boiler plate, of plugin-name.php -> class-plugin-name.php -> class-plugin-name-admin.php-> class-plugin-name-manage-table.php)
Inside of class-plugin-name-admin:
$hook = add_menu_page( 'Plugin Manage', 'Plugin Manage', 'manage_options', 'plugin_manage_options', array($this, 'render_page_content'), 'dashicons-money-alt' ); $this->hook = $hook; $this->MT = new Plugin_Manage_Table($this->plugin_name, $this->plugin_version, $this->hook); $this->MT->prepare_items(); // try to configure $columns? add_action('load-' . $hook, array($this->MT, 'load_user_table_screen_options'));
Then in Plugin_Manage_Table
public function __construct($plugin_name, $version, $hook) { $this->plugin_name = $plugin_name; $this->version = $version; $this->search = ''; $this->hook = $hook; // menu hook parent::__construct( array( 'singular' => 'item', 'plural' => 'items', 'ajax' => false ) ); } public function load_user_table_screen_options() { $arguments = array( 'label' => __('Items', 'plugin_manage_options'), 'default' => 30, 'option' => 'items_per_page' ); add_screen_option('_per_page', $arguments); }
However the screen option box shows columns from a different wp_table_list object. When I check global $wp_metabox it’s empty, but the get_current_screen appears correct for the object. This is right after calling add_screen_options
WP_Screen Object ( [action] => [base] => toplevel_page_plugin_manage_options [columns:WP_Screen:private] => 0 [id] => toplevel_page_plugin_manage_options [in_admin:protected] => site [is_network] => [is_user] => [parent_base] => [parent_file] => [post_type] => [taxonomy] => [_help_tabs:WP_Screen:private] => Array ( ) [_help_sidebar:WP_Screen:private] => [_screen_reader_content:WP_Screen:private] => Array ( ) [_options:WP_Screen:private] => Array ( [_per_page] => Array ( [label] => Items [default] => 30 [option] => items_per_page ) ) [_show_screen_options:WP_Screen:private] => [_screen_settings:WP_Screen:private] => [is_block_editor] => )
I should also mention that my plugin generates this warning which I’ve been unable to figure out how to fix:
PHP Notice: Undefined index: hook_suffix in /WP/wp-admin/includes/class-wp-screen.php on line 223, referer: https://localhost/wp-admin/admin.php?page=plugin_manage_options
- The topic ‘Screen Options with wp_list_table not picking up correct columns’ is closed to new replies.