Skip to content

Code Modernization: Use the null coalescing assignment operator in wp-includes/update.php - #16051

Open
noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:fix/65823-update-defaults
Open

noruzzamans wants to merge 1 commit into
WordPress:trunkfrom
noruzzamans:fix/65823-update-defaults

Conversation

@noruzzamans

Copy link
Copy Markdown
Member

Part of Core Trac Ticket #65823.

Replaces verbose ! isset() guard blocks that assign default values with the null coalescing assignment operator (??=) in src/wp-includes/update.php.

Scope

This covers wp_update_plugins() and wp_update_themes() completely in src/wp-includes/update.php:

  • wp_update_plugins(): Sets default $update->new_version from $update->version.
  • wp_update_themes(): Sets default $update->new_version from $update->version.

Both update functions normalize version information using the same idiom, so the two functions read consistently. 2 guard blocks replaced (-6 lines, +2 lines).

Why this is safe

  • ??= requires PHP 7.4, which is already the minimum supported version for WordPress.
  • ??= and ! isset() evaluate the exact same condition, applying the default only when the property is not already set.
  • Assignment order is preserved.
  • No behavior change; this is a purely internal syntax simplification.

Follow-up to [r65529], [r65530], and [r65535].

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

@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.

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.

🟢 Approval recommended

No active review issues are reported for the version-normalization cleanup in plugin and theme update checks.

No open issues 🎉

What changed in this PR

Modernizes version normalization in WordPress’s plugin and theme update checks as part of Trac #65823, without changing behavior.

Changes:

  • Replaces two ! isset() assignment guards with ??= in wp_update_plugins() and wp_update_themes().
  • Preserves the fallback from version when new_version is unset or null.
File Description
src/​wp-includes/​update.php Simplifies default version assignments in both update functions.

Review effort: Balanced

@noruzzamans
noruzzamans marked this pull request as ready for review November 17, 2026 05:16
@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.

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

Props noruzzaman.

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.

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