Skip to content

Administration: Avoid fatals when list table request parameters are arrays - #15328

Open
sarequl wants to merge 9 commits into
WordPress:trunkfrom
sarequl:fix/66432-admin-list-table-array-params
Open

sarequl wants to merge 9 commits into
WordPress:trunkfrom
sarequl:fix/66432-admin-list-table-array-params

Conversation

@sarequl

@sarequl sarequl commented Nov 1, 2026

Copy link
Copy Markdown

Fixes fatal errors on admin screens when list table request parameters are sent as arrays.

See https://core.trac.wordpress.org/ticket/66432

What

Several admin screens pass $_REQUEST values directly into string functions. PHP turns ?s[]=x into an array, so strlen(), trim(), urlencode(), urldecode(), and similar calls throw a TypeError and the screen dies with "There has been a critical error on this website". A few other parameters only produce "Array to string conversion" warnings.

Why

These request values are assumed to be strings. This is the admin counterpart of the front-end query var fatals in #60745, #64507, and #66171, which do not cover these screens.

How

Adds is_string() guards before the values reach string functions in 17 admin files. WP_Comment_Query::search uses is_scalar() so an integer 0 still works. Array values are ignored and the screen falls back to its default state; scalar values behave exactly as before. Also adds a PHPUnit test that an array search value is ignored by WP_Comment_Query.

Testing Instructions

  1. Log in as an administrator on PHP 8.0 or later with WP_DEBUG on.
  2. Visit each URL below with an array parameter and confirm the screen loads normally, with no fatal and no "Array to string conversion" warning:
    • /wp-admin/edit.php?s[]=x
    • /wp-admin/upload.php?mode=list&s[]=x
    • /wp-admin/upload.php?mode=list&attachment-filter[]=image (media list view)
    • /wp-admin/edit-comments.php?s[]=x
    • /wp-admin/users.php?s[]=x
    • /wp-admin/edit-tags.php?taxonomy=category&s[]=x
    • /wp-admin/edit-tags.php?taxonomy=category&orderby[]=name
    • /wp-admin/plugins.php?s[]=x
    • /wp-admin/plugin-install.php?tab=search&s[]=x
    • /wp-admin/site-health.php?tab[]=debug
  3. Check the warning-only cases as well: edit.php?post_status[]=draft, edit.php?order[]=asc, edit.php?author[]=1, upload.php?mode[]=list, edit-comments.php?comment_type[]=comment, and users.php?role[]=administrator.
  4. Confirm scalar searches are unchanged on the Posts, Comments, Users, Terms, Plugins, Media, and Plugin Install screens: ?s=foo, ?s=, ?s=0, and no s parameter.

A 19-URL sweep covering all of the above returns HTTP 200 on every URL, with 0 fatals and 0 "Array to string conversion" warnings; scalar responses are byte-identical to trunk. PHPUnit (tests/phpunit/tests/comment/query.php, 163 tests), PHPStan, and npm run build pass, and phpcs reports no errors on the changed files (the remaining warnings are pre-existing and not on changed lines).

Props digitalpritam for the report.

Several admin screens passed request values straight into string
functions, so an array parameter caused a TypeError or an "Array to
string conversion" warning. Check that each value is a string (or a
scalar for the comment search query) before using it.
_admin_search_query() and the post_mime_type and detached hidden fields
still cast request arrays to strings, which surfaced as warnings once
the earlier fatals were fixed.
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sarequl, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

westonruter and others added 7 commits November 12, 2026 10:05
Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
An array 'orderby' whose list entry is itself an array, as with
`users.php?orderby[0][]=x`, reached the `isset()` lookup on the meta
query clauses in `parse_orderby()` and threw a TypeError. Guarding in
the query class covers every caller of `get_users()`, not only the
Users list table.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
On the Posts and Media screens, an array `ids` was passed to
`explode()`, and on the Posts screen a scalar `post` was passed to
`array_map()`. Both threw a TypeError. Only a string `ids` is now
exploded, and `post` is cast to an array, with any non-numeric entry
mapped to 0.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
`WP_Plugins_List_Table::search_box()` overrides the parent method,
so it missed the string checks added there. An array `orderby` or
`order` raised an "Array to string conversion" warning and printed
`value="Array"` into the hidden input.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
When `orderby` is an array, `WP_List_Table::search_box()` echoes each
entry back as a hidden input. A nested array entry, such as from
`orderby[title][]=x`, raised an "Array to string conversion" warning
and printed `value="Array"`. Non-string entries are now skipped.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
The search `type` was read without a string check next to the `s`
reads that already had one. An array `type` raised "Array to string
conversion" warnings in `selected()`. It now falls back to `term`, in
both the search form and the list table.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379
…able.

`WP_Comments_List_Table::prepare_items()` added the AJAX `offset` to
`start` without checking either. An array, or a non-numeric string,
threw an "Unsupported operand types" TypeError. Both are now used only
when numeric and are cast to integers; otherwise `start` falls back to
the page offset.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tnky3LnCGk4tTNDf3wjdhe
Claude-Code-Session-Id: d29ab326-6a9a-4f1d-99bf-988709d1b379

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking this as requested changes because it will need to be re-worked to incorporate the changes described in https://core.trac.wordpress.org/ticket/22325#comment:54

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.

2 participants