[wp-trac] [WordPress Trac] #42692: Unused static variable $column_headers

WordPress Trac noreply at wordpress.org
Fri Nov 24 18:56:51 UTC 2017


#42692: Unused static variable $column_headers
----------------------------+-----------------------------
 Reporter:  jlambe          |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 === Context

 We're working on a custom `WP_List_Table` class. For a project, we have
 setup a custom admin page and attach it to a custom post type.

 Basically we call the `add_submenu_page` and set its parent slug to
 `edit.php?post_type=custom_post_slug`.

 Our custom list table class is called `CurrencyListTable` and just
 displays a list of currencies coming from a custom database table. For
 this table, we have defined 2 custom columns. We correctly extend the
 `get_columns()` method and return an array with those 2 columns.

 === Expected result

 On our page display fallback, we instantiate our custom table class and
 call its `prepare_item()`, `search_box()` and `display()` methods in order
 to render our list table.

 We expect to see the usual list table with the table header and footer,
 the rows containing 20 items as our `$per_page` definition, the search box
 and the table pagination.

 === Result

 Everything is displayed on screen except the header, footer and rows of
 the table. The search box, pagination and total number of items is
 correctly displayed.

 === Solution

 We have digged into the WordPress source code and stop our attention on
 the `get_column_headers()` function defined into the `wp-
 admin/includes/screen.php` file line 19.

 When we remove the `static` definition for the `$columns_header` variable
 on line 23, our custom table renders correctly.

 Perhaps a core developer could provide more information on why this
 variable is set as static.

 We can see that the `get_column_headers()` function is called several
 times when rendering a list table and that we might want to re-use the set
 variable. But we don't understand why the first initialization is
 incorrect and set our column headers as an empty array.

 When removing the `static` definition, everything works as expected. We
 have tested this with another custom set of people data where we have
 114589 rows and haven't noticed any slow performance (we still show 20
 rows per page).

 Core list tables also work as expected for posts, pages, plugins, users,
 ...

 Personnaly I think we can remove the `static` keyword as the
 `WP_List_Table` class `get_column_info()` method is storing the list of
 columns for a table instance into its "private" property
 `$_column_headers`. But I would like more insights from core developers
 before diggin into a patch.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42692>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list