Commit 014b3f1f76 for wordpress.org

commit 014b3f1f7697b129687791e4ee607cf180fa5cdf
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date:   Sat Sep 5 12:44:49 2026 +0000

    Code Modernization: Use the null coalescing assignment operator for default value assignments.

    Replacing further `isset()`/`null` guards that assign a default value with the null coalescing assignment operator (`??=`):

    {{{
    // Before
    if ( ! isset( $size_data['width'] ) ) {
            $size_data['width'] = null;
    }

    if ( ! isset( $size_data['height'] ) ) {
            $size_data['height'] = null;
    }

    if ( ! isset( $size_data['crop'] ) ) {
            $size_data['crop'] = false;
    }


    // After
    $size_data['width']  ??= null;
    $size_data['height'] ??= null;
    $size_data['crop']   ??= false;
    }}}

    Both forms are functionally identical; `??=` is shorter and turns a nine-line block into three lines that read as a single list of defaults.

    **Scope**

    This is deliberately limited to blocks where ''every'' guard in a contiguous run can be converted, so no mixed styles are left behind within one function:

    - `WP_Image_Editor_GD::resize()` and `WP_Image_Editor_Imagick::resize()` — the `$size_data` defaults (identical blocks in both classes).
    - `WP_Date_Query::build_mysql_datetime()` — the `$datetime` defaults.
    - `WP_Translation_Controller` — the `$locale` fallback in `load_file()`, `is_textdomain_loaded()`, `get_files()` and `has_translation()`.
    - `register_post_status()` — the `$args` defaults.

    **Why this is safe**

    - `??=` requires PHP 7.4, which is already the minimum supported version.
    - `??=` and `! isset()` test the same condition, so the default is applied in exactly the same cases.
    - Assignment order is preserved everywhere it matters. In `register_post_status()` the compound guard above the block is left untouched and still runs first, `$args->internal ??= false;` still follows it, and `publicly_queryable` is still derived after `public` has been resolved.
    - In `WP_Date_Query::build_mysql_datetime()` the preceding `array_map( 'absint', $datetime )` turns any existing `null` into `0`, which both `isset()` and `??=` treat as set.
    - No behavior change.

    **Not converted**

    Similar runs in `WP_Query::parse_query()`, `WP_Post_Type::set_props()` and `WP_Taxonomy::set_props()` contain guards that cannot be expressed as `??=` — an `elseif` branch in the first case, compound conditions such as `if ( null === $args['show_in_menu'] || ! $args['show_ui'] )` in the other two. Converting only the neighbouring guards would leave two styles interleaved in the same block, so those are left alone.

    Developed in https://github.com/WordPress/wordpress-develop/pull/12911.

    Follow-up to r63443.

    Props Soean, mukesh27.
    See #65823.
    Built from https://develop.svn.wordpress.org/trunk@63501


    git-svn-id: http://core.svn.wordpress.org/trunk@62677 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/class-wp-date-query.php b/wp-includes/class-wp-date-query.php
index 063d1a2f3d..4a6e6ca2ed 100644
--- a/wp-includes/class-wp-date-query.php
+++ b/wp-includes/class-wp-date-query.php
@@ -933,29 +933,12 @@ class WP_Date_Query {

 		$datetime = array_map( 'absint', $datetime );

-		if ( ! isset( $datetime['year'] ) ) {
-			$datetime['year'] = current_time( 'Y' );
-		}
-
-		if ( ! isset( $datetime['month'] ) ) {
-			$datetime['month'] = ( $default_to_max ) ? 12 : 1;
-		}
-
-		if ( ! isset( $datetime['day'] ) ) {
-			$datetime['day'] = ( $default_to_max ) ? (int) gmdate( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1;
-		}
-
-		if ( ! isset( $datetime['hour'] ) ) {
-			$datetime['hour'] = ( $default_to_max ) ? 23 : 0;
-		}
-
-		if ( ! isset( $datetime['minute'] ) ) {
-			$datetime['minute'] = ( $default_to_max ) ? 59 : 0;
-		}
-
-		if ( ! isset( $datetime['second'] ) ) {
-			$datetime['second'] = ( $default_to_max ) ? 59 : 0;
-		}
+		$datetime['year']   ??= current_time( 'Y' );
+		$datetime['month']  ??= ( $default_to_max ) ? 12 : 1;
+		$datetime['day']    ??= ( $default_to_max ) ? (int) gmdate( 't', mktime( 0, 0, 0, $datetime['month'], 1, $datetime['year'] ) ) : 1;
+		$datetime['hour']   ??= ( $default_to_max ) ? 23 : 0;
+		$datetime['minute'] ??= ( $default_to_max ) ? 59 : 0;
+		$datetime['second'] ??= ( $default_to_max ) ? 59 : 0;

 		return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $datetime['year'], $datetime['month'], $datetime['day'], $datetime['hour'], $datetime['minute'], $datetime['second'] );
 	}
diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php
index 3d93b5bd8a..34c0453ff6 100644
--- a/wp-includes/class-wp-image-editor-gd.php
+++ b/wp-includes/class-wp-image-editor-gd.php
@@ -312,17 +312,9 @@ class WP_Image_Editor_GD extends WP_Image_Editor {

 		$orig_size = $this->size;

-		if ( ! isset( $size_data['width'] ) ) {
-			$size_data['width'] = null;
-		}
-
-		if ( ! isset( $size_data['height'] ) ) {
-			$size_data['height'] = null;
-		}
-
-		if ( ! isset( $size_data['crop'] ) ) {
-			$size_data['crop'] = false;
-		}
+		$size_data['width']  ??= null;
+		$size_data['height'] ??= null;
+		$size_data['crop']   ??= false;

 		$resized = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );

diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php
index b2d6b374e3..0be31905ea 100644
--- a/wp-includes/class-wp-image-editor-imagick.php
+++ b/wp-includes/class-wp-image-editor-imagick.php
@@ -875,17 +875,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
 		$orig_size  = $this->size;
 		$orig_image = $this->image->getImage();

-		if ( ! isset( $size_data['width'] ) ) {
-			$size_data['width'] = null;
-		}
-
-		if ( ! isset( $size_data['height'] ) ) {
-			$size_data['height'] = null;
-		}
-
-		if ( ! isset( $size_data['crop'] ) ) {
-			$size_data['crop'] = false;
-		}
+		$size_data['width']  ??= null;
+		$size_data['height'] ??= null;
+		$size_data['crop']   ??= false;

 		if ( ( $this->size['width'] === $size_data['width'] ) && ( $this->size['height'] === $size_data['height'] ) ) {
 			return new WP_Error( 'image_subsize_create_error', __( 'The image already has the requested size.' ) );
diff --git a/wp-includes/l10n/class-wp-translation-controller.php b/wp-includes/l10n/class-wp-translation-controller.php
index 7ccec6f6e1..60ccab87dd 100644
--- a/wp-includes/l10n/class-wp-translation-controller.php
+++ b/wp-includes/l10n/class-wp-translation-controller.php
@@ -97,9 +97,7 @@ final class WP_Translation_Controller {
 	 * @return bool True on success, false otherwise.
 	 */
 	public function load_file( string $translation_file, string $textdomain = 'default', ?string $locale = null ): bool {
-		if ( null === $locale ) {
-			$locale = $this->current_locale;
-		}
+		$locale ??= $this->current_locale;

 		$translation_file = realpath( $translation_file );

@@ -239,9 +237,7 @@ final class WP_Translation_Controller {
 	 * @return bool True if there are any loaded translations, false otherwise.
 	 */
 	public function is_textdomain_loaded( string $textdomain = 'default', ?string $locale = null ): bool {
-		if ( null === $locale ) {
-			$locale = $this->current_locale;
-		}
+		$locale ??= $this->current_locale;

 		return isset( $this->loaded_translations[ $locale ][ $textdomain ] ) &&
 			array() !== $this->loaded_translations[ $locale ][ $textdomain ];
@@ -426,9 +422,7 @@ final class WP_Translation_Controller {
 	 * @return WP_Translation_File[] List of translation files.
 	 */
 	protected function get_files( string $textdomain = 'default', ?string $locale = null ): array {
-		if ( null === $locale ) {
-			$locale = $this->current_locale;
-		}
+		$locale ??= $this->current_locale;

 		return $this->loaded_translations[ $locale ][ $textdomain ] ?? array();
 	}
@@ -444,9 +438,7 @@ final class WP_Translation_Controller {
 	 * @return bool  True if the translation exists, false otherwise.
 	 */
 	public function has_translation( string $singular, string $textdomain = 'default', ?string $locale = null ): bool {
-		if ( null === $locale ) {
-			$locale = $this->current_locale;
-		}
+		$locale ??= $this->current_locale;

 		return false !== $this->locate_translation( $singular, $textdomain, $locale );
 	}
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 87c4e9627b..aeea4e5baf 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -1487,41 +1487,15 @@ function register_post_status( $post_status, $args = array() ) {
 		$args->internal = true;
 	}

-	if ( null === $args->public ) {
-		$args->public = false;
-	}
-
-	if ( null === $args->private ) {
-		$args->private = false;
-	}
-
-	if ( null === $args->protected ) {
-		$args->protected = false;
-	}
-
-	if ( null === $args->internal ) {
-		$args->internal = false;
-	}
-
-	if ( null === $args->publicly_queryable ) {
-		$args->publicly_queryable = $args->public;
-	}
-
-	if ( null === $args->exclude_from_search ) {
-		$args->exclude_from_search = $args->internal;
-	}
-
-	if ( null === $args->show_in_admin_all_list ) {
-		$args->show_in_admin_all_list = ! $args->internal;
-	}
-
-	if ( null === $args->show_in_admin_status_list ) {
-		$args->show_in_admin_status_list = ! $args->internal;
-	}
-
-	if ( null === $args->date_floating ) {
-		$args->date_floating = false;
-	}
+	$args->public                    ??= false;
+	$args->private                   ??= false;
+	$args->protected                 ??= false;
+	$args->internal                  ??= false;
+	$args->publicly_queryable        ??= $args->public;
+	$args->exclude_from_search       ??= $args->internal;
+	$args->show_in_admin_all_list    ??= ! $args->internal;
+	$args->show_in_admin_status_list ??= ! $args->internal;
+	$args->date_floating             ??= false;

 	if ( false === $args->label ) {
 		$args->label = $post_status;
diff --git a/wp-includes/version.php b/wp-includes/version.php
index dd33c0fb79..7975d09ff9 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.2-alpha-63500';
+$wp_version = '7.2-alpha-63501';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.