Commit 74d6d906f2 for wordpress.org
commit 74d6d906f268d13560663e133608fddee984b036
Author: Weston Ruter <weston@xwp.co>
Date: Mon Jan 5 04:33:34 2026 +0000
Code Modernization: REST API: Use null coalescing operator in place of `isset()` in ternaries.
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 [61424], [61404], [61403].
Props costdev, westonruter.
See #58874, #63430.
Built from https://develop.svn.wordpress.org/trunk@61429
git-svn-id: http://core.svn.wordpress.org/trunk@60741 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php
index d33a52ef51..c4fce5a43e 100644
--- a/wp-includes/rest-api.php
+++ b/wp-includes/rest-api.php
@@ -952,7 +952,7 @@ 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 ] = isset( $ref[ $next ] ) ? $ref[ $next ] : array();
+ $ref[ $next ] = $ref[ $next ] ?? array();
$ref = &$ref[ $next ];
}
$last = array_shift( $parts );
@@ -3088,7 +3088,7 @@ function rest_filter_response_by_context( $response_data, $schema, $context ) {
$check = array();
if ( $is_array_type ) {
- $check = isset( $schema['items'] ) ? $schema['items'] : array();
+ $check = $schema['items'] ?? array();
} elseif ( $is_object_type ) {
if ( isset( $schema['properties'][ $key ] ) ) {
$check = $schema['properties'][ $key ];
@@ -3417,7 +3417,7 @@ function rest_convert_error_to_response( $error ) {
$status = array_reduce(
$error->get_all_error_data(),
static function ( $status, $error_data ) {
- return is_array( $error_data ) && isset( $error_data['status'] ) ? $error_data['status'] : $status;
+ return $error_data['status'] ?? $status;
},
500
);
diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php
index 2eae390fea..0a18be77cd 100644
--- a/wp-includes/rest-api/class-wp-rest-server.php
+++ b/wp-includes/rest-api/class-wp-rest-server.php
@@ -1374,7 +1374,7 @@ class WP_REST_Server {
$response = new WP_REST_Response( $available );
- $fields = isset( $request['_fields'] ) ? $request['_fields'] : '';
+ $fields = $request['_fields'] ?? '';
$fields = wp_parse_list( $fields );
if ( empty( $fields ) ) {
$fields[] = '_links';
@@ -1618,7 +1618,7 @@ class WP_REST_Server {
$data['namespace'] = $options['namespace'];
}
- $allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false;
+ $allow_batch = $options['allow_batch'] ?? false;
if ( isset( $options['schema'] ) && 'help' === $context ) {
$data['schema'] = call_user_func( $options['schema'] );
@@ -1640,7 +1640,7 @@ class WP_REST_Server {
'methods' => array_keys( $callback['methods'] ),
);
- $callback_batch = isset( $callback['allow_batch'] ) ? $callback['allow_batch'] : $allow_batch;
+ $callback_batch = $callback['allow_batch'] ?? $allow_batch;
if ( $callback_batch ) {
$endpoint_data['allow_batch'] = $callback_batch;
@@ -1722,7 +1722,7 @@ class WP_REST_Server {
continue;
}
- $single_request = new WP_REST_Request( isset( $args['method'] ) ? $args['method'] : 'POST', $parsed_url['path'] );
+ $single_request = new WP_REST_Request( $args['method'] ?? 'POST', $parsed_url['path'] );
if ( ! empty( $parsed_url['query'] ) ) {
$query_args = array();
@@ -1767,7 +1767,7 @@ class WP_REST_Server {
$allow_batch = $handler['allow_batch'];
} else {
$route_options = $this->get_route_options( $route );
- $allow_batch = isset( $route_options['allow_batch'] ) ? $route_options['allow_batch'] : false;
+ $allow_batch = $route_options['allow_batch'] ?? false;
}
if ( ! is_array( $allow_batch ) || empty( $allow_batch['v1'] ) ) {
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 fbead90390..f824b0c9e2 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
@@ -159,7 +159,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
* @param bool $check_mime Whether to prevent uploads of unsupported image types.
* @param string|null $mime_type The mime type of the file being uploaded (if available).
*/
- $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, isset( $files['file']['type'] ) ? $files['file']['type'] : null );
+ $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, $files['file']['type'] ?? null );
// If the upload is an image, check if the server can handle the mime type.
if (
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
index 2e093f6656..8cb0a4987f 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
@@ -389,7 +389,7 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
foreach ( $revisioned_meta_keys as $meta_key ) {
// get_metadata_raw is used to avoid retrieving the default value.
$old_meta = get_metadata_raw( 'post', $post_id, $meta_key, true );
- $new_meta = isset( $meta[ $meta_key ] ) ? $meta[ $meta_key ] : '';
+ $new_meta = $meta[ $meta_key ] ?? '';
if ( $new_meta !== $old_meta ) {
$autosave_is_different = true;
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
index 8a34c78d33..c2c92efbbc 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
@@ -136,7 +136,7 @@ class WP_REST_Block_Directory_Controller extends WP_REST_Controller {
'author_block_rating' => $plugin['author_block_rating'] / 20,
'author_block_count' => (int) $plugin['author_block_count'],
'author' => wp_strip_all_tags( $plugin['author'] ),
- 'icon' => ( isset( $plugin['icons']['1x'] ) ? $plugin['icons']['1x'] : 'block-default' ),
+ 'icon' => $plugin['icons']['1x'] ?? 'block-default',
'last_updated' => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
'humanized_updated' => sprintf(
/* translators: %s: Human-readable time difference. */
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php
index 6f600a0494..b7286bea74 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php
@@ -58,7 +58,7 @@ class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {
unset( $data['content']['rendered'] );
// Add the core wp_pattern_sync_status meta as top level property to the response.
- $data['wp_pattern_sync_status'] = isset( $data['meta']['wp_pattern_sync_status'] ) ? $data['meta']['wp_pattern_sync_status'] : '';
+ $data['wp_pattern_sync_status'] = $data['meta']['wp_pattern_sync_status'] ?? '';
unset( $data['meta']['wp_pattern_sync_status'] );
return $data;
}
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
index 0474613b2e..75e72a442f 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
@@ -571,7 +571,7 @@ abstract class WP_REST_Controller {
*/
public function get_fields_for_response( $request ) {
$schema = $this->get_item_schema();
- $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
+ $properties = $schema['properties'] ?? array();
$additional_fields = $this->get_additional_fields();
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
index 908ebe4bcc..2a3d4d340d 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
@@ -573,7 +573,7 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Posts_Controller {
if ( rest_is_field_included( 'styles', $fields ) ) {
$raw_data = $theme->get_raw_data();
- $data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
+ $data['styles'] = $raw_data['styles'] ?? array();
}
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php
index b0ccd60fc3..c9ce88ce24 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php
@@ -181,7 +181,7 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller {
$location = $item;
$locations = get_nav_menu_locations();
- $menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
+ $menu = $locations[ $location->name ] ?? 0;
$fields = $this->get_fields_for_response( $request );
$data = array();
@@ -242,7 +242,7 @@ class WP_REST_Menu_Locations_Controller extends WP_REST_Controller {
);
$locations = get_nav_menu_locations();
- $menu = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
+ $menu = $locations[ $location->name ] ?? 0;
if ( $menu ) {
$path = rest_get_route_for_term( $menu );
if ( $path ) {
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
index bec92f1c7e..fe6c056eb7 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
@@ -100,8 +100,8 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
$query_args['locale'] = get_user_locale();
$query_args['wp-version'] = wp_get_wp_version();
- $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false;
- $query_args['pattern-keywords'] = isset( $request['keyword'] ) ? $request['keyword'] : false;
+ $query_args['pattern-categories'] = $request['category'] ?? false;
+ $query_args['pattern-keywords'] = $request['keyword'] ?? false;
$query_args = array_filter( $query_args );
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
index 004f5851a2..142836c7c8 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
@@ -239,7 +239,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
'type' => empty( $args['type'] ) ? null : $args['type'],
'title' => empty( $args['label'] ) ? '' : $args['label'],
'description' => empty( $args['description'] ) ? '' : $args['description'],
- 'default' => isset( $args['default'] ) ? $args['default'] : null,
+ 'default' => $args['default'] ?? null,
);
$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
index aba1773884..80efbf5ea5 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
@@ -339,13 +339,13 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
$registered_sidebar = $wp_registered_sidebars[ $id ];
$sidebar['status'] = 'active';
- $sidebar['name'] = isset( $registered_sidebar['name'] ) ? $registered_sidebar['name'] : '';
+ $sidebar['name'] = $registered_sidebar['name'] ?? '';
$sidebar['description'] = isset( $registered_sidebar['description'] ) ? wp_sidebar_description( $id ) : '';
- $sidebar['class'] = isset( $registered_sidebar['class'] ) ? $registered_sidebar['class'] : '';
- $sidebar['before_widget'] = isset( $registered_sidebar['before_widget'] ) ? $registered_sidebar['before_widget'] : '';
- $sidebar['after_widget'] = isset( $registered_sidebar['after_widget'] ) ? $registered_sidebar['after_widget'] : '';
- $sidebar['before_title'] = isset( $registered_sidebar['before_title'] ) ? $registered_sidebar['before_title'] : '';
- $sidebar['after_title'] = isset( $registered_sidebar['after_title'] ) ? $registered_sidebar['after_title'] : '';
+ $sidebar['class'] = $registered_sidebar['class'] ?? '';
+ $sidebar['before_widget'] = $registered_sidebar['before_widget'] ?? '';
+ $sidebar['after_widget'] = $registered_sidebar['after_widget'] ?? '';
+ $sidebar['before_title'] = $registered_sidebar['before_title'] ?? '';
+ $sidebar['after_title'] = $registered_sidebar['after_title'] ?? '';
} else {
$sidebar['status'] = 'inactive';
$sidebar['name'] = $raw_sidebar['name'];
@@ -361,7 +361,7 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
if ( rest_is_field_included( 'widgets', $fields ) ) {
$sidebars = wp_get_sidebars_widgets();
$widgets = array_filter(
- isset( $sidebars[ $sidebar['id'] ] ) ? $sidebars[ $sidebar['id'] ] : array(),
+ $sidebars[ $sidebar['id'] ] ?? array(),
static function ( $widget_id ) use ( $wp_registered_widgets ) {
return isset( $wp_registered_widgets[ $widget_id ] );
}
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
index 3f13968ae2..0ac6c8b93d 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
@@ -579,7 +579,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
$changes->post_type = $this->post_type;
$changes->post_status = 'publish';
$changes->tax_input = array(
- 'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : get_stylesheet(),
+ 'wp_theme' => $request['theme'] ?? get_stylesheet(),
);
} elseif ( 'custom' !== $template->source ) {
$changes->post_name = $template->slug;
@@ -914,8 +914,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
if ( isset( $plugins[ $plugin_basename ] ) && isset( $plugins[ $plugin_basename ]['Name'] ) ) {
return $plugins[ $plugin_basename ]['Name'];
}
- return isset( $template_object->plugin ) ?
- $template_object->plugin :
+ return $template_object->plugin ??
$template_object->theme;
case 'site':
return get_bloginfo( 'name' );
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
index 51ad50aa9e..94b3e5c264 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
@@ -405,7 +405,7 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
$id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
} else {
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
- $id = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null;
+ $id = $user_cpt['ID'] ?? null;
}
if ( $id ) {
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
index 43c29ac888..9b25cf7974 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
@@ -333,9 +333,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
$prepared_args['search_columns'] = array( 'ID', 'user_login', 'user_nicename', 'display_name' );
}
$search_columns = $request->get_param( 'search_columns' );
- $valid_columns = isset( $prepared_args['search_columns'] )
- ? $prepared_args['search_columns']
- : array( 'ID', 'user_login', 'user_nicename', 'user_email', 'display_name' );
+ $valid_columns = $prepared_args['search_columns'] ?? array( 'ID', 'user_login', 'user_nicename', 'user_email', 'display_name' );
$search_columns_mapping = array(
'id' => 'ID',
'username' => 'user_login',
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
index 1eb1ef27eb..4208ad2d92 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
@@ -611,7 +611,7 @@ class WP_REST_Widget_Types_Controller extends WP_REST_Controller {
return array(
'preview' => $this->render_legacy_widget_preview_iframe(
$request['id'],
- isset( $request['instance'] ) ? $request['instance'] : null
+ $request['instance'] ?? null
),
);
}
diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
index a8e7af54e8..9b25298c34 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
@@ -533,7 +533,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
$id = $request['id'];
$parsed_id = wp_parse_widget_id( $id );
$id_base = $parsed_id['id_base'];
- $number = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null;
+ $number = $parsed_id['number'] ?? null;
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
$creating = false;
} elseif ( $request['id_base'] ) {
diff --git a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
index aa0bc644bc..a9c3fbcde8 100644
--- a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
+++ b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
@@ -480,7 +480,7 @@ abstract class WP_REST_Meta_Fields {
'type' => $default_args['type'],
'title' => empty( $args['label'] ) ? '' : $args['label'],
'description' => empty( $args['description'] ) ? '' : $args['description'],
- 'default' => isset( $args['default'] ) ? $args['default'] : null,
+ 'default' => $args['default'] ?? null,
);
$rest_args = array_merge( $default_args, $rest_args );
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 18a1888e6a..e80e1e36e1 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61428';
+$wp_version = '7.0-alpha-61429';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.