Using WP_List_Table in a plugin

I’m not entirely familiar with OOP, but I know the basics. I’m creating a WordPress plugin and need to create a (html) table on the plugin page. I’ve read that in WP 3.1 there is a class called WP_List_Table which can generate the necessary markup.

Could someone give me a very basic idea of how to use this? Do I need to create a child class in order to use it?

Related posts

Leave a Reply

2 comments

  1. Yes, you have to create a child class to extend the properties of the parent class. I duplicated the wp-admin/plugins.php and wp-admin/includes/class-wp-plugins-list-table.php and moved those files into my plugin.

    I then did the whole backwards engineering thing to make it work with the current plugin I was working on. I also found a bug in the process that has already been reported and being worked on.

    The bug is found on http://core.trac.wordpress.org/ticket/15386.

    In short this never executed when the child class is executed from a plugin.

    list($columns, $hidden) = $this->get_column_info();
    

    As a work around I commented out the above code and feed the method directly with what it was looking for:

    $columns = $this->get_columns();
    $hidden  = $sortable = array();
    

    If you have hidden or sortable columns you can call their methods directly as well, but I didn’t need them for my implementation.

    After a few hours I now understand what the class is doing and I have a working model. and when the bug is fixed, it’ll be a little nicer 😉