Skip to content

Commit 76ca772

Browse files
committed
Code Modernization: Use null coalescing operator instead of isset() ternaries in remaining core files.
Developed as a subset of #10654 Initially developed in #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. git-svn-id: https://develop.svn.wordpress.org/trunk@61457 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e800ced commit 76ca772

File tree

7 files changed

+16
-26
lines changed

7 files changed

+16
-26
lines changed

src/wp-includes/IXR/class-IXR-client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function __construct( $server, $path = false, $port = 80, $timeout = 15 )
3131
// Assume we have been given a URL instead
3232
$bits = parse_url($server);
3333
$this->server = $bits['host'];
34-
$this->port = isset($bits['port']) ? $bits['port'] : 80;
35-
$this->path = isset($bits['path']) ? $bits['path'] : '/';
34+
$this->port = $bits['port'] ?? 80;
35+
$this->path = $bits['path'] ?? '/';
3636

3737
// Make absolutely sure we have a path
3838
if (!$this->path) {

src/wp-includes/class-wp-duotone.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private static function colord_parse_hue( $value, $unit = 'deg' ) {
209209
'rad' => 360 / ( M_PI * 2 ),
210210
);
211211

212-
$factor = isset( $angle_units[ $unit ] ) ? $angle_units[ $unit ] : 1;
212+
$factor = $angle_units[ $unit ] ?? 1;
213213

214214
return (float) $value * $factor;
215215
}
@@ -972,9 +972,7 @@ private static function get_selector( $block_type ) {
972972
* If the experimental duotone support was set, that value is to be
973973
* treated as a selector and requires scoping.
974974
*/
975-
$experimental_duotone = isset( $block_type->supports['color']['__experimentalDuotone'] )
976-
? $block_type->supports['color']['__experimentalDuotone']
977-
: false;
975+
$experimental_duotone = $block_type->supports['color']['__experimentalDuotone'] ?? false;
978976
if ( $experimental_duotone ) {
979977
$root_selector = wp_get_block_css_selector( $block_type );
980978
return is_string( $experimental_duotone )
@@ -1003,7 +1001,7 @@ private static function get_all_global_styles_presets() {
10031001
}
10041002
// Get the per block settings from the theme.json.
10051003
$tree = wp_get_global_settings();
1006-
$presets_by_origin = isset( $tree['color']['duotone'] ) ? $tree['color']['duotone'] : array();
1004+
$presets_by_origin = $tree['color']['duotone'] ?? array();
10071005

10081006
self::$global_styles_presets = array();
10091007
foreach ( $presets_by_origin as $presets ) {
@@ -1304,9 +1302,7 @@ public static function add_editor_settings( $settings ) {
13041302
* @return array Filtered block type settings.
13051303
*/
13061304
public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
1307-
$duotone_support = isset( $metadata['supports']['color']['__experimentalDuotone'] )
1308-
? $metadata['supports']['color']['__experimentalDuotone']
1309-
: null;
1305+
$duotone_support = $metadata['supports']['color']['__experimentalDuotone'] ?? null;
13101306

13111307
if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
13121308
_wp_array_set( $settings, array( 'supports', 'filter', 'duotone' ), (bool) $duotone_support );

src/wp-includes/class-wp-hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public function offsetExists( $offset ) {
492492
*/
493493
#[ReturnTypeWillChange]
494494
public function offsetGet( $offset ) {
495-
return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null;
495+
return $this->callbacks[ $offset ] ?? null;
496496
}
497497

498498
/**

src/wp-includes/class-wp-theme.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function __construct( $theme_dir, $theme_root, $_child = null ) {
515515
return;
516516
}
517517
// Set the parent. Pass the current instance so we can do the checks above and assess errors.
518-
$this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this );
518+
$this->parent = new WP_Theme( $this->template, $theme_root_template ?? $this->theme_root, $this );
519519
}
520520

521521
if ( wp_paused_themes()->get( $this->stylesheet ) && ( ! is_wp_error( $this->errors ) || ! isset( $this->errors->errors['theme_paused'] ) ) ) {
@@ -776,7 +776,7 @@ public function exists() {
776776
* @return WP_Theme|false Parent theme, or false if the active theme is not a child theme.
777777
*/
778778
public function parent() {
779-
return isset( $this->parent ) ? $this->parent : false;
779+
return $this->parent ?? false;
780780
}
781781

782782
/**
@@ -1397,7 +1397,7 @@ public function get_page_templates( $post = null, $post_type = 'page' ) {
13971397
}
13981398

13991399
$post_templates = $this->get_post_templates();
1400-
$post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array();
1400+
$post_templates = $post_templates[ $post_type ] ?? array();
14011401

14021402
/**
14031403
* Filters list of page templates for a theme.

src/wp-includes/deprecated.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,9 +4264,7 @@ function wp_render_duotone_filter_preset( $preset ) {
42644264
function wp_skip_border_serialization( $block_type ) {
42654265
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
42664266

4267-
$border_support = isset( $block_type->supports['__experimentalBorder'] )
4268-
? $block_type->supports['__experimentalBorder']
4269-
: false;
4267+
$border_support = $block_type->supports['__experimentalBorder'] ?? false;
42704268

42714269
return is_array( $border_support ) &&
42724270
array_key_exists( '__experimentalSkipSerialization', $border_support ) &&
@@ -4288,9 +4286,7 @@ function wp_skip_border_serialization( $block_type ) {
42884286
function wp_skip_dimensions_serialization( $block_type ) {
42894287
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
42904288

4291-
$dimensions_support = isset( $block_type->supports['__experimentalDimensions'] )
4292-
? $block_type->supports['__experimentalDimensions']
4293-
: false;
4289+
$dimensions_support = $block_type->supports['__experimentalDimensions'] ?? false;
42944290

42954291
return is_array( $dimensions_support ) &&
42964292
array_key_exists( '__experimentalSkipSerialization', $dimensions_support ) &&
@@ -4312,9 +4308,7 @@ function wp_skip_dimensions_serialization( $block_type ) {
43124308
function wp_skip_spacing_serialization( $block_type ) {
43134309
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
43144310

4315-
$spacing_support = isset( $block_type->supports['spacing'] )
4316-
? $block_type->supports['spacing']
4317-
: false;
4311+
$spacing_support = $block_type->supports['spacing'] ?? false;
43184312

43194313
return is_array( $spacing_support ) &&
43204314
array_key_exists( '__experimentalSkipSerialization', $spacing_support ) &&

src/wp-includes/pluggable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ function wp_validate_redirect( $location, $fallback_url = '' ) {
17221722
* @param string[] $hosts An array of allowed host names.
17231723
* @param string $host The host name of the redirect destination; empty string if not set.
17241724
*/
1725-
$allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), isset( $lp['host'] ) ? $lp['host'] : '' );
1725+
$allowed_hosts = (array) apply_filters( 'allowed_redirect_hosts', array( $wpp['host'] ), $lp['host'] ?? '' );
17261726

17271727
if ( isset( $lp['host'] ) && ( ! in_array( $lp['host'], $allowed_hosts, true ) && strtolower( $wpp['host'] ) !== $lp['host'] ) ) {
17281728
$location = $fallback_url;

src/wp-includes/theme.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ function get_theme_mod( $name, $default_value = false ) {
11041104
*/
11051105
function set_theme_mod( $name, $value ) {
11061106
$mods = get_theme_mods();
1107-
$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;
1107+
$old_value = $mods[ $name ] ?? false;
11081108

11091109
/**
11101110
* Filters the theme modification, or 'theme_mod', value on save.
@@ -3428,7 +3428,7 @@ function get_registered_theme_feature( $feature ) {
34283428
return null;
34293429
}
34303430

3431-
return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
3431+
return $_wp_registered_theme_features[ $feature ] ?? null;
34323432
}
34333433

34343434
/**

0 commit comments

Comments
 (0)