Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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?

share|improve this question
    
Safe for what? Please explain the actual problem you want to solve. –  toscho Jul 25 '12 at 17:30
    
I am developing a plug-in that generates a table of users. I read that the class is not safe to use because its listed as private. So I was wondering if it is ok to use or not. –  Ken Jul 25 '12 at 17:39
    
Add your use case – the data you want to work with and the place where you want to use the class – to the question. There are circumstances where you cannot or should not use WP_List_Table and others where it is rather safe. The better you scope your question the better the answers will be. –  toscho Jul 25 '12 at 17:45

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.