Skip to content

Code Quality: Fix the undefined preview action in WP_Themes_List_Table - #16533

Open
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66739-phpstan-offsetaccess-notfound-themes-list-table
Open

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66739-phpstan-offsetaccess-notfound-themes-list-table

Conversation

@hmbashar

@hmbashar hmbashar commented Dec 5, 2026

Copy link
Copy Markdown

This resolves one of the four default offsetAccess.notFound PHPStan errors, in WP_Themes_List_Table::display_rows(), and removes its entry from the baseline. The other three entries, in class-wp-site-health.php and fonts.php, are left in the baseline.

The error

display_rows() builds the theme action links in $actions, and for users who can customize it adds the Live Preview link with $actions['preview'] .= sprintf( ... ). The preview key has not been set at that point, so PHPStan reports Offset 'preview' does not exist on array{activate: non-falsy-string}. This is a real bug: the .= reads the missing key first, which raises Undefined array key "preview" on PHP 8 (a notice on PHP 7) every time the Live Preview link is printed.

The fix

The line now assigns the link with = instead of appending with .=. Behavior is unchanged apart from the warning: appending to a missing key already produced the link on its own, so $actions['preview'] holds the same string and the theme_action_links filters receive the same array. The line has been this way since at least r25001.

A test, test_themes_list_table_display_rows_prints_live_preview_link(), prints the rows for an administrator and checks that the Live Preview link is there. It errors with Undefined array key "preview" without the fix and passes with it.

Testing

  • composer phpstan:default and composer phpstan:strict report no errors.
  • composer phpstan:baselines -- --identifier=offsetAccess.notFound reports no errors, and only the class-wp-themes-list-table.php entry is removed.
  • PHPCS reports no issues on class-wp-themes-list-table.php and wpListTable.php.
  • tests/phpunit/tests/admin/wpListTable.php passes (75 tests, the same 4 PHPUnit deprecation warnings as on trunk).

Trac ticket: https://core.trac.wordpress.org/ticket/66739

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Assign the Live Preview link instead of appending to an action that is not set, and add a test.
@github-actions

github-actions Bot commented Dec 5, 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 hmbashar.

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 Dec 5, 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.

@hmbashar

hmbashar commented Dec 5, 2026

Copy link
Copy Markdown
Author

@propsbot refresh

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