Skip to content

Taxonomy: Fix strtolower() deprecation in WP_Term_Query::parse_orderby()#12622

Open
Adi-ty wants to merge 2 commits into
WordPress:trunkfrom
Adi-ty:fix/65679-term-query-orderby-null
Open

Taxonomy: Fix strtolower() deprecation in WP_Term_Query::parse_orderby()#12622
Adi-ty wants to merge 2 commits into
WordPress:trunkfrom
Adi-ty:fix/65679-term-query-orderby-null

Conversation

@Adi-ty

@Adi-ty Adi-ty commented Jul 21, 2026

Copy link
Copy Markdown

WP_Term_Query::parse_orderby() passes the orderby query var straight into strtolower(). If a caller explicitly passes 'orderby' => null, this triggers a Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated notice on PHP 8.1+.

parse_order() in the same class already guards against this with an is_string() check; this PR adds the same guard to parse_orderby(). A null value now falls through to the existing empty-string handling, preserving the current ORDER BY t.term_id fallback behavior with no notice.

Adds a test asserting no deprecation is thrown and that ordering falls back to term_id as before.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Opencode
Model(s): DeepSeek V4 Flash
Used for: Diagnosing the issue.


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.

Copilot AI review requested due to automatic review settings July 21, 2026 11:56
@Adi-ty
Adi-ty marked this pull request as ready for review July 21, 2026 11:56
@github-actions

github-actions Bot commented Jul 21, 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. 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 iamadisingh, soean.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Addresses a PHP 8.1+ deprecation in WP_Term_Query::parse_orderby() by ensuring the orderby query var is a string before calling strtolower(), preventing notices when callers pass orderby => null. Adds a PHPUnit regression test covering the null orderby case.

Changes:

  • Guard WP_Term_Query::parse_orderby() against non-string orderby values before lowercasing.
  • Add a term query test for orderby => null to ensure no PHP deprecation and that ordering falls back as expected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/wp-includes/class-wp-term-query.php Adds a type guard to prevent strtolower(null) deprecation on PHP 8.1+.
tests/phpunit/tests/term/query.php Adds a regression test for orderby => null behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/phpunit/tests/term/query.php Outdated
Comment on lines +296 to +308
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );

$q = new WP_Term_Query(
array(
'taxonomy' => 'wptests_tax_1',
'orderby' => null,
'hide_empty' => false,
'fields' => 'ids',
)
);

$this->assertSame( $terms, $q->terms );
}
@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.

@Soean

Soean commented Jul 21, 2026

Copy link
Copy Markdown
Member

orderby should be a string, why should we allow null?

https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters

Copilot AI review requested due to automatic review settings July 21, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines 917 to +921
* @param string $orderby_raw Alias for the field to order by.
* @return string|false Value to used in the ORDER clause. False otherwise.
*/
protected function parse_orderby( $orderby_raw ) {
if ( ! is_string( $orderby_raw ) ) {
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.

3 participants