List Table API – Safe to use?

Just curious what developers think about extending the WP_List_Table class for use on plug-ins.

I am working on a plug-in that will show a list of users (ID, name, email) then pull data from another plug-in that created a subscription date and access level in the user meta table.
The plug-in will be in the admin area of WP and only available to administrators.

Read More

I was hoping to use the class to be able to select multiple users and edit the data of multiple users at one time.

Is the class safe to use in this case or should the table be re-created?

Related posts

Leave a Reply

2 comments

  1. Its not a private class, only its methods (some) are defined as private so as long as you extend the class and use your own instance of theme extention you should bs safe and fine.

  2. Known issue

    The only thing were you shouldn’t use the class WP_List_Table without checking if it is already in use, is inside a meta box.

    Reason

    Using it would break the columns of one of the meta boxes as there’s only one filter to setup the screen columns per screen.

    Filters

    • manage_{$screen->id}_columns inside get_column_headers()
    • manage_{$screen->id}_columnshidden inside get_hidden_columns()

    They’re located in ~/wp-admin/includes/screen.php.

    Solution #1

    Check if there’s already a callback attached to those filters.

    Disclaimer: I’m not aware of other issues, but there maybe some.

    Solution #2

    As @Bainternet described and as you can read in the Codex, here’s a short example:

    class WPSE_59744_List_Table extends WP_List_Table
    {
        // Example
        public function extra_tablenav( $which )
        {
            // This can be overridden to display additional controls 
            // between the rendered bulk actions and pagination controls.
            // ...
            // define your logic here
        }
    }
    

    Then simply use your own instance like this:

    $wpse_59744_list_table = new WPSE_59744_List_Table();
    $wpse_59744_list_table->display();