Make WordPress Core

Changeset 61456


Ignore:
Timestamp:
01/09/2026 04:20:21 AM (8 weeks ago)
Author:
westonruter
Message:

Code Modernization: Administration: 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 [61455], [61454], [61453], [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/wp-admin
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r61411 r61456  
    18091809    $hidden = array_filter( $hidden );
    18101810
    1811     $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
     1811    $page = $_POST['page'] ?? '';
    18121812
    18131813    if ( sanitize_key( $page ) !== $page ) {
     
    18401840function wp_ajax_hidden_columns() {
    18411841    check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
    1842     $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
     1842    $page = $_POST['page'] ?? '';
    18431843
    18441844    if ( sanitize_key( $page ) !== $page ) {
     
    19891989    check_ajax_referer( 'meta-box-order' );
    19901990    $order        = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
    1991     $page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
     1991    $page_columns = $_POST['page_columns'] ?? 'auto';
    19921992
    19931993    if ( 'auto' !== $page_columns ) {
     
    19951995    }
    19961996
    1997     $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
     1997    $page = $_POST['page'] ?? '';
    19981998
    19991999    if ( sanitize_key( $page ) !== $page ) {
     
    20532053    check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    20542054    $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
    2055     $title   = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
    2056     $slug    = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
     2055    $title   = $_POST['new_title'] ?? '';
     2056    $slug    = $_POST['new_slug'] ?? null;
    20572057    wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
    20582058}
     
    23942394
    23952395    $sidebars = wp_get_sidebars_widgets();
    2396     $sidebar  = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array();
     2396    $sidebar  = $sidebars[ $sidebar_id ] ?? array();
    23972397
    23982398    // Delete.
     
    33543354
    33553355    if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
    3356         $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
    3357         $size  = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
    3358         $alt   = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
     3356        $align = $attachment['align'] ?? 'none';
     3357        $size  = $attachment['image-size'] ?? 'medium';
     3358        $alt   = $attachment['image_alt'] ?? '';
    33593359
    33603360        // No whitespace-only captions.
    3361         $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
     3361        $caption = $attachment['post_excerpt'] ?? '';
    33623362        if ( '' === trim( $caption ) ) {
    33633363            $caption = '';
     
    33693369        $html = stripslashes_deep( $_POST['html'] );
    33703370    } else {
    3371         $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
     3371        $html = $attachment['post_title'] ?? '';
    33723372        $rel  = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized.
    33733373
     
    34223422    }
    34233423
    3424     $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
     3424    $post = get_post( $_POST['post_id'] ?? 0 );
    34253425
    34263426    // Ping WordPress for an embed.
     
    36483648    }
    36493649
    3650     $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
     3650    $old_filter = $args['browse'] ?? 'search';
    36513651
    36523652    /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
  • trunk/src/wp-admin/includes/class-wp-community-events.php

    r60273 r61456  
    123123            $response_error = new WP_Error(
    124124                'api-invalid-response',
    125                 isset( $response_body['error'] ) ? $response_body['error'] : __( 'Unknown API error.' )
     125                $response_body['error'] ?? __( 'Unknown API error.' )
    126126            );
    127127        }
  • trunk/src/wp-admin/includes/class-wp-links-list-table.php

    r58745 r61456  
    3030            array(
    3131                'plural' => 'bookmarks',
    32                 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     32                'screen' => $args['screen'] ?? null,
    3333            )
    3434        );
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r61440 r61456  
    14521452
    14531453            if ( isset( $sortable[ $column_key ] ) ) {
    1454                 $orderby       = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
    1455                 $desc_first    = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
    1456                 $abbr          = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
    1457                 $orderby_text  = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
    1458                 $initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
     1454                $orderby       = $sortable[ $column_key ][0] ?? '';
     1455                $desc_first    = $sortable[ $column_key ][1] ?? false;
     1456                $abbr          = $sortable[ $column_key ][2] ?? '';
     1457                $orderby_text  = $sortable[ $column_key ][3] ?? '';
     1458                $initial_order = $sortable[ $column_key ][4] ?? '';
    14591459
    14601460                /*
     
    15681568
    15691569            if ( isset( $sortable[ $column_key ] ) ) {
    1570                 $orderby       = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
    1571                 $desc_first    = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
    1572                 $abbr          = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
    1573                 $orderby_text  = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
    1574                 $initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
     1570                $orderby       = $sortable[ $column_key ][0] ?? '';
     1571                $desc_first    = $sortable[ $column_key ][1] ?? false;
     1572                $abbr          = $sortable[ $column_key ][2] ?? '';
     1573                $orderby_text  = $sortable[ $column_key ][3] ?? '';
     1574                $initial_order = $sortable[ $column_key ][4] ?? '';
    15751575
    15761576                if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r60528 r61456  
    557557            }
    558558
    559             $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
    560             $requires_wp  = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
     559            $requires_php = $plugin['requires_php'] ?? null;
     560            $requires_wp  = $plugin['requires'] ?? null;
    561561
    562562            $compatible_php = is_php_version_compatible( $requires_php );
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r60723 r61456  
    4343            array(
    4444                'plural' => 'plugins',
    45                 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     45                'screen' => $args['screen'] ?? null,
    4646            )
    4747        );
     
    727727        list( $plugin_file, $plugin_data ) = $item;
    728728
    729         $plugin_slug    = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] );
     729        $plugin_slug    = $plugin_data['slug'] ?? sanitize_title( $plugin_data['Name'] );
    730730        $plugin_id_attr = $plugin_slug;
    731731
     
    754754        $restrict_network_only   = false;
    755755
    756         $requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null;
    757         $requires_wp  = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null;
     756        $requires_php = $plugin_data['RequiresPHP'] ?? null;
     757        $requires_wp  = $plugin_data['RequiresWP'] ?? null;
    758758
    759759        $compatible_php = is_php_version_compatible( $requires_php );
  • trunk/src/wp-admin/includes/class-wp-screen.php

    r61300 r61456  
    809809        );
    810810
    811         $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
     811        $old_help = self::$_old_compat_help[ $this->id ] ?? '';
    812812
    813813        /**
     
    12581258
    12591259        if ( 'edit_comments_per_page' === $option ) {
    1260             $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
     1260            $comment_status = $_REQUEST['comment_status'] ?? 'all';
    12611261
    12621262            /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
  • trunk/src/wp-admin/includes/class-wp-themes-list-table.php

    r61440 r61456  
    3333            array(
    3434                'ajax'   => true,
    35                 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     35                'screen' => $args['screen'] ?? null,
    3636            )
    3737        );
  • trunk/src/wp-admin/includes/credits.php

    r59541 r61456  
    121121 */
    122122function wp_credits_section_list( $credits = array(), $slug = '' ) {
    123     $group_data   = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
     123    $group_data   = $credits['groups'][ $slug ] ?? array();
    124124    $credits_data = $credits['data'];
    125125    if ( ! count( $group_data ) ) {
  • trunk/src/wp-admin/includes/file.php

    r61375 r61456  
    909909
    910910    // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
    911     $test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
    912     $test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
     911    $test_form = $overrides['test_form'] ?? true;
     912    $test_size = $overrides['test_size'] ?? true;
    913913
    914914    // If you override this, you must provide $ext and $type!!
    915     $test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
    916     $mimes     = isset( $overrides['mimes'] ) ? $overrides['mimes'] : null;
     915    $test_type = $overrides['test_type'] ?? true;
     916    $mimes     = $overrides['mimes'] ?? null;
    917917
    918918    // A correct form post will pass this test.
     
    24972497    }
    24982498
    2499     $hostname        = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
    2500     $username        = isset( $credentials['username'] ) ? $credentials['username'] : '';
    2501     $public_key      = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
    2502     $private_key     = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
    2503     $port            = isset( $credentials['port'] ) ? $credentials['port'] : '';
    2504     $connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
     2499    $hostname        = $credentials['hostname'] ?? '';
     2500    $username        = $credentials['username'] ?? '';
     2501    $public_key      = $credentials['public_key'] ?? '';
     2502    $private_key     = $credentials['private_key'] ?? '';
     2503    $port            = $credentials['port'] ?? '';
     2504    $connection_type = $credentials['connection_type'] ?? '';
    25052505
    25062506    if ( $error ) {
  • trunk/src/wp-admin/includes/meta-boxes.php

    r61440 r61456  
    12661266    }
    12671267
    1268     $link_rel  = isset( $link->link_rel ) ? $link->link_rel : '';
     1268    $link_rel  = $link->link_rel ?? '';
    12691269    $link_rels = preg_split( '/\s+/', $link_rel );
    12701270
     
    14551455    <tr>
    14561456        <th scope="row"><label for="link_notes"><?php _e( 'Notes' ); ?></label></th>
    1457         <td><textarea name="link_notes" id="link_notes" rows="10"><?php echo ( isset( $link->link_notes ) ? $link->link_notes : '' ); // textarea_escaped ?></textarea></td>
     1457        <td><textarea name="link_notes" id="link_notes" rows="10"><?php echo $link->link_notes ?? ''; // textarea_escaped ?></textarea></td>
    14581458    </tr>
    14591459    <tr>
  • trunk/src/wp-admin/includes/plugin-install.php

    r61411 r61456  
    797797    <div id="section-holder">
    798798    <?php
    799     $requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
    800     $requires_wp  = isset( $api->requires ) ? $api->requires : null;
     799    $requires_php = $api->requires_php ?? null;
     800    $requires_wp  = $api->requires ?? null;
    801801
    802802    $compatible_php = is_php_version_compatible( $requires_php );
  • trunk/src/wp-admin/includes/theme.php

    r58813 r61456  
    733733        }
    734734
    735         $update_requires_wp  = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
    736         $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
     735        $update_requires_wp  = $updates[ $slug ]['requires'] ?? null;
     736        $update_requires_php = $updates[ $slug ]['requires_php'] ?? null;
    737737
    738738        $auto_update        = in_array( $slug, $auto_updates, true );
  • trunk/src/wp-admin/options-privacy.php

    r59667 r61456  
    3131);
    3232
    33 $action = isset( $_POST['action'] ) ? $_POST['action'] : '';
     33$action = $_POST['action'] ?? '';
    3434
    3535get_current_screen()->add_help_tab(
Note: See TracChangeset for help on using the changeset viewer.