Skip to content

Query Loop: Normalize invalid sticky post options - #14617

Open
salvatorecorsi wants to merge 1 commit into
WordPress:trunkfrom
salvatorecorsi:fix/60276-normalize-sticky-posts
Open

salvatorecorsi wants to merge 1 commit into
WordPress:trunkfrom
salvatorecorsi:fix/60276-normalize-sticky-posts

Conversation

@salvatorecorsi

Copy link
Copy Markdown

Query Loop can throw a PHP TypeError when its sticky-post setting is exclude and the stored sticky_posts option is a string or is missing. A nonempty string also reaches post__in unchanged in only mode.

Normalize a non-array option to an empty local list before constructing the query. Valid arrays retain their existing behavior; only still uses the existing array( 0 ) sentinel to return no posts. The stored option is not modified. This follows the defensive handling already used by other sticky-post readers.

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

To reproduce on a disposable test site, set sticky_posts to an empty string, insert a Query Loop with inherited query disabled, select Sticky Posts → Exclude, and render or save the template. Before this change, array_merge() receives a string; afterwards the query runs without treating the invalid value as post IDs. The ticket's original corrupted value was observed on an old WordPress.com site; its source was not established.

Validation on Windows, PHP 8.3.28, PHPUnit 9.6.38, using the isolated native test database:

  • Added 15 real-option/WP_Block/WP_Query cases covering three sticky modes, empty/nonempty/numeric strings, a missing option and an empty-array control. They also verify explicit exclusions and that the option is not rewritten. Against unchanged runtime: 4 TypeErrors and 2 assertion failures (15 tests, 29 assertions); with the fix: 15 tests, 45 assertions passed.
  • scripts/test-php.ps1 -Repository wordpress-develop -Checkout C:/Users/salva/.wp-fix/worktrees/wordpress-develop-60276 -Filter '^Tests_Blocks_wpBlock::': 64 tests, 221 assertions passed, including the existing valid-array sticky-post cases.
  • WPCS and PHP compatibility checks on both changed PHP files, PHP syntax checks, production-file PHPStan (0 errors), and git diff --check: passed.
  • Full npm run build after the runtime fix: passed. The built and source wp-includes/blocks.php copies have identical SHA-256 hashes. Existing Node deprecation and webpack asset-size/performance warnings remain nonfatal.

A preliminary broader filter (Tests_Blocks_wpBlock) also matched unrelated metadata-registry classes: 241 tests / 531 assertions with one Windows path-separator failure. That exact registry test fails identically against the frozen unchanged runtime (1 test / 2 assertions). It is retained as a known baseline limitation. PHPUnit also reports its existing deprecated XML-schema warning. No full PHPUnit, multisite or Docker E2E pass is claimed.

Use of AI Tools

AI assistance: Yes. OpenAI Codex investigated the ticket, authored the implementation and regression tests, and ran the recorded automated validation. A separate Codex agent reviewed the source, tests and results. The owner has not performed a human review; maintainer review is needed for acceptance into WordPress.


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.

@github-actions

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props salvatorecorsi.

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

@github-actions

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.

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