[wp-trac] [WordPress Trac] #15386: WP_List_Table::get_columns does not work for plugins

WordPress Trac noreply at wordpress.org
Sun Feb 23 06:14:55 UTC 2020


#15386: WP_List_Table::get_columns does not work for plugins
--------------------------+------------------------------
 Reporter:  ptahdunbar    |       Owner:  scribu
     Type:  defect (bug)  |      Status:  reopened
 Priority:  high          |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.1
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------
Changes (by johnwatkins0):

 * keywords:  needs-patch => has-patch


Comment:

 Attaching 15386.diff. Also via GitHub: https://patch-
 diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/165.diff

 = Description of the change

 This allows the filter in the `get_column_headers` function to be applied
 multiple times during page execution. Previously this function used a
 static variable to ensure the filter was only applied once per screen
 object per page load.

 That static variable is not needed. The function doesn't need to maintain
 internal state because it's never called more than once within core, and I
 don't see any reason that the performance-related use cases for static
 variables apply here. I'm happy to discuss this further.

 = Test steps

 Before pulling these changes, put this in a file in `wp-content/plugins`


 {{{
 <?php
 /**
  * Plugin Name: My List Table Plugin
  */

 add_action( 'admin_menu', 'my_list_table_plugin_init' );

 function my_list_table_plugin_init() {
         add_menu_page( 'Test', 'Test', 'manage_options', 'test',
 'my_list_table_plugin_display' );
 }

 function my_list_table_plugin_display() {
         $table = _get_list_table( 'WP_Comments_List_Table' );
         $table->views();
         $table->prepare_items();
         $table->display();
 }
 }}}


 == Before

 Activate the plugin. Visit /wp-admin/admin.php?page=test in your local
 environment. Note that the table displays without the expected table rows.

 == After

 After pulling these changes, visit that page again. The table rows should
 now display.

 = Further considerations

 If this change were merged, wouldn't it mean that at least the
 `WP_List_Table` class and maybe also `_get_list_table` would no longer
 need to be private? If so, how would I deprecate `_get_list_table` in
 favor of `get_list_table`? Do we have documentation on that somewhere?

 I feel the API around these list tables could be improved, however, and
 maybe even Gutenbergized. If others agree, then maybe that class and
 function should stay private for now.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/15386#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list