Make WordPress Core

Changeset 61429


Ignore:
Timestamp:
01/05/2026 04:31:14 AM (8 months ago)
Author:
westonruter
Message:

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.

Location:
trunk/src/wp-includes
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r61178 r61429  
    953953                                break 2;
    954954                        }
    955                         $ref[ $next ] = isset( $ref[ $next ] ) ? $ref[ $next ] : array();
     955                        $ref[ $next ] = $ref[ $next ] ?? array();
    956956                        $ref          = &$ref[ $next ];
    957957                }
     
    30893089
    30903090                if ( $is_array_type ) {
    3091                         $check = isset( $schema['items'] ) ? $schema['items'] : array();
     3091                        $check = $schema['items'] ?? array();
    30923092                } elseif ( $is_object_type ) {
    30933093                        if ( isset( $schema['properties'][ $key ] ) ) {
     
    34183418                $error->get_all_error_data(),
    34193419                static function ( $status, $error_data ) {
    3420                         return is_array( $error_data ) && isset( $error_data['status'] ) ? $error_data['status'] : $status;
     3420                        return $error_data['status'] ?? $status;
    34213421                },
    34223422                500
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r61428 r61429  
    13751375                $response = new WP_REST_Response( $available );
    13761376
    1377                 $fields = isset( $request['_fields'] ) ? $request['_fields'] : '';
     1377                $fields = $request['_fields'] ?? '';
    13781378                $fields = wp_parse_list( $fields );
    13791379                if ( empty( $fields ) ) {
     
    16191619                        }
    16201620
    1621                         $allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false;
     1621                        $allow_batch = $options['allow_batch'] ?? false;
    16221622
    16231623                        if ( isset( $options['schema'] ) && 'help' === $context ) {
     
    16411641                        );
    16421642
    1643                         $callback_batch = isset( $callback['allow_batch'] ) ? $callback['allow_batch'] : $allow_batch;
     1643                        $callback_batch = $callback['allow_batch'] ?? $allow_batch;
    16441644
    16451645                        if ( $callback_batch ) {
     
    17231723                        }
    17241724
    1725                         $single_request = new WP_REST_Request( isset( $args['method'] ) ? $args['method'] : 'POST', $parsed_url['path'] );
     1725                        $single_request = new WP_REST_Request( $args['method'] ?? 'POST', $parsed_url['path'] );
    17261726
    17271727                        if ( ! empty( $parsed_url['query'] ) ) {
     
    17681768                                } else {
    17691769                                        $route_options = $this->get_route_options( $route );
    1770                                         $allow_batch   = isset( $route_options['allow_batch'] ) ? $route_options['allow_batch'] : false;
     1770                                        $allow_batch   = $route_options['allow_batch'] ?? false;
    17711771                                }
    17721772
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r61065 r61429  
    160160                 * @param string|null $mime_type  The mime type of the file being uploaded (if available).
    161161                 */
    162                 $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, isset( $files['file']['type'] ) ? $files['file']['type'] : null );
     162                $prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, $files['file']['type'] ?? null );
    163163
    164164                // If the upload is an image, check if the server can handle the mime type.
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php

    r59970 r61429  
    390390                                // get_metadata_raw is used to avoid retrieving the default value.
    391391                                $old_meta = get_metadata_raw( 'post', $post_id, $meta_key, true );
    392                                 $new_meta = isset( $meta[ $meta_key ] ) ? $meta[ $meta_key ] : '';
     392                                $new_meta = $meta[ $meta_key ] ?? '';
    393393
    394394                                if ( $new_meta !== $old_meta ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php

    r59501 r61429  
    137137                        'author_block_count'  => (int) $plugin['author_block_count'],
    138138                        'author'              => wp_strip_all_tags( $plugin['author'] ),
    139                         'icon'                => ( isset( $plugin['icons']['1x'] ) ? $plugin['icons']['1x'] : 'block-default' ),
     139                        'icon'                => $plugin['icons']['1x'] ?? 'block-default',
    140140                        'last_updated'        => gmdate( 'Y-m-d\TH:i:s', strtotime( $plugin['last_updated'] ) ),
    141141                        'humanized_updated'   => sprintf(
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php

    r57033 r61429  
    5959
    6060                // Add the core wp_pattern_sync_status meta as top level property to the response.
    61                 $data['wp_pattern_sync_status'] = isset( $data['meta']['wp_pattern_sync_status'] ) ? $data['meta']['wp_pattern_sync_status'] : '';
     61                $data['wp_pattern_sync_status'] = $data['meta']['wp_pattern_sync_status'] ?? '';
    6262                unset( $data['meta']['wp_pattern_sync_status'] );
    6363                return $data;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    r60249 r61429  
    572572        public function get_fields_for_response( $request ) {
    573573                $schema     = $this->get_item_schema();
    574                 $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
     574                $properties = $schema['properties'] ?? array();
    575575
    576576                $additional_fields = $this->get_additional_fields();
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php

    r60359 r61429  
    574574                if ( rest_is_field_included( 'styles', $fields ) ) {
    575575                        $raw_data       = $theme->get_raw_data();
    576                         $data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
     576                        $data['styles'] = $raw_data['styles'] ?? array();
    577577                }
    578578
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php

    r59718 r61429  
    182182
    183183                $locations = get_nav_menu_locations();
    184                 $menu      = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
     184                $menu      = $locations[ $location->name ] ?? 0;
    185185
    186186                $fields = $this->get_fields_for_response( $request );
     
    243243
    244244                $locations = get_nav_menu_locations();
    245                 $menu      = isset( $locations[ $location->name ] ) ? $locations[ $location->name ] : 0;
     245                $menu      = $locations[ $location->name ] ?? 0;
    246246                if ( $menu ) {
    247247                        $path = rest_get_route_for_term( $menu );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php

    r59970 r61429  
    101101                $query_args['locale']             = get_user_locale();
    102102                $query_args['wp-version']         = wp_get_wp_version();
    103                 $query_args['pattern-categories'] = isset( $request['category'] ) ? $request['category'] : false;
    104                 $query_args['pattern-keywords']   = isset( $request['keyword'] ) ? $request['keyword'] : false;
     103                $query_args['pattern-categories'] = $request['category'] ?? false;
     104                $query_args['pattern-keywords']   = $request['keyword'] ?? false;
    105105
    106106                $query_args = array_filter( $query_args );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

    r61324 r61429  
    240240                                'title'       => empty( $args['label'] ) ? '' : $args['label'],
    241241                                'description' => empty( $args['description'] ) ? '' : $args['description'],
    242                                 'default'     => isset( $args['default'] ) ? $args['default'] : null,
     242                                'default'     => $args['default'] ?? null,
    243243                        );
    244244
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php

    r59970 r61429  
    340340
    341341                        $sidebar['status']        = 'active';
    342                         $sidebar['name']          = isset( $registered_sidebar['name'] ) ? $registered_sidebar['name'] : '';
     342                        $sidebar['name']          = $registered_sidebar['name'] ?? '';
    343343                        $sidebar['description']   = isset( $registered_sidebar['description'] ) ? wp_sidebar_description( $id ) : '';
    344                         $sidebar['class']         = isset( $registered_sidebar['class'] ) ? $registered_sidebar['class'] : '';
    345                         $sidebar['before_widget'] = isset( $registered_sidebar['before_widget'] ) ? $registered_sidebar['before_widget'] : '';
    346                         $sidebar['after_widget']  = isset( $registered_sidebar['after_widget'] ) ? $registered_sidebar['after_widget'] : '';
    347                         $sidebar['before_title']  = isset( $registered_sidebar['before_title'] ) ? $registered_sidebar['before_title'] : '';
    348                         $sidebar['after_title']   = isset( $registered_sidebar['after_title'] ) ? $registered_sidebar['after_title'] : '';
     344                        $sidebar['class']         = $registered_sidebar['class'] ?? '';
     345                        $sidebar['before_widget'] = $registered_sidebar['before_widget'] ?? '';
     346                        $sidebar['after_widget']  = $registered_sidebar['after_widget'] ?? '';
     347                        $sidebar['before_title']  = $registered_sidebar['before_title'] ?? '';
     348                        $sidebar['after_title']   = $registered_sidebar['after_title'] ?? '';
    349349                } else {
    350350                        $sidebar['status']      = 'inactive';
     
    362362                        $sidebars = wp_get_sidebars_widgets();
    363363                        $widgets  = array_filter(
    364                                 isset( $sidebars[ $sidebar['id'] ] ) ? $sidebars[ $sidebar['id'] ] : array(),
     364                                $sidebars[ $sidebar['id'] ] ?? array(),
    365365                                static function ( $widget_id ) use ( $wp_registered_widgets ) {
    366366                                        return isset( $wp_registered_widgets[ $widget_id ] );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

    r59970 r61429  
    580580                        $changes->post_status = 'publish';
    581581                        $changes->tax_input   = array(
    582                                 'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : get_stylesheet(),
     582                                'wp_theme' => $request['theme'] ?? get_stylesheet(),
    583583                        );
    584584                } elseif ( 'custom' !== $template->source ) {
     
    915915                                        return $plugins[ $plugin_basename ]['Name'];
    916916                                }
    917                                 return isset( $template_object->plugin ) ?
    918                                         $template_object->plugin :
     917                                return $template_object->plugin ??
    919918                                        $template_object->theme;
    920919                        case 'site':
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php

    r60984 r61429  
    406406                } else {
    407407                        $user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
    408                         $id       = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null;
     408                        $id       = $user_cpt['ID'] ?? null;
    409409                }
    410410
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r61002 r61429  
    334334                        }
    335335                        $search_columns         = $request->get_param( 'search_columns' );
    336                         $valid_columns          = isset( $prepared_args['search_columns'] )
    337                                 ? $prepared_args['search_columns']
    338                                 : array( 'ID', 'user_login', 'user_nicename', 'user_email', 'display_name' );
     336                        $valid_columns          = $prepared_args['search_columns'] ?? array( 'ID', 'user_login', 'user_nicename', 'user_email', 'display_name' );
    339337                        $search_columns_mapping = array(
    340338                                'id'       => 'ID',
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php

    r59970 r61429  
    612612                        'preview' => $this->render_legacy_widget_preview_iframe(
    613613                                $request['id'],
    614                                 isset( $request['instance'] ) ? $request['instance'] : null
     614                                $request['instance'] ?? null
    615615                        ),
    616616                );
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php

    r60044 r61429  
    534534                        $parsed_id     = wp_parse_widget_id( $id );
    535535                        $id_base       = $parsed_id['id_base'];
    536                         $number        = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null;
     536                        $number        = $parsed_id['number'] ?? null;
    537537                        $widget_object = $wp_widget_factory->get_widget_object( $id_base );
    538538                        $creating      = false;
  • trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    r59023 r61429  
    481481                                'title'       => empty( $args['label'] ) ? '' : $args['label'],
    482482                                'description' => empty( $args['description'] ) ? '' : $args['description'],
    483                                 'default'     => isset( $args['default'] ) ? $args['default'] : null,
     483                                'default'     => $args['default'] ?? null,
    484484                        );
    485485
Note: See TracChangeset for help on using the changeset viewer.