From 71cb111109adb29ace47747634e4532433fea502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Thu, 6 Aug 2026 15:02:24 +0200 Subject: [PATCH] Code Quality: Use the null coalescing assignment operator for array initialization. Replace `if ( ! isset( $x ) ) { $x = array(); }` with `$x ??= array();`, using the null coalescing assignment operator introduced in PHP 7.4. --- src/wp-admin/includes/dashboard.php | 4 +-- src/wp-admin/includes/nav-menu.php | 4 +-- src/wp-admin/includes/post.php | 4 +-- src/wp-admin/includes/template.php | 28 +++++-------------- src/wp-admin/includes/widgets.php | 4 +-- src/wp-includes/block-supports/anchor.php | 4 +-- src/wp-includes/block-template-utils.php | 4 +-- src/wp-includes/blocks.php | 12 ++------ src/wp-includes/capabilities.php | 8 ++---- .../class-wp-block-styles-registry.php | 4 +-- .../class-wp-customize-manager.php | 16 +++-------- .../class-wp-customize-nav-menus.php | 4 +-- .../class-wp-customize-setting.php | 8 ++---- .../class-wp-customize-widgets.php | 10 ++----- src/wp-includes/class-wp-duotone.php | 4 +-- .../class-wp-metadata-lazyloader.php | 4 +-- src/wp-includes/class-wp-query.php | 10 ++----- .../class-wp-speculation-rules.php | 4 +-- src/wp-includes/class-wp-tax-query.php | 6 ++-- src/wp-includes/class-wp-theme-json.php | 4 +-- src/wp-includes/class-wp-theme.php | 6 ++-- src/wp-includes/class-wp-token-map.php | 4 +-- ...ass-wp-customize-nav-menu-item-setting.php | 4 +-- .../class-wp-customize-nav-menu-setting.php | 14 +++------- ...class-wp-widget-form-customize-control.php | 6 ++-- src/wp-includes/general-template.php | 4 +-- .../class-wp-interactivity-api.php | 12 ++------ .../l10n/class-wp-translation-controller.php | 4 +-- src/wp-includes/meta.php | 6 ++-- src/wp-includes/plugin.php | 12 ++------ .../rest-api/class-wp-rest-request.php | 4 +-- .../rest-api/class-wp-rest-server.php | 4 +-- .../class-wp-rest-attachments-controller.php | 4 +-- .../class-wp-rest-menus-controller.php | 4 +-- src/wp-includes/taxonomy.php | 20 ++++--------- 35 files changed, 69 insertions(+), 185 deletions(-) diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 0fe5c62064b64..cfed8f0a064c2 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -1274,9 +1274,7 @@ function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { $widget_options = array(); } - if ( ! isset( $widget_options[ $widget_id ] ) ) { - $widget_options[ $widget_id ] = array(); - } + $widget_options[ $widget_id ] ??= array(); $number = 1; // Hack to use wp_widget_rss_form(). diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index f26d63d528e78..dc90feb3b3309 100644 --- a/src/wp-admin/includes/nav-menu.php +++ b/src/wp-admin/includes/nav-menu.php @@ -1483,9 +1483,7 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte $auto_add = ! empty( $_POST['auto-add-pages'] ); $nav_menu_option = (array) get_option( 'nav_menu_options' ); - if ( ! isset( $nav_menu_option['auto_add'] ) ) { - $nav_menu_option['auto_add'] = array(); - } + $nav_menu_option['auto_add'] ??= array(); if ( $auto_add ) { if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) { diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 39d267b623037..9b60abf886ab4 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -2335,9 +2335,7 @@ function get_block_editor_server_block_settings() { continue; } - if ( ! isset( $blocks[ $block_name ] ) ) { - $blocks[ $block_name ] = array(); - } + $blocks[ $block_name ] ??= array(); $blocks[ $block_name ][ $key ] = $block_type->{ $field }; } diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 418bfd7def697..2d29418322c94 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -1098,15 +1098,9 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan $page = $screen->id; - if ( ! isset( $wp_meta_boxes ) ) { - $wp_meta_boxes = array(); - } - if ( ! isset( $wp_meta_boxes[ $page ] ) ) { - $wp_meta_boxes[ $page ] = array(); - } - if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { - $wp_meta_boxes[ $page ][ $context ] = array(); - } + $wp_meta_boxes ??= array(); + $wp_meta_boxes[ $page ] ??= array(); + $wp_meta_boxes[ $page ][ $context ] ??= array(); foreach ( array_keys( $wp_meta_boxes[ $page ] ) as $a_context ) { foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { @@ -1158,9 +1152,7 @@ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advan $priority = 'low'; } - if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { - $wp_meta_boxes[ $page ][ $context ][ $priority ] = array(); - } + $wp_meta_boxes[ $page ][ $context ][ $priority ] ??= array(); $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = array( 'id' => $id, @@ -1502,15 +1494,9 @@ function remove_meta_box( $id, $screen, $context ) { $page = $screen->id; - if ( ! isset( $wp_meta_boxes ) ) { - $wp_meta_boxes = array(); - } - if ( ! isset( $wp_meta_boxes[ $page ] ) ) { - $wp_meta_boxes[ $page ] = array(); - } - if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { - $wp_meta_boxes[ $page ][ $context ] = array(); - } + $wp_meta_boxes ??= array(); + $wp_meta_boxes[ $page ] ??= array(); + $wp_meta_boxes[ $page ][ $context ] ??= array(); foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false; diff --git a/src/wp-admin/includes/widgets.php b/src/wp-admin/includes/widgets.php index e751602866b0d..c4510931411c8 100644 --- a/src/wp-admin/includes/widgets.php +++ b/src/wp-admin/includes/widgets.php @@ -29,9 +29,7 @@ function wp_list_widgets() { $sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false ); $done[] = $widget['callback']; - if ( ! isset( $widget['params'][0] ) ) { - $widget['params'][0] = array(); - } + $widget['params'][0] ??= array(); $args = array( 'widget_id' => $widget['id'], diff --git a/src/wp-includes/block-supports/anchor.php b/src/wp-includes/block-supports/anchor.php index 657234f8cbf6c..c6eceea13669c 100644 --- a/src/wp-includes/block-supports/anchor.php +++ b/src/wp-includes/block-supports/anchor.php @@ -19,9 +19,7 @@ function wp_register_anchor_support( WP_Block_Type $block_type ) { return; } - if ( ! isset( $block_type->attributes ) ) { - $block_type->attributes = array(); - } + $block_type->attributes ??= array(); if ( ! array_key_exists( 'anchor', $block_type->attributes ) ) { $block_type->attributes['anchor'] = array( diff --git a/src/wp-includes/block-template-utils.php b/src/wp-includes/block-template-utils.php index a7d5d4aa1141d..843aa55ce431e 100644 --- a/src/wp-includes/block-template-utils.php +++ b/src/wp-includes/block-template-utils.php @@ -1783,9 +1783,7 @@ function inject_ignored_hooked_blocks_metadata_attributes( $changes, $deprecated $wrapper_block = parse_blocks( $wrapper_block_markup )[0]; $ignored_hooked_blocks = $wrapper_block['attrs']['metadata']['ignoredHookedBlocks'] ?? array(); if ( ! empty( $ignored_hooked_blocks ) ) { - if ( ! isset( $changes->meta_input ) ) { - $changes->meta_input = array(); - } + $changes->meta_input ??= array(); $changes->meta_input['_wp_ignored_hooked_blocks'] = wp_json_encode( $ignored_hooked_blocks ); } } else { diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index a0360ffdc8bf8..89d47891af435 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -979,12 +979,8 @@ function get_hooked_blocks() { continue; } foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) { - if ( ! isset( $hooked_blocks[ $anchor_block_type ] ) ) { - $hooked_blocks[ $anchor_block_type ] = array(); - } - if ( ! isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) ) { - $hooked_blocks[ $anchor_block_type ][ $relative_position ] = array(); - } + $hooked_blocks[ $anchor_block_type ] ??= array(); + $hooked_blocks[ $anchor_block_type ][ $relative_position ] ??= array(); $hooked_blocks[ $anchor_block_type ][ $relative_position ][] = $block_type->name; } } @@ -1490,9 +1486,7 @@ function update_ignored_hooked_blocks_postmeta( $post ) { $ignored_hooked_blocks = array_unique( array_merge( $ignored_hooked_blocks, $existing_ignored_hooked_blocks ) ); } - if ( ! isset( $post->meta_input ) ) { - $post->meta_input = array(); - } + $post->meta_input ??= array(); $post->meta_input['_wp_ignored_hooked_blocks'] = json_encode( $ignored_hooked_blocks ); } diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php index 645ab5588ee5e..3d92ee7357bbc 100644 --- a/src/wp-includes/capabilities.php +++ b/src/wp-includes/capabilities.php @@ -830,11 +830,9 @@ function map_meta_cap( $cap, $user_id, ...$args ) { } $post_type_object = get_post_type_object( $object_subtype ); // Initialize empty array if it doesn't exist. - if ( ! isset( $post_type_object->capabilities ) ) { - $post_type_object->capabilities = array(); - } - $post_type_capabilities = get_post_type_capabilities( $post_type_object ); - $caps = map_meta_cap( $post_type_capabilities->edit_post, $user_id, $object_id ); + $post_type_object->capabilities ??= array(); + $post_type_capabilities = get_post_type_capabilities( $post_type_object ); + $caps = map_meta_cap( $post_type_capabilities->edit_post, $user_id, $object_id ); break; default: // Handle meta capabilities for custom post types. diff --git a/src/wp-includes/class-wp-block-styles-registry.php b/src/wp-includes/class-wp-block-styles-registry.php index 9efdb30157235..78c4b56701824 100644 --- a/src/wp-includes/class-wp-block-styles-registry.php +++ b/src/wp-includes/class-wp-block-styles-registry.php @@ -99,9 +99,7 @@ public function register( $block_name, $style_properties ) { } foreach ( $block_names as $name ) { - if ( ! isset( $this->registered_block_styles[ $name ] ) ) { - $this->registered_block_styles[ $name ] = array(); - } + $this->registered_block_styles[ $name ] ??= array(); $this->registered_block_styles[ $name ][ $block_style_name ] = $style_properties; } diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index e298b04efcf90..df07511b8dd8e 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -2817,9 +2817,7 @@ public function save_changeset_post( $args = array() ) { // Ensure that all post values are included in the changeset data. foreach ( $post_values as $setting_id => $post_value ) { - if ( ! isset( $args['data'][ $setting_id ] ) ) { - $args['data'][ $setting_id ] = array(); - } + $args['data'][ $setting_id ] ??= array(); if ( ! isset( $args['data'][ $setting_id ]['value'] ) ) { $args['data'][ $setting_id ]['value'] = $post_value; } @@ -2846,9 +2844,7 @@ public function save_changeset_post( $args = array() ) { unset( $data[ $changeset_setting_id ] ); } else { - if ( ! isset( $data[ $changeset_setting_id ] ) ) { - $data[ $changeset_setting_id ] = array(); - } + $data[ $changeset_setting_id ] ??= array(); // Merge any additional setting params that have been supplied with the existing params. $merged_setting_params = array_merge( $data[ $changeset_setting_id ], $setting_params ); @@ -3516,9 +3512,7 @@ public function _publish_changeset_values( $changeset_post_id ) { preg_match( $namespace_pattern, $raw_setting_id, $matches ) ); if ( $is_theme_mod_setting ) { - if ( ! isset( $theme_mod_settings[ $matches['stylesheet'] ] ) ) { - $theme_mod_settings[ $matches['stylesheet'] ] = array(); - } + $theme_mod_settings[ $matches['stylesheet'] ] ??= array(); $theme_mod_settings[ $matches['stylesheet'] ][ $matches['setting_id'] ] = $setting_params; if ( $this->get_stylesheet() === $matches['stylesheet'] ) { @@ -3665,9 +3659,7 @@ protected function update_stashed_theme_mod_settings( $inactive_theme_mod_settin // Merge inactive theme mods with the stashed theme mod settings. foreach ( $inactive_theme_mod_settings as $stylesheet => $theme_mod_settings ) { - if ( ! isset( $stashed_theme_mod_settings[ $stylesheet ] ) ) { - $stashed_theme_mod_settings[ $stylesheet ] = array(); - } + $stashed_theme_mod_settings[ $stylesheet ] ??= array(); $stashed_theme_mod_settings[ $stylesheet ] = array_merge( $stashed_theme_mod_settings[ $stylesheet ], diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index 07b2742264775..3f58dfb71a093 100644 --- a/src/wp-includes/class-wp-customize-nav-menus.php +++ b/src/wp-includes/class-wp-customize-nav-menus.php @@ -977,9 +977,7 @@ public function insert_auto_draft_post( $postarr ) { if ( empty( $postarr['post_name'] ) ) { $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); } - if ( ! isset( $postarr['meta_input'] ) ) { - $postarr['meta_input'] = array(); - } + $postarr['meta_input'] ??= array(); $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid(); unset( $postarr['post_name'] ); diff --git a/src/wp-includes/class-wp-customize-setting.php b/src/wp-includes/class-wp-customize-setting.php index 2586646f7f2e1..7fa1f886a4184 100644 --- a/src/wp-includes/class-wp-customize-setting.php +++ b/src/wp-includes/class-wp-customize-setting.php @@ -248,9 +248,7 @@ final public function id_data() { */ protected function aggregate_multidimensional() { $id_base = $this->id_data['base']; - if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) { - self::$aggregated_multidimensionals[ $this->type ] = array(); - } + self::$aggregated_multidimensionals[ $this->type ] ??= array(); if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) { self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array( 'previewed_instances' => array(), // Calling preview() will add the $setting to the array. @@ -887,9 +885,7 @@ final protected function multidimensional( &$root, $keys, $create = false ) { // Account for an array overriding a string or object value. $node = array(); } - if ( ! isset( $node[ $last ] ) ) { - $node[ $last ] = array(); - } + $node[ $last ] ??= array(); } if ( ! isset( $node[ $last ] ) ) { diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index 7484d2deee7da..2f1b4193d8e24 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -1080,9 +1080,7 @@ public function get_available_widgets() { $sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false ); $done[] = $widget['callback']; - if ( ! isset( $widget['params'][0] ) ) { - $widget['params'][0] = array(); - } + $widget['params'][0] ??= array(); $available_widget = $widget; unset( $available_widget['callback'] ); // Not serializable to JSON. @@ -1885,10 +1883,8 @@ public function filter_dynamic_sidebar_params( $params ) { */ public function filter_wp_kses_allowed_data_attributes( $allowed_html ) { foreach ( array_keys( $this->before_widget_tags_seen ) as $tag_name ) { - if ( ! isset( $allowed_html[ $tag_name ] ) ) { - $allowed_html[ $tag_name ] = array(); - } - $allowed_html[ $tag_name ] = array_merge( + $allowed_html[ $tag_name ] ??= array(); + $allowed_html[ $tag_name ] = array_merge( $allowed_html[ $tag_name ], array_fill_keys( array( diff --git a/src/wp-includes/class-wp-duotone.php b/src/wp-includes/class-wp-duotone.php index 0e12e7ca7f306..53b8fe4353f07 100644 --- a/src/wp-includes/class-wp-duotone.php +++ b/src/wp-includes/class-wp-duotone.php @@ -1276,9 +1276,7 @@ public static function output_footer_assets() { public static function add_editor_settings( $settings ) { $global_styles_presets = self::get_all_global_styles_presets(); if ( ! empty( $global_styles_presets ) ) { - if ( ! isset( $settings['styles'] ) ) { - $settings['styles'] = array(); - } + $settings['styles'] ??= array(); $settings['styles'][] = array( // For the editor we can add all of the presets by default. diff --git a/src/wp-includes/class-wp-metadata-lazyloader.php b/src/wp-includes/class-wp-metadata-lazyloader.php index f9c02391d2b1d..0bae09debe810 100644 --- a/src/wp-includes/class-wp-metadata-lazyloader.php +++ b/src/wp-includes/class-wp-metadata-lazyloader.php @@ -84,9 +84,7 @@ public function queue_objects( $object_type, $object_ids ) { $type_settings = $this->settings[ $object_type ]; - if ( ! isset( $this->pending_objects[ $object_type ] ) ) { - $this->pending_objects[ $object_type ] = array(); - } + $this->pending_objects[ $object_type ] ??= array(); foreach ( $object_ids as $object_id ) { // Keyed by ID for faster lookup. diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php index 228691d26d12b..aad2fbc7af23c 100644 --- a/src/wp-includes/class-wp-query.php +++ b/src/wp-includes/class-wp-query.php @@ -643,9 +643,7 @@ public function fill_query_vars( $query_vars ) { ); foreach ( $array_keys as $key ) { - if ( ! isset( $query_vars[ $key ] ) ) { - $query_vars[ $key ] = array(); - } + $query_vars[ $key ] ??= array(); } return $query_vars; @@ -1279,10 +1277,8 @@ public function parse_tax_query( &$query_vars ) { } if ( ! empty( $query_vars['category__and'] ) && 1 === count( (array) $query_vars['category__and'] ) ) { - $query_vars['category__and'] = (array) $query_vars['category__and']; - if ( ! isset( $query_vars['category__in'] ) ) { - $query_vars['category__in'] = array(); - } + $query_vars['category__and'] = (array) $query_vars['category__and']; + $query_vars['category__in'] ??= array(); $query_vars['category__in'][] = absint( reset( $query_vars['category__and'] ) ); unset( $query_vars['category__and'] ); } diff --git a/src/wp-includes/class-wp-speculation-rules.php b/src/wp-includes/class-wp-speculation-rules.php index 45e6f3ff0be0a..11794c83b8717 100644 --- a/src/wp-includes/class-wp-speculation-rules.php +++ b/src/wp-includes/class-wp-speculation-rules.php @@ -204,9 +204,7 @@ public function add_rule( string $mode, string $id, array $rule ): bool { } } - if ( ! isset( $this->rules_by_mode[ $mode ] ) ) { - $this->rules_by_mode[ $mode ] = array(); - } + $this->rules_by_mode[ $mode ] ??= array(); $this->rules_by_mode[ $mode ][ $id ] = $rule; return true; diff --git a/src/wp-includes/class-wp-tax-query.php b/src/wp-includes/class-wp-tax-query.php index c6ec3258cc201..9229dcce8fb82 100644 --- a/src/wp-includes/class-wp-tax-query.php +++ b/src/wp-includes/class-wp-tax-query.php @@ -160,10 +160,8 @@ public function sanitize_query( $queries ) { * $queried_terms array, for use in WP_Query. */ if ( ! empty( $cleaned_clause['taxonomy'] ) && 'NOT IN' !== $cleaned_clause['operator'] ) { - $taxonomy = $cleaned_clause['taxonomy']; - if ( ! isset( $this->queried_terms[ $taxonomy ] ) ) { - $this->queried_terms[ $taxonomy ] = array(); - } + $taxonomy = $cleaned_clause['taxonomy']; + $this->queried_terms[ $taxonomy ] ??= array(); /* * Backward compatibility: Only store the first diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 7e2cb54731b1f..39ac5ec48b052 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2511,9 +2511,7 @@ protected function get_css_variables( $nodes, $origins ) { $target = static::get_feature_selector( $feature_selectors, $preset_metadata['path'][0], $selector ); - if ( ! isset( $vars_by_selector[ $target ] ) ) { - $vars_by_selector[ $target ] = array(); - } + $vars_by_selector[ $target ] ??= array(); foreach ( $values_by_slug as $slug => $value ) { $vars_by_selector[ $target ][] = array( diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 6a18e7a534daa..4284a589ed3da 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1357,10 +1357,8 @@ public function get_post_templates() { } foreach ( $types as $type ) { - $type = sanitize_key( $type ); - if ( ! isset( $post_templates[ $type ] ) ) { - $post_templates[ $type ] = array(); - } + $type = sanitize_key( $type ); + $post_templates[ $type ] ??= array(); $post_templates[ $type ][ $file ] = $headers['TemplateName']; } diff --git a/src/wp-includes/class-wp-token-map.php b/src/wp-includes/class-wp-token-map.php index fc223b187f8c5..93f47845b02c5 100644 --- a/src/wp-includes/class-wp-token-map.php +++ b/src/wp-includes/class-wp-token-map.php @@ -312,9 +312,7 @@ public static function from_array( array $mappings, int $key_length = 2 ): ?WP_T } else { $group = substr( $word, 0, $key_length ); - if ( ! isset( $groups[ $group ] ) ) { - $groups[ $group ] = array(); - } + $groups[ $group ] ??= array(); $groups[ $group ][] = array( substr( $word, $key_length ), $mapping ); } diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php index aca7619a6b895..de6c6a1fe13ef 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php @@ -902,9 +902,7 @@ protected function update( $value ) { * @return array Save response data. */ public function amend_customize_save_response( $data ) { - if ( ! isset( $data['nav_menu_item_updates'] ) ) { - $data['nav_menu_item_updates'] = array(); - } + $data['nav_menu_item_updates'] ??= array(); $data['nav_menu_item_updates'][] = array( 'post_id' => $this->post_id, diff --git a/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php b/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php index 138ab8806e719..83489d21cf460 100644 --- a/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php +++ b/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php @@ -601,10 +601,8 @@ protected function update( $value ) { * @return array (Maybe) modified nav_menu_options array. */ protected function filter_nav_menu_options_value( $nav_menu_options, $menu_id, $auto_add ) { - $nav_menu_options = (array) $nav_menu_options; - if ( ! isset( $nav_menu_options['auto_add'] ) ) { - $nav_menu_options['auto_add'] = array(); - } + $nav_menu_options = (array) $nav_menu_options; + $nav_menu_options['auto_add'] ??= array(); $i = array_search( $menu_id, $nav_menu_options['auto_add'], true ); @@ -628,12 +626,8 @@ protected function filter_nav_menu_options_value( $nav_menu_options, $menu_id, $ * @return array Export data. */ public function amend_customize_save_response( $data ) { - if ( ! isset( $data['nav_menu_updates'] ) ) { - $data['nav_menu_updates'] = array(); - } - if ( ! isset( $data['widget_nav_menu_updates'] ) ) { - $data['widget_nav_menu_updates'] = array(); - } + $data['nav_menu_updates'] ??= array(); + $data['widget_nav_menu_updates'] ??= array(); $data['nav_menu_updates'][] = array( 'term_id' => $this->term_id, diff --git a/src/wp-includes/customize/class-wp-widget-form-customize-control.php b/src/wp-includes/customize/class-wp-widget-form-customize-control.php index cfab1886062fd..3ac0e69969ed5 100644 --- a/src/wp-includes/customize/class-wp-widget-form-customize-control.php +++ b/src/wp-includes/customize/class-wp-widget-form-customize-control.php @@ -98,10 +98,8 @@ public function to_json() { // Get the widget_control and widget_content. require_once ABSPATH . 'wp-admin/includes/widgets.php'; - $widget = $wp_registered_widgets[ $this->widget_id ]; - if ( ! isset( $widget['params'][0] ) ) { - $widget['params'][0] = array(); - } + $widget = $wp_registered_widgets[ $this->widget_id ]; + $widget['params'][0] ??= array(); $args = array( 'widget_id' => $widget['id'], diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 22a1d3e307d3e..c59100e42cd6f 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -5095,9 +5095,7 @@ function paginate_links( $args = '' ) { function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { global $_wp_admin_css_colors; - if ( ! isset( $_wp_admin_css_colors ) ) { - $_wp_admin_css_colors = array(); - } + $_wp_admin_css_colors ??= array(); $_wp_admin_css_colors[ $key ] = (object) array( 'name' => $name, diff --git a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php index 62bfc29cfc03f..ecd8b1e9b085e 100644 --- a/src/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/src/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -192,9 +192,7 @@ public function state( ?string $store_namespace = null, ?array $state = null ): $store_namespace = end( $this->namespace_stack ); } - if ( ! isset( $this->state_data[ $store_namespace ] ) ) { - $this->state_data[ $store_namespace ] = array(); - } + $this->state_data[ $store_namespace ] ??= array(); if ( is_array( $state ) ) { $this->state_data[ $store_namespace ] = array_replace_recursive( $this->state_data[ $store_namespace ], @@ -220,9 +218,7 @@ public function state( ?string $store_namespace = null, ?array $state = null ): * $config argument was provided. */ public function config( string $store_namespace, array $config = array() ): array { - if ( ! isset( $this->config_data[ $store_namespace ] ) ) { - $this->config_data[ $store_namespace ] = array(); - } + $this->config_data[ $store_namespace ] ??= array(); if ( is_array( $config ) ) { $this->config_data[ $store_namespace ] = array_replace_recursive( $this->config_data[ $store_namespace ], @@ -260,9 +256,7 @@ public function print_client_interactivity_data() { * @return array Data for the Interactivity Router script module. */ public function filter_script_module_interactivity_router_data( array $data ): array { - if ( ! isset( $data['i18n'] ) ) { - $data['i18n'] = array(); - } + $data['i18n'] ??= array(); $data['i18n']['loading'] = __( 'Loading page, please wait.' ); $data['i18n']['loaded'] = __( 'Page Loaded.' ); return $data; diff --git a/src/wp-includes/l10n/class-wp-translation-controller.php b/src/wp-includes/l10n/class-wp-translation-controller.php index c68cf32add6d6..da7a35203aa80 100644 --- a/src/wp-includes/l10n/class-wp-translation-controller.php +++ b/src/wp-includes/l10n/class-wp-translation-controller.php @@ -134,9 +134,7 @@ public function load_file( string $translation_file, string $textdomain = 'defau return false; } - if ( ! isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) { - $this->loaded_translations[ $locale ][ $textdomain ] = array(); - } + $this->loaded_translations[ $locale ][ $textdomain ] ??= array(); $this->loaded_translations[ $locale ][ $textdomain ][] = $moe; diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index c657c6c2e7af3..874604129832f 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -1224,10 +1224,8 @@ function update_meta_cache( $meta_type, $object_ids ) { $data = array(); foreach ( $non_cached_ids as $id ) { - if ( ! isset( $cache[ $id ] ) ) { - $cache[ $id ] = array(); - } - $data[ $id ] = $cache[ $id ]; + $cache[ $id ] ??= array(); + $data[ $id ] = $cache[ $id ]; } wp_cache_add_multiple( $data, $cache_group ); diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index f64b584374c8e..5770a2ded7c2a 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -43,17 +43,11 @@ $wp_filter = array(); } -if ( ! isset( $wp_actions ) ) { - $wp_actions = array(); -} +$wp_actions ??= array(); -if ( ! isset( $wp_filters ) ) { - $wp_filters = array(); -} +$wp_filters ??= array(); -if ( ! isset( $wp_current_filter ) ) { - $wp_current_filter = array(); -} +$wp_current_filter ??= array(); /** * Adds a callback function to a filter hook. diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php index a6169ada2c05b..a2606e1a46dff 100644 --- a/src/wp-includes/rest-api/class-wp-rest-request.php +++ b/src/wp-includes/rest-api/class-wp-rest-request.php @@ -265,9 +265,7 @@ public function add_header( $key, $value ) { $key = $this->canonicalize_header_name( $key ); $value = (array) $value; - if ( ! isset( $this->headers[ $key ] ) ) { - $this->headers[ $key ] = array(); - } + $this->headers[ $key ] ??= array(); $this->headers[ $key ] = array_merge( $this->headers[ $key ], $value ); } diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index c331d73363541..a8002800e5d3e 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -989,9 +989,7 @@ public function get_routes( $route_namespace = '' ) { $handlers = array( $handlers ); } - if ( ! isset( $this->route_options[ $route ] ) ) { - $this->route_options[ $route ] = array(); - } + $this->route_options[ $route ] ??= array(); foreach ( $handlers as $key => &$handler ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index f336f321a9ea2..6ef6d09b0333b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -2139,9 +2139,7 @@ protected function get_media_types() { foreach ( get_allowed_mime_types() as $mime_type ) { $parts = explode( '/', $mime_type ); - if ( ! isset( $media_types[ $parts[0] ] ) ) { - $media_types[ $parts[0] ] = array(); - } + $media_types[ $parts[0] ] ??= array(); $media_types[ $parts[0] ][] = $mime_type; } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php index 706e36fb6cc66..887662e06ad33 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php @@ -436,9 +436,7 @@ protected function handle_auto_add( $menu_id, $request ) { $nav_menu_option = (array) get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); - if ( ! isset( $nav_menu_option['auto_add'] ) ) { - $nav_menu_option['auto_add'] = array(); - } + $nav_menu_option['auto_add'] ??= array(); $auto_add = $request['auto_add']; diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 29317f0a8bf9b..e7d63c1210117 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -3603,10 +3603,8 @@ function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) { } if ( wp_defer_term_counting() ) { - if ( ! isset( $_deferred[ $taxonomy ] ) ) { - $_deferred[ $taxonomy ] = array(); - } - $_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) ); + $_deferred[ $taxonomy ] ??= array(); + $_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) ); return true; } @@ -3909,9 +3907,7 @@ function update_object_term_cache( $object_ids, $object_type ) { foreach ( $non_cached_ids as $id ) { foreach ( $taxonomies as $taxonomy ) { if ( ! isset( $object_terms[ $id ][ $taxonomy ] ) ) { - if ( ! isset( $object_terms[ $id ] ) ) { - $object_terms[ $id ] = array(); - } + $object_terms[ $id ] ??= array(); $object_terms[ $id ][ $taxonomy ] = array(); } } @@ -4401,10 +4397,8 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { // Keep a record of term_ids that have been split, keyed by old term_id. See wp_get_split_term(). if ( $record ) { - $split_term_data = get_option( '_split_terms', array() ); - if ( ! isset( $split_term_data[ $term_id ] ) ) { - $split_term_data[ $term_id ] = array(); - } + $split_term_data = get_option( '_split_terms', array() ); + $split_term_data[ $term_id ] ??= array(); $split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id; update_option( '_split_terms', $split_term_data ); @@ -4509,9 +4503,7 @@ function _wp_batch_split_terms() { continue; } - if ( ! isset( $split_term_data[ $term_id ] ) ) { - $split_term_data[ $term_id ] = array(); - } + $split_term_data[ $term_id ] ??= array(); // Keep track of taxonomies whose hierarchies need flushing. if ( ! isset( $taxonomies[ $shared_tt->taxonomy ] ) ) {