Make WordPress Core

Changeset 61453


Ignore:
Timestamp:
01/09/2026 02:24:18 AM (2 months ago)
Author:
westonruter
Message:

Code Modernization: Media: Use null coalescing operator instead of isset() 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 [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

Props costdev, westonruter.
See #58874, #63430.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-custom-image-header.php

    r61440 r61453  
    13521352     */
    13531353    final public function insert_attachment( $attachment, $cropped ) {
    1354         $parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
     1354        $parent_id = $attachment['post_parent'] ?? null;
    13551355        unset( $attachment['post_parent'] );
    13561356
     
    15851585        foreach ( $header_images as &$header_image ) {
    15861586            $header_meta               = get_post_meta( $header_image['attachment_id'] );
    1587             $header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
    1588             $header_image['alt_text']  = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
     1587            $header_image['timestamp'] = $header_meta[ $timestamp_key ] ?? '';
     1588            $header_image['alt_text']  = $header_meta[ $alt_text_key ] ?? '';
    15891589        }
    15901590
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r61268 r61453  
    4848            array(
    4949                'plural' => 'media',
    50                 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     50                'screen' => $args['screen'] ?? null,
    5151            )
    5252        );
  • trunk/src/wp-admin/includes/image-edit.php

    r60703 r61453  
    110110            <input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
    111111            <input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
    112             <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
    113             <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
     112            <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo $meta['width'] ?? 0; ?>" />
     113            <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height'] ?? 0; ?>" />
    114114
    115115            <div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
     
    155155                            ?>
    156156                            </label>
    157                             <input type="number" step="1" min="0" max="<?php echo isset( $meta['width'] ) ? $meta['width'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>"  id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
     157                            <input type="number" step="1" min="0" max="<?php echo $meta['width'] ?? ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>"  id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo $meta['width'] ?? 0; ?>" />
    158158                            <span class="imgedit-separator" aria-hidden="true">&times;</span>
    159159                            <label for="imgedit-scale-height-<?php echo $post_id; ?>" class="screen-reader-text"><?php _e( 'scale height' ); ?></label>
    160                             <input type="number" step="1" min="0" max="<?php echo isset( $meta['height'] ) ? $meta['height'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
     160                            <input type="number" step="1" min="0" max="<?php echo $meta['height'] ?? ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo $meta['height'] ?? 0; ?>" />
    161161                            <button id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary"><?php esc_html_e( 'Scale' ); ?></button>
    162162                            </div>
     
    745745                    $h    = $size['height'];
    746746
    747                     $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
     747                    $scale = $sel->r ?? 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
    748748                    $image->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) );
    749749                } else {
    750                     $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
     750                    $scale = $sel->r ?? 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
    751751                    $image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
    752752                }
  • trunk/src/wp-admin/includes/media.php

    r61440 r61453  
    833833    if ( isset( $send_id ) ) {
    834834        $attachment = wp_unslash( $_POST['attachments'][ $send_id ] );
    835         $html       = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
     835        $html       = $attachment['post_title'] ?? '';
    836836
    837837        if ( ! empty( $attachment['url'] ) ) {
     
    15591559        }
    15601560
    1561         $item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) );
     1561        $item = get_media_item( $id, array( 'errors' => $errors[ $id ] ?? null ) );
    15621562
    15631563        if ( $item ) {
     
    21042104    $upload_action_url = admin_url( 'async-upload.php' );
    21052105    $post_id           = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
    2106     $_type             = isset( $type ) ? $type : '';
    2107     $_tab              = isset( $tab ) ? $tab : '';
     2106    $_type             = $type ?? '';
     2107    $_tab              = $tab ?? '';
    21082108
    21092109    $max_upload_size = wp_max_upload_size();
     
    36573657    wp_add_id3_tag_data( $metadata, $data );
    36583658
    3659     $file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;
     3659    $file_format = $metadata['fileformat'] ?? null;
    36603660
    36613661    /**
     
    37403740    wp_add_id3_tag_data( $metadata, $data );
    37413741
    3742     $file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null;
     3742    $file_format = $metadata['fileformat'] ?? null;
    37433743
    37443744    /**
  • trunk/src/wp-admin/upload.php

    r61279 r61453  
    8888    $message .= sprintf(
    8989        ' <a href="%1$s">%2$s</a>',
    90         esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
     90        esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( $_GET['ids'] ?? '' ), 'bulk-media' ) ),
    9191        __( 'Undo' )
    9292    );
     
    118118$messages[4] = __( 'Media file moved to the Trash.' ) . sprintf(
    119119    ' <a href="%1$s">%2$s</a>',
    120     esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( isset( $_GET['ids'] ) ? $_GET['ids'] : '' ), 'bulk-media' ) ),
     120    esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids=' . ( $_GET['ids'] ?? '' ), 'bulk-media' ) ),
    121121    __( 'Undo' )
    122122);
  • trunk/src/wp-includes/embed.php

    r61119 r61453  
    694694    }
    695695
    696     $width = isset( $args['width'] ) ? $args['width'] : 0;
     696    $width = $args['width'] ?? 0;
    697697
    698698    $data = get_oembed_response_data( $post_id, $width );
  • trunk/src/wp-includes/media.php

    r61411 r61453  
    12301230function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
    12311231    $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
    1232     return isset( $image[0] ) ? $image[0] : false;
     1232    return $image[0] ?? false;
    12331233}
    12341234
     
    14111411         */
    14121412        $parsed = parse_url( $image_baseurl );
    1413         $domain = isset( $parsed['host'] ) ? $parsed['host'] : '';
     1413        $domain = $parsed['host'] ?? '';
    14141414
    14151415        if ( isset( $parsed['port'] ) ) {
     
    21722172        $filtered_decoding_attr = apply_filters(
    21732173            'wp_img_tag_add_decoding_attr',
    2174             isset( $optimization_attrs['decoding'] ) ? $optimization_attrs['decoding'] : false,
     2174            $optimization_attrs['decoding'] ?? false,
    21752175            $image,
    21762176            $context
     
    22142214        $filtered_loading_attr = apply_filters(
    22152215            'wp_img_tag_add_loading_attr',
    2216             isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false,
     2216            $optimization_attrs['loading'] ?? false,
    22172217            $image,
    22182218            $context
     
    22332233             */
    22342234            if ( isset( $optimization_attrs['fetchpriority'] ) && 'high' === $optimization_attrs['fetchpriority'] &&
    2235                 ( isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false ) !== $filtered_loading_attr &&
     2235                ( $optimization_attrs['loading'] ?? false ) !== $filtered_loading_attr &&
    22362236                'lazy' === $filtered_loading_attr
    22372237            ) {
     
    23812381    }
    23822382
    2383     $value = isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false;
     2383    $value = $optimization_attrs['loading'] ?? false;
    23842384
    23852385    /**
Note: See TracChangeset for help on using the changeset viewer.