Skip to content

fix: make the Screen Options column toggles work on the subscriptions screen - #60

Merged
wzul merged 1 commit into
mainfrom
fix/screen-options-columns
Sep 25, 2026
Merged

wzul merged 1 commit into
mainfrom
fix/screen-options-columns

Conversation

@wzul

@wzul wzul commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

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:

  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.

… 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.
@wzul
wzul merged commit f4ae818 into main Sep 25, 2026
7 checks passed
@wzul
wzul deleted the fix/screen-options-columns branch September 25, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant