Make WordPress Core

Changeset 61463


Ignore:
Timestamp:
01/10/2026 05:01:08 AM (10 months ago)
Author:
westonruter
Message:

Code Modernization: Use null coalescing operator instead of isset() with if/else statements.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10711

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

See #58874, #63430.

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-importer.php

    r60094 r61463  
    312312                        $key   = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
    313313
    314                         if ( isset( $parts[1] ) ) {
    315                                 $out[ $key ] = $parts[1];
    316                         } else {
    317                                 $out[ $key ] = true;
    318                         }
     314                        $out[ $key ] = $parts[1] ?? true;
    319315
    320316                        $last_arg = $key;
  • trunk/src/wp-admin/includes/post.php

    r61445 r61463  
    123123        }
    124124
    125         if ( isset( $post_data['ID'] ) ) {
    126                 $post_id = $post_data['ID'];
    127         } else {
    128                 $post_id = false;
    129         }
     125        $post_id         = $post_data['ID'] ?? false;
    130126        $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
    131127
  • trunk/src/wp-admin/includes/template.php

    r61440 r61463  
    22972297function get_post_states( $post ) {
    22982298        $post_states = array();
    2299 
    2300         if ( isset( $_REQUEST['post_status'] ) ) {
    2301                 $post_status = $_REQUEST['post_status'];
    2302         } else {
    2303                 $post_status = '';
    2304         }
     2299        $post_status = $_REQUEST['post_status'] ?? '';
    23052300
    23062301        if ( ! empty( $post->post_password ) ) {
  • trunk/src/wp-admin/includes/theme.php

    r61456 r61463  
    401401
    402402                foreach ( $feature_items as $feature ) {
    403                         if ( isset( $features[ $feature_category ][ $feature ] ) ) {
    404                                 $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
    405                         } else {
    406                                 $wporg_features[ $feature_category ][ $feature ] = $feature;
    407                         }
     403                        $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ] ?? $feature;
    408404                }
    409405        }
  • trunk/src/wp-admin/upgrade.php

    r60898 r61463  
    2424delete_site_transient( 'update_core' );
    2525
    26 if ( isset( $_GET['step'] ) ) {
    27         $step = $_GET['step'];
    28 } else {
    29         $step = 0;
    30 }
     26$step = $_GET['step'] ?? 0;
    3127
    3228// Do it. No output.
  • trunk/src/wp-includes/class-wp-date-query.php

    r61449 r61463  
    209209                        }
    210210
    211                         if ( isset( $parent_query[ $dkey ] ) ) {
    212                                 $queries[ $dkey ] = $parent_query[ $dkey ];
    213                         } else {
    214                                 $queries[ $dkey ] = $dvalue;
    215                         }
     211                        $queries[ $dkey ] = $parent_query[ $dkey ] ?? $dvalue;
    216212                }
    217213
  • trunk/src/wp-includes/class-wp-http-streams.php

    r56655 r61463  
    7878
    7979                if ( isset( $parsed_args['headers']['Host'] ) || isset( $parsed_args['headers']['host'] ) ) {
    80                         if ( isset( $parsed_args['headers']['Host'] ) ) {
    81                                 $parsed_url['host'] = $parsed_args['headers']['Host'];
    82                         } else {
    83                                 $parsed_url['host'] = $parsed_args['headers']['host'];
    84                         }
     80                        $parsed_url['host'] = $parsed_args['headers']['Host'] ?? $parsed_args['headers']['host'];
    8581                        unset( $parsed_args['headers']['Host'], $parsed_args['headers']['host'] );
    8682                }
  • trunk/src/wp-includes/class-wp-post-type.php

    r59791 r61463  
    656656                        }
    657657                        if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
    658                                 if ( isset( $args['permalink_epmask'] ) ) {
    659                                         $args['rewrite']['ep_mask'] = $args['permalink_epmask'];
    660                                 } else {
    661                                         $args['rewrite']['ep_mask'] = EP_PERMALINK;
    662                                 }
     658                                $args['rewrite']['ep_mask'] = $args['permalink_epmask'] ?? EP_PERMALINK;
    663659                        }
    664660                }
  • trunk/src/wp-includes/class-wp-styles.php

    r61442 r61463  
    179179                }
    180180
    181                 if ( isset( $obj->args ) ) {
    182                         $media = $obj->args;
    183                 } else {
    184                         $media = 'all';
    185                 }
     181                $media = $obj->args ?? 'all';
    186182
    187183                // A single item may alias a set of items, by having dependencies, but no source.
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r61460 r61463  
    36743674                do_action( 'xmlrpc_call', 'wp.getComments', $args, $this );
    36753675
    3676                 if ( isset( $struct['status'] ) ) {
    3677                         $status = $struct['status'];
    3678                 } else {
    3679                         $status = '';
    3680                 }
     3676                $status = $struct['status'] ?? '';
    36813677
    36823678                if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) {
  • trunk/src/wp-includes/general-template.php

    r61454 r61463  
    18741874
    18751875        // Check if a description is set.
    1876         if ( isset( $post_type_obj->description ) ) {
    1877                 $description = $post_type_obj->description;
    1878         } else {
    1879                 $description = '';
    1880         }
     1876        $description = $post_type_obj->description ?? '';
    18811877
    18821878        /**
  • trunk/src/wp-includes/media.php

    r61453 r61463  
    60376037         */
    60386038        if ( 'img' === $tag_name ) {
    6039                 if ( isset( $attr['decoding'] ) ) {
    6040                         $loading_attrs['decoding'] = $attr['decoding'];
    6041                 } else {
    6042                         $loading_attrs['decoding'] = 'async';
    6043                 }
     6039                $loading_attrs['decoding'] = $attr['decoding'] ?? 'async';
    60446040        }
    60456041
  • trunk/src/wp-includes/meta.php

    r60264 r61463  
    675675        if ( ! $meta_cache ) {
    676676                $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
    677                 if ( isset( $meta_cache[ $object_id ] ) ) {
    678                         $meta_cache = $meta_cache[ $object_id ];
    679                 } else {
    680                         $meta_cache = null;
    681                 }
     677                $meta_cache = $meta_cache[ $object_id ] ?? null;
    682678        }
    683679
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r61429 r61463  
    365365
    366366                if ( empty( $path ) ) {
    367                         if ( isset( $_SERVER['PATH_INFO'] ) ) {
    368                                 $path = $_SERVER['PATH_INFO'];
    369                         } else {
    370                                 $path = '/';
    371                         }
     367                        $path = $_SERVER['PATH_INFO'] ?? '/';
    372368                }
    373369
  • trunk/src/wp-includes/theme.php

    r61457 r61463  
    15301530                $header_index = $header->ID;
    15311531
    1532                 $header_images[ $header_index ]                  = array();
    1533                 $header_images[ $header_index ]['attachment_id'] = $header->ID;
    1534                 $header_images[ $header_index ]['url']           = $url;
    1535                 $header_images[ $header_index ]['thumbnail_url'] = $url;
    1536                 $header_images[ $header_index ]['alt_text']      = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
    1537 
    1538                 if ( isset( $header_data['attachment_parent'] ) ) {
    1539                         $header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent'];
    1540                 } else {
    1541                         $header_images[ $header_index ]['attachment_parent'] = '';
    1542                 }
     1532                $header_images[ $header_index ]                      = array();
     1533                $header_images[ $header_index ]['attachment_id']     = $header->ID;
     1534                $header_images[ $header_index ]['url']               = $url;
     1535                $header_images[ $header_index ]['thumbnail_url']     = $url;
     1536                $header_images[ $header_index ]['alt_text']          = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
     1537                $header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent'] ?? '';
    15431538
    15441539                if ( isset( $header_data['width'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.