[wp-trac] [WordPress Trac] #14776: 'manage_' . screen . '_columns' filter not working

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 16 20:27:17 UTC 2010


#14776: 'manage_' . screen . '_columns' filter not working
-----------------------------+----------------------------------------------
 Reporter:  arena            |        Owner:            
     Type:  feature request  |       Status:  closed    
 Priority:  normal           |    Milestone:            
Component:  Administration   |      Version:            
 Severity:  major            |   Resolution:  worksforme
 Keywords:                   |  
-----------------------------+----------------------------------------------
Changes (by scribu):

  * status:  reopened => closed
  * resolution:  => worksforme


Comment:

 Sure.

 Example class:

 {{{
 class Example_List_Table extends WP_List_Table {

         function __construct() {
                 parent::WP_List_Table( array(
                         'screen' => 'item',
                         'plural' => 'items',
                 ) );
         }

         function prepare_items() {
                 $this->items = get_items();

                 $this->set_pagination_args( array(
                         'total_items' => 100,
                         'per_page' => 10
                 ) );
         }

         function get_columns() {
                 return array(
                         'cb'    => '<input type="checkbox" />',
                         'name'  => 'Name',
                         'color' => 'Color',
                 );
         }

         function column_cb( $item ) {
                 return '<input type="checkbox" name="delete_items[]"
 value="' . $item->id . '">';
         }

         function column_name( $item ) {
                 return $item->name;
         }

         function column_color( $item ) {
                 return $item->color;
         }

         function column_default( $item, $column_name ) {
                 return apply_filters( "manage_items_custom_column", '',
 $column_name, $item->id );
         }
 }
 }}}

 How you use it:

 {{{
 function example_init() {
   require dirname(__FILE__) . '/example-list-table.class.php';

   global $wp_list_table;

   $wp_list_table = new Example_List_Table;
 }
 add_action('admin_init', 'example_init');

 // later...

 $wp_list_table->prepare_items();
 $wp_list_table->display();
 }}}


 Mockup get_items() function:

 {{{
 function get_items() {
         $items = array();

         $items[] = (object) array(
                 'id' => 1,
                 'name' => 'First item',
                 'color' => 'red',
         );

         $items[] = (object) array(
                 'id' => 2,
                 'name' => 'Second item',
                 'color' => 'green',
         );

         return $items;
 }
 }}}

 Note: you don't need to re-open the ticket to leave a reply.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14776#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list