Code Modernization: Use null coalescing operator instead of isset() ternaries in remaining core files.

Developed as a subset of https://github.com/WordPress/wordpress-develop/pull/10654
Initially developed in https://github.com/WordPress/wordpress-develop/pull/4886

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

Props costdev, westonruter, jrf, SergeyBiryukov, swissspidy, hellofromTonya, marybaum, oglekler, dmsnell, chaion07, noisysocks, mukesh27.
See #63430.
Fixes #58874.

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


git-svn-id: http://core.svn.wordpress.org/trunk@60769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2026-01-09 04:28:52 +00:00
parent 87cd08d8a4
commit 4cbb4971f2
10 changed files with 51 additions and 61 deletions

View File

@@ -31,8 +31,8 @@ class IXR_Client
// Assume we have been given a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->port = isset($bits['port']) ? $bits['port'] : 80;
$this->path = isset($bits['path']) ? $bits['path'] : '/';
$this->port = $bits['port'] ?? 80;
$this->path = $bits['path'] ?? '/';
// Make absolutely sure we have a path
if (!$this->path) {

View File

@@ -209,7 +209,7 @@ class WP_Duotone {
'rad' => 360 / ( M_PI * 2 ),
);
$factor = isset( $angle_units[ $unit ] ) ? $angle_units[ $unit ] : 1;
$factor = $angle_units[ $unit ] ?? 1;
return (float) $value * $factor;
}
@@ -972,9 +972,7 @@ class WP_Duotone {
* If the experimental duotone support was set, that value is to be
* treated as a selector and requires scoping.
*/
$experimental_duotone = isset( $block_type->supports['color']['__experimentalDuotone'] )
? $block_type->supports['color']['__experimentalDuotone']
: false;
$experimental_duotone = $block_type->supports['color']['__experimentalDuotone'] ?? false;
if ( $experimental_duotone ) {
$root_selector = wp_get_block_css_selector( $block_type );
return is_string( $experimental_duotone )
@@ -1003,7 +1001,7 @@ class WP_Duotone {
}
// Get the per block settings from the theme.json.
$tree = wp_get_global_settings();
$presets_by_origin = isset( $tree['color']['duotone'] ) ? $tree['color']['duotone'] : array();
$presets_by_origin = $tree['color']['duotone'] ?? array();
self::$global_styles_presets = array();
foreach ( $presets_by_origin as $presets ) {
@@ -1304,9 +1302,7 @@ class WP_Duotone {
* @return array Filtered block type settings.
*/
public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
$duotone_support = isset( $metadata['supports']['color']['__experimentalDuotone'] )
? $metadata['supports']['color']['__experimentalDuotone']
: null;
$duotone_support = $metadata['supports']['color']['__experimentalDuotone'] ?? null;
if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
_wp_array_set( $settings, array( 'supports', 'filter', 'duotone' ), (bool) $duotone_support );

View File

@@ -492,7 +492,7 @@ final class WP_Hook implements Iterator, ArrayAccess {
*/
#[ReturnTypeWillChange]
public function offsetGet( $offset ) {
return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null;
return $this->callbacks[ $offset ] ?? null;
}
/**

View File

@@ -515,7 +515,7 @@ final class WP_Theme implements ArrayAccess {
return;
}
// Set the parent. Pass the current instance so we can do the checks above and assess errors.
$this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this );
$this->parent = new WP_Theme( $this->template, $theme_root_template ?? $this->theme_root, $this );
}
if ( wp_paused_themes()->get( $this->stylesheet ) && ( ! is_wp_error( $this->errors ) || ! isset( $this->errors->errors['theme_paused'] ) ) ) {
@@ -776,7 +776,7 @@ final class WP_Theme implements ArrayAccess {
* @return WP_Theme|false Parent theme, or false if the active theme is not a child theme.
*/
public function parent() {
return isset( $this->parent ) ? $this->parent : false;
return $this->parent ?? false;
}
/**
@@ -1397,7 +1397,7 @@ final class WP_Theme implements ArrayAccess {
}
$post_templates = $this->get_post_templates();
$post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
$post_templates = $post_templates[ $post_type ] ?? array();
/**
* Filters list of page templates for a theme.

View File

@@ -8,13 +8,13 @@
return array(
array(
'handle' => 'wp-nux',
'path' => 'nux/style',
'handle' => 'wp-list-reusable-blocks',
'path' => 'list-reusable-blocks/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-list-reusable-blocks',
'path' => 'list-reusable-blocks/style',
'handle' => 'wp-nux',
'path' => 'nux/style',
'dependencies' => array('wp-components'),
),
array(
@@ -22,14 +22,19 @@ return array(
'path' => 'preferences/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-reusable-blocks',
'path' => 'reusable-blocks/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-commands',
'path' => 'commands/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-reusable-blocks',
'path' => 'reusable-blocks/style',
'handle' => 'wp-patterns',
'path' => 'patterns/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
@@ -42,59 +47,54 @@ return array(
'path' => 'components/style',
'dependencies' => array(),
),
array(
'handle' => 'wp-patterns',
'path' => 'patterns/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-format-library',
'path' => 'format-library/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-block-directory',
'path' => 'block-directory/style',
'dependencies' => array('wp-block-editor', 'wp-components', 'wp-editor'),
),
array(
'handle' => 'wp-media-utils',
'path' => 'media-utils/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-edit-widgets',
'path' => 'edit-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
'handle' => 'wp-block-directory',
'path' => 'block-directory/style',
'dependencies' => array('wp-block-editor', 'wp-components', 'wp-editor'),
),
array(
'handle' => 'wp-customize-widgets',
'path' => 'customize-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-edit-post',
'path' => 'edit-post/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-block-library',
'path' => 'block-library/style',
'dependencies' => array('wp-block-editor', 'wp-components', 'wp-patterns'),
),
array(
'handle' => 'wp-edit-widgets',
'path' => 'edit-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-edit-post',
'path' => 'edit-post/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-editor',
'path' => 'editor/style',
'dependencies' => array('wp-block-editor', 'wp-commands', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences'),
),
array(
'handle' => 'wp-edit-site',
'path' => 'edit-site/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-block-editor',
'path' => 'block-editor/style',
'dependencies' => array('wp-commands', 'wp-components', 'wp-preferences'),
),
array(
'handle' => 'wp-edit-site',
'path' => 'edit-site/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
);

View File

@@ -4264,9 +4264,7 @@ function wp_render_duotone_filter_preset( $preset ) {
function wp_skip_border_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$border_support = isset( $block_type->supports['__experimentalBorder'] )
? $block_type->supports['__experimentalBorder']
: false;
$border_support = $block_type->supports['__experimentalBorder'] ?? false;
return is_array( $border_support ) &&
array_key_exists( '__experimentalSkipSerialization', $border_support ) &&
@@ -4288,9 +4286,7 @@ function wp_skip_border_serialization( $block_type ) {
function wp_skip_dimensions_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$dimensions_support = isset( $block_type->supports['__experimentalDimensions'] )
? $block_type->supports['__experimentalDimensions']
: false;
$dimensions_support = $block_type->supports['__experimentalDimensions'] ?? false;
return is_array( $dimensions_support ) &&
array_key_exists( '__experimentalSkipSerialization', $dimensions_support ) &&
@@ -4312,9 +4308,7 @@ function wp_skip_dimensions_serialization( $block_type ) {
function wp_skip_spacing_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$spacing_support = isset( $block_type->supports['spacing'] )
? $block_type->supports['spacing']
: false;
$spacing_support = $block_type->supports['spacing'] ?? false;
return is_array( $spacing_support ) &&
array_key_exists( '__experimentalSkipSerialization', $spacing_support ) &&

View File

@@ -7,6 +7,11 @@
*/
return array(
array(
'id' => '@wordpress/core-abilities',
'path' => 'core-abilities/index',
'asset' => 'core-abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/interactivity',
'path' => 'interactivity/index',
@@ -22,11 +27,6 @@ return array(
'path' => 'interactivity-router/full-page',
'asset' => 'interactivity-router/full-page.min.asset.php',
),
array(
'id' => '@wordpress/core-abilities',
'path' => 'core-abilities/index',
'asset' => 'core-abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/a11y',
'path' => 'a11y/index',

View File

@@ -1722,7 +1722,7 @@ if ( ! function_exists( 'wp_validate_redirect' ) ) :
* @param string[] $hosts An array of allowed host names.
* @param string $host The host name of the redirect destination; empty string if not set.
*/
$allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), isset( $lp['host'] ) ? $lp['host'] : '' );
$allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), $lp['host'] ?? '' );
if ( isset( $lp['host'] ) && ( ! in_array( $lp['host'], $allowed_hosts, true ) && strtolower( $wpp['host'] ) !== $lp['host'] ) ) {
$location = $fallback_url;

View File

@@ -1104,7 +1104,7 @@ function get_theme_mod( $name, $default_value = false ) {
*/
function set_theme_mod( $name, $value ) {
$mods = get_theme_mods();
$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;
$old_value = $mods[ $name ] ?? false;
/**
* Filters the theme modification, or 'theme_mod', value on save.
@@ -3428,7 +3428,7 @@ function get_registered_theme_feature( $feature ) {
return null;
}
return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
return $_wp_registered_theme_features[ $feature ] ?? null;
}
/**

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61456';
$wp_version = '7.0-alpha-61457';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.