Skip to content

Conversation

@westonruter
Copy link
Member

Search: \bif\s*\(\s*isset\(\s*(\$.+?)\s*\)\s*\)\s*\{\s*(\$.+?)\s*=\s*\1;\s*\}\s*else\s*\{\s*\2\s*=\s*(\S*?);\s*}

Replace: $2 = $1 ?? $3;

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


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.

Search:  \bif\s*\(\s*isset\(\s*(\$.+?)\s*\)\s*\)\s*\{\s*(\$.+?)\s*=\s*\1;\s*\}\s*else\s*\{\s*\2\s*=\s*(\S*?);\s*}
Replace: $2 = $1 ?? $3;
@github-actions
Copy link

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

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

@github-actions
Copy link

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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 westonruter force-pushed the update/null-coalescing-for-if-statements branch from 42d8a9c to dd160ef Compare January 10, 2026 04:33
@westonruter westonruter requested a review from Copilot January 10, 2026 04:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request modernizes WordPress code by replacing traditional isset() checks with the null coalescing operator (??), making the code more concise and readable while maintaining identical behavior.

Changes:

  • Replaced if (isset($var)) { $result = $var; } else { $result = $default; } patterns with $result = $var ?? $default;
  • Applied this refactoring consistently across 15 files in both wp-includes and wp-admin directories
  • Maintained existing code alignment and formatting conventions

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/wp-includes/theme.php Simplified array key check for attachment_parent in header images
src/wp-includes/rest-api/class-wp-rest-server.php Simplified $_SERVER['PATH_INFO'] check in request handling
src/wp-includes/meta.php Simplified array key check for meta cache retrieval
src/wp-includes/media.php Simplified decoding attribute check for image optimization
src/wp-includes/general-template.php Simplified object property check for post type description
src/wp-includes/class-wp-xmlrpc-server.php Simplified array key check for comment status in XML-RPC
src/wp-includes/class-wp-styles.php Simplified object property check for media type
src/wp-includes/class-wp-post-type.php Simplified array key check for permalink endpoint mask
src/wp-includes/class-wp-http-streams.php Simplified Host header check in HTTP streams
src/wp-includes/class-wp-date-query.php Simplified array key check for date query parameters
src/wp-admin/upgrade.php Simplified $_GET['step'] check in upgrade process
src/wp-admin/includes/theme.php Simplified nested array key check for theme features
src/wp-admin/includes/template.php Simplified $_REQUEST['post_status'] check for post states
src/wp-admin/includes/post.php Simplified array key check for post ID
src/wp-admin/includes/class-wp-importer.php Simplified array key check for CLI argument parsing

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

@westonruter westonruter changed the title Use null coalescing operator instead of if/else statements Use null coalescing operator instead of isset() in if/else statements Jan 10, 2026
pento pushed a commit that referenced this pull request Jan 10, 2026
… with `if`/`else` statements.

Developed in #10711

Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

See #58874, #63430.


git-svn-id: https://develop.svn.wordpress.org/trunk@61463 602fd350-edb4-49c9-b593-d223f7449a82
@westonruter
Copy link
Member Author

Committed in r61463.

markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jan 10, 2026
… with `if`/`else` statements.

Developed in WordPress/wordpress-develop#10711

Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

See #58874, #63430.

Built from https://develop.svn.wordpress.org/trunk@61463


git-svn-id: http://core.svn.wordpress.org/trunk@60775 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to gilzow/wordpress-performance that referenced this pull request Jan 10, 2026
… with `if`/`else` statements.

Developed in WordPress/wordpress-develop#10711

Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

See #58874, #63430.

Built from https://develop.svn.wordpress.org/trunk@61463


git-svn-id: https://core.svn.wordpress.org/trunk@60775 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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