Commit a11eaaecde for wordpress.org
commit a11eaaecde237054f0af3a787552fec68a5a9792
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date: Sun Sep 6 18:39:53 2026 +0000
Code Modernization: Use the null coalescing assignment operator for default value assignments.
Replaces verbose "assign a default only if not already set" patterns with the null coalescing assignment operator (`??=`):
{{{
// Before
$args['title'] = $args['title'] ?? '';
// After
$args['title'] ??= '';
}}}
Both forms are functionally identical; `??=` is shorter and clearer.
**Why this is safe**
- `??=` requires PHP 7.4, which is already the minimum.
- The operator is already used elsewhere in core (e.g. `wp-includes/l10n.php`, `wp-includes/view-config.php`), so this only makes existing usage consistent.
- No behavior change.
Follow-up to r63443, r63501.
Props Soean, mukesh27.
See #65823.
Built from https://develop.svn.wordpress.org/trunk@63509
git-svn-id: http://core.svn.wordpress.org/trunk@62685 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index 8c80b94c04..8b1dd3d1f9 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -67,9 +67,9 @@ if ( wp_is_mobile() ) {
* @name $post_ID
* @var int
*/
-$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
-$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
-$action = $action ?? '';
+$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
+$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
+$action ??= '';
if ( (int) get_option( 'page_for_posts' ) === $post->ID && empty( $post->post_content ) ) {
add_action( 'edit_form_after_title', '_wp_posts_page_notice' );
diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index 8f2d431f05..88853f6496 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -369,8 +369,8 @@ class WP_Ability {
* `show_in_rest` value wins, then the high-level `public` flag seeds the
* default, then the built-in default applies.
*/
- $args['meta']['show_in_rest'] = $args['meta']['show_in_rest'] ?? $args['meta']['public'] ?? self::DEFAULT_SHOW_IN_REST;
- $args['meta']['public'] = $args['meta']['public'] ?? self::DEFAULT_PUBLIC;
+ $args['meta']['show_in_rest'] ??= $args['meta']['public'] ?? self::DEFAULT_SHOW_IN_REST;
+ $args['meta']['public'] ??= self::DEFAULT_PUBLIC;
return $args;
}
diff --git a/wp-includes/block-supports/background.php b/wp-includes/block-supports/background.php
index dc73e48c37..ca04322f9c 100644
--- a/wp-includes/block-supports/background.php
+++ b/wp-includes/block-supports/background.php
@@ -82,7 +82,7 @@ function wp_render_background_support( $block_content, $block ) {
$background_styles['backgroundAttachment'] = $block_attributes['style']['background']['backgroundAttachment'] ?? null;
if ( ! empty( $background_styles['backgroundImage'] ) ) {
- $background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover';
+ $background_styles['backgroundSize'] ??= 'cover';
// If the background size is set to `contain` and no position is set, set the position to `center`.
if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) {
diff --git a/wp-includes/class-wp-http-cookie.php b/wp-includes/class-wp-http-cookie.php
index cfdf4da1dd..6049681f11 100644
--- a/wp-includes/class-wp-http-cookie.php
+++ b/wp-includes/class-wp-http-cookie.php
@@ -189,9 +189,9 @@ class WP_Http_Cookie {
}
// Get details on the URL we're thinking about sending to.
- $url = parse_url( $url );
- $url['port'] = $url['port'] ?? ( 'https' === $url['scheme'] ? 443 : 80 );
- $url['path'] = $url['path'] ?? '/';
+ $url = parse_url( $url );
+ $url['port'] ??= ( 'https' === $url['scheme'] ? 443 : 80 );
+ $url['path'] ??= '/';
// Values to use for comparison against the URL.
$path = $this->path ?? '/';
diff --git a/wp-includes/class-wp-icons-registry.php b/wp-includes/class-wp-icons-registry.php
index ec60bb381b..a10960da9a 100644
--- a/wp-includes/class-wp-icons-registry.php
+++ b/wp-includes/class-wp-icons-registry.php
@@ -320,8 +320,8 @@ class WP_Icons_Registry {
return null;
}
- $icon = $this->registered_icons[ $icon_name ];
- $icon['content'] = $icon['content'] ?? $this->get_content( $icon_name );
+ $icon = $this->registered_icons[ $icon_name ];
+ $icon['content'] ??= $this->get_content( $icon_name );
return $icon;
}
@@ -346,8 +346,8 @@ class WP_Icons_Registry {
continue;
}
- $icon['content'] = $icon['content'] ?? $this->get_content( $icon['name'] );
- $icons[] = $icon;
+ $icon['content'] ??= $this->get_content( $icon['name'] );
+ $icons[] = $icon;
}
return $icons;
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 1f29dfb5f2..294580be4d 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -6292,8 +6292,8 @@ function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTIC
* @return bool Whether the server is running lighttpd < 1.5.0.
*/
function is_lighttpd_before_150() {
- $server_parts = explode( '/', $_SERVER['SERVER_SOFTWARE'] ?? '' );
- $server_parts[1] = $server_parts[1] ?? '';
+ $server_parts = explode( '/', $_SERVER['SERVER_SOFTWARE'] ?? '' );
+ $server_parts[1] ??= '';
return ( 'lighttpd' === $server_parts[0] && -1 === version_compare( $server_parts[1], '1.5.0' ) );
}
diff --git a/wp-includes/interactivity-api/class-wp-interactivity-api.php b/wp-includes/interactivity-api/class-wp-interactivity-api.php
index 16f270be0f..8a2bc34675 100644
--- a/wp-includes/interactivity-api/class-wp-interactivity-api.php
+++ b/wp-includes/interactivity-api/class-wp-interactivity-api.php
@@ -739,7 +739,7 @@ final class WP_Interactivity_API {
*
* @since 6.9.0
*/
- $this->derived_state_closures[ $ns ] = $this->derived_state_closures[ $ns ] ?? array();
+ $this->derived_state_closures[ $ns ] ??= array();
// Builds path for the current property and add it to tracking if not already present.
$current_path = implode( '.', array_slice( $path_segments, 0, $index + 1 ) );
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index ed37a83a87..10bda68115 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -109,8 +109,8 @@ function wp_force_plain_post_permalink( $post = null, $sample = null ) {
) {
$sample = true;
} else {
- $post = get_post( $post );
- $sample = $sample ?? false;
+ $post = get_post( $post );
+ $sample ??= false;
}
if ( ! $post ) {
diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php
index af81ea640b..0de022beac 100644
--- a/wp-includes/rest-api.php
+++ b/wp-includes/rest-api.php
@@ -973,8 +973,8 @@ function rest_filter_response_fields( $response, $server, $request ) {
// Skip any sub-properties if their parent prop is already marked for inclusion.
break 2;
}
- $ref[ $next ] = $ref[ $next ] ?? array();
- $ref = &$ref[ $next ];
+ $ref[ $next ] ??= array();
+ $ref = &$ref[ $next ];
}
$last = array_shift( $parts );
$ref[ $last ] = true;
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index c17193acfc..b95b061b33 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
@@ -1291,16 +1291,16 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
unset( $new_attachment_post->ID );
// Set new attachment post title with fallbacks.
- $new_attachment_post->post_title = $new_attachment_post->post_title ?? $original_attachment_post->post_title ?? $image_name;
+ $new_attachment_post->post_title ??= $original_attachment_post->post_title ?? $image_name;
// Set new attachment post caption (post_excerpt).
- $new_attachment_post->post_excerpt = $new_attachment_post->post_excerpt ?? $original_attachment_post->post_excerpt ?? '';
+ $new_attachment_post->post_excerpt ??= $original_attachment_post->post_excerpt ?? '';
// Set new attachment post description (post_content) with fallbacks.
- $new_attachment_post->post_content = $new_attachment_post->post_content ?? $original_attachment_post->post_content ?? '';
+ $new_attachment_post->post_content ??= $original_attachment_post->post_content ?? '';
// Set post parent if set in request, else the default of `0` (no parent).
- $new_attachment_post->post_parent = $new_attachment_post->post_parent ?? 0;
+ $new_attachment_post->post_parent ??= 0;
// Insert the new attachment post.
$new_attachment_id = wp_insert_attachment( wp_slash( (array) $new_attachment_post ), $saved['path'], 0, true );
@@ -1525,7 +1525,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
$metadata = array();
}
- $metadata['sizes'] = $metadata['sizes'] ?? array();
+ $metadata['sizes'] ??= array();
$fallback_sizes = array(
'thumbnail',
@@ -3299,7 +3299,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
continue;
}
- $metadata['sizes'] = $metadata['sizes'] ?? array();
+ $metadata['sizes'] ??= array();
foreach ( $image_size as $name ) {
$metadata['sizes'][ $name ] = array(
@@ -3384,7 +3384,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
continue;
}
- $metadata['sizes'] = $metadata['sizes'] ?? array();
+ $metadata['sizes'] ??= array();
$metadata['sizes'][ $image_size ] = array(
'width' => $sub_size['width'] ?? 0,
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 0f42e24a08..454d8a6488 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63507';
+$wp_version = '7.2-alpha-63509';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php
index fb4f3d2b05..7661e6d3f4 100644
--- a/wp-includes/widgets.php
+++ b/wp-includes/widgets.php
@@ -1720,9 +1720,9 @@ function wp_widget_rss_form( $args, $inputs = null ) {
);
$inputs = wp_parse_args( $inputs, $default_inputs );
- $args['title'] = $args['title'] ?? '';
- $args['url'] = $args['url'] ?? '';
- $args['items'] = (int) ( $args['items'] ?? 0 );
+ $args['title'] ??= '';
+ $args['url'] ??= '';
+ $args['items'] = (int) ( $args['items'] ?? 0 );
if ( $args['items'] < 1 || 20 < $args['items'] ) {
$args['items'] = 10;