Repository navigation
fix: make the Screen Options column toggles work on the subscriptions screen - #60
Merged
Merged
Conversation
… screen
Screen Options listed only "Subscriptions per page". There was no Columns panel,
so an operator could not choose which columns to see — the page had the shape of
a list table without one of its basic controls.
Two independent faults, both silent:
1. The table was built inside the page callback, which runs AFTER the admin
header. Screen Options draws its column toggles from `get_column_headers()`,
which caches the first lookup for the screen, and a `WP_List_Table`
supplies those headers through a filter registered in its CONSTRUCTOR. So
the cache was already filled with an empty array by the time the header
rendered, and the Columns panel came out blank. No warning, no error.
Fixed by building the table on `load-{hook}` — the last moment before the
header is printed, and what core's own list screens do (wp-admin/edit.php
builds its table at line 52 and prints the header at line 411). `render()`
now consumes that same table instead of constructing a second one.
2. `prepare_items()` set `_column_headers` with a hardcoded empty array for the
hidden set. That property is the cache `get_column_info()` returns, so it
discarded the preference on every render: the toggle wrote it, the next
render erased it, and a column could never actually be hidden. Fixed by
reading `get_hidden_columns( $this->screen )`, and the primary column is now
resolved via `get_primary_column_name()` rather than named literally.
Verified on a live install, not only in the suite:
panel open, 7 toggles, all checked
click "Token" off -> th + td carry `hidden` immediately
reload -> still hidden (the preference persisted)
re-check -> column returns
Also drops `cacheDirectory` from phpunit.xml.dist. It is valid on the 12.5
schema but not on 9.6, which the composer pin still uses, so PHPUnit 9 printed
"the configuration file did not pass validation ... results may not be as
expected" on every local run. Removed rather than worked around: nothing needed
the cache.
Tests: the build-on-load ordering, a single construction site, the hidden set
coming from the screen rather than a literal, and the primary column being
resolved rather than hardcoded. The harness gained `get_var()` and a faithful
`get_primary_column_name()` — without `get_var()` no test could get past
`prepare_items()` to reach the header cache, which is how both faults survived
the suite.
## Potential Risks & Review Items
- The table is now constructed earlier in the request. Anything the constructor
or `prepare_items()` touches must be available on `load-{hook}`: it reads the
row query and the screen's column preferences, both already available there.
`get_current_screen()` is set by admin.php before this hook fires.
- `prepare_items()` now runs during `load-{hook}`, i.e. one row query earlier in
the request than before. It is the same single query per request, not an
extra one; `render()` no longer triggers a second `prepare_items()`.
- A hidden column is a display preference only. The column stays declared, so
sorting by a hidden column and `?orderby=` still work.
- The status filter is now parsed once in `current_status()` and read back off
the table via `status()`. The clamp to the known vocabulary moved with it, so
an arbitrary value still cannot reach the query.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: make the Screen Options column toggles work on the subscriptions screen
Screen Options listed only "Subscriptions per page". There was no Columns panel,
so an operator could not choose which columns to see — the page had the shape of
a list table without one of its basic controls.
Two independent faults, both silent:
The table was built inside the page callback, which runs AFTER the admin
header. Screen Options draws its column toggles from
get_column_headers(),which caches the first lookup for the screen, and a
WP_List_Tablesupplies those headers through a filter registered in its CONSTRUCTOR. So
the cache was already filled with an empty array by the time the header
rendered, and the Columns panel came out blank. No warning, no error.
Fixed by building the table on
load-{hook}— the last moment before theheader is printed, and what core's own list screens do (wp-admin/edit.php
builds its table at line 52 and prints the header at line 411).
render()now consumes that same table instead of constructing a second one.
prepare_items()set_column_headerswith a hardcoded empty array for thehidden set. That property is the cache
get_column_info()returns, so itdiscarded the preference on every render: the toggle wrote it, the next
render erased it, and a column could never actually be hidden. Fixed by
reading
get_hidden_columns( $this->screen ), and the primary column is nowresolved via
get_primary_column_name()rather than named literally.Verified on a live install, not only in the suite:
Also drops
cacheDirectoryfrom phpunit.xml.dist. It is valid on the 12.5schema but not on 9.6, which the composer pin still uses, so PHPUnit 9 printed
"the configuration file did not pass validation ... results may not be as
expected" on every local run. Removed rather than worked around: nothing needed
the cache.
Tests: the build-on-load ordering, a single construction site, the hidden set
coming from the screen rather than a literal, and the primary column being
resolved rather than hardcoded. The harness gained
get_var()and a faithfulget_primary_column_name()— withoutget_var()no test could get pastprepare_items()to reach the header cache, which is how both faults survivedthe suite.
Potential Risks & Review Items
or
prepare_items()touches must be available onload-{hook}: it reads therow query and the screen's column preferences, both already available there.
get_current_screen()is set by admin.php before this hook fires.prepare_items()now runs duringload-{hook}, i.e. one row query earlier inthe request than before. It is the same single query per request, not an
extra one;
render()no longer triggers a secondprepare_items().sorting by a hidden column and
?orderby=still work.current_status()and read back offthe table via
status(). The clamp to the known vocabulary moved with it, soan arbitrary value still cannot reach the query.