Make WordPress Core

Changeset 61445


Ignore:
Timestamp:
01/06/2026 06:05:20 AM (2 months ago)
Author:
westonruter
Message:

Code Modernization: Taxonomy, Posts/Post Types, Options/Meta APIs, Query, General: 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 [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:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r61255 r61445  
    7777            array(
    7878                'plural' => 'posts',
    79                 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     79                'screen' => $args['screen'] ?? null,
    8080            )
    8181        );
     
    532532        }
    533533
    534         $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
     534        $displayed_post_format = $_GET['post_format'] ?? '';
    535535        ?>
    536536        <label for="filter-by-format" class="screen-reader-text">
     
    12651265        <div class="post-com-count-wrapper">
    12661266        <?php
    1267             $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
     1267            $pending_comments = $this->comment_pending_count[ $post->ID ] ?? 0;
    12681268
    12691269            $this->comments_bubble( $post->ID, $pending_comments );
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r60498 r61445  
    4242                'plural'   => 'tags',
    4343                'singular' => 'tag',
    44                 'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
     44                'screen'   => $args['screen'] ?? null,
    4545            )
    4646        );
  • trunk/src/wp-admin/includes/post.php

    r61440 r61445  
    430430        }
    431431
    432         $attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array();
     432        $attachment_data = $post_data['attachments'][ $post_id ] ?? array();
    433433
    434434        /** This filter is documented in wp-admin/includes/media.php */
     
    10151015    $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : '';
    10161016    $metakeyinput  = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : '';
    1017     $metavalue     = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
     1017    $metavalue     = $_POST['metavalue'] ?? '';
    10181018    if ( is_string( $metavalue ) ) {
    10191019        $metavalue = trim( $metavalue );
     
    20442044     * this is hooked on inner core hooks where a valid nonce was already checked.
    20452045     */
    2046     $posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST;
     2046    $posted_data = $_POST['data']['wp_autosave'] ?? $_POST;
    20472047
    20482048    $post_type = get_post_type( $new_autosave['post_parent'] );
  • trunk/src/wp-includes/class-wp-meta-query.php

    r60176 r61445  
    620620
    621621        // Determine the data type.
    622         $_meta_type     = isset( $clause['type'] ) ? $clause['type'] : '';
     622        $_meta_type     = $clause['type'] ?? '';
    623623        $meta_type      = $this->get_cast_for_type( $_meta_type );
    624624        $clause['cast'] = $meta_type;
  • trunk/src/wp-includes/class-wp-term.php

    r54133 r61445  
    237237                $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' );
    238238                foreach ( $columns as $column ) {
    239                     $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null;
     239                    $data->{$column} = $this->{$column} ?? null;
    240240                }
    241241
  • trunk/src/wp-includes/class-wp.php

    r61111 r61445  
    168168            $this->did_permalink = true;
    169169
    170             $pathinfo         = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : '';
     170            $pathinfo         = $_SERVER['PATH_INFO'] ?? '';
    171171            list( $pathinfo ) = explode( '?', $pathinfo );
    172172            $pathinfo         = str_replace( '%', '%25', $pathinfo );
     
    540540
    541541        if ( is_singular() ) {
    542             $post = isset( $wp_query->post ) ? $wp_query->post : null;
     542            $post = $wp_query->post ?? null;
    543543
    544544            // Only set X-Pingback for single posts that allow pings.
     
    670670        $GLOBALS['query_string'] = $this->query_string;
    671671        $GLOBALS['posts']        = & $wp_query->posts;
    672         $GLOBALS['post']         = isset( $wp_query->post ) ? $wp_query->post : null;
     672        $GLOBALS['post']         = $wp_query->post ?? null;
    673673        $GLOBALS['request']      = $wp_query->request;
    674674
     
    756756
    757757            if ( is_singular() ) {
    758                 $post = isset( $wp_query->post ) ? $wp_query->post : null;
     758                $post = $wp_query->post ?? null;
    759759                $next = '<!--nextpage-->';
    760760
  • trunk/src/wp-includes/functions.php

    r61411 r61445  
    953953            if ( $headers ) {
    954954                $len           = isset( $headers['Content-Length'] ) ? (int) $headers['Content-Length'] : 0;
    955                 $type          = isset( $headers['Content-Type'] ) ? $headers['Content-Type'] : '';
     955                $type          = $headers['Content-Type'] ?? '';
    956956                $allowed_types = array( 'video', 'audio' );
    957957
     
    36913691        );
    36923692
    3693         $redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
     3693        $redirect_to = $_REQUEST['redirect_to'] ?? '';
    36943694
    36953695        $html  = $title;
     
    61406140 */
    61416141function is_lighttpd_before_150() {
    6142     $server_parts    = explode( '/', isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
    6143     $server_parts[1] = isset( $server_parts[1] ) ? $server_parts[1] : '';
     6142    $server_parts    = explode( '/', $_SERVER['SERVER_SOFTWARE'] ?? '' );
     6143    $server_parts[1] = $server_parts[1] ?? '';
    61446144
    61456145    return ( 'lighttpd' === $server_parts[0] && -1 === version_compare( $server_parts[1], '1.5.0' ) );
     
    71227122        $tortoise
    71237123    &&
    7124         ( $evanescent_hare = isset( $override[ $hare ] ) ? $override[ $hare ] : call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
     7124        ( $evanescent_hare = $override[ $hare ] ?? call_user_func_array( $callback, array_merge( array( $hare ), $callback_args ) ) )
    71257125    &&
    7126         ( $hare = isset( $override[ $evanescent_hare ] ) ? $override[ $evanescent_hare ] : call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
     7126        ( $hare = $override[ $evanescent_hare ] ?? call_user_func_array( $callback, array_merge( array( $evanescent_hare ), $callback_args ) ) )
    71277127    ) {
    71287128        if ( $_return_loop ) {
     
    71387138
    71397139        // Increment tortoise by one step.
    7140         $tortoise = isset( $override[ $tortoise ] ) ? $override[ $tortoise ] : call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
     7140        $tortoise = $override[ $tortoise ] ?? call_user_func_array( $callback, array_merge( array( $tortoise ), $callback_args ) );
    71417141    }
    71427142
     
    72677267                $caller[] = "{$call['function']}('{$call['args'][0]}')";
    72687268            } elseif ( in_array( $call['function'], array( 'include', 'include_once', 'require', 'require_once' ), true ) ) {
    7269                 $filename = isset( $call['args'][0] ) ? $call['args'][0] : '';
     7269                $filename = $call['args'][0] ?? '';
    72707270                $caller[] = $call['function'] . "('" . str_replace( $truncate_paths, '', wp_normalize_path( $filename ) ) . "')";
    72717271            } else {
  • trunk/src/wp-includes/option.php

    r61387 r61445  
    17561756    $all_user_settings = get_all_user_settings();
    17571757
    1758     return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default_value;
     1758    return $all_user_settings[ $name ] ?? $default_value;
    17591759}
    17601760
  • trunk/src/wp-includes/post-template.php

    r61269 r61445  
    119119    $post = get_post( $post );
    120120
    121     $post_title = isset( $post->post_title ) ? $post->post_title : '';
    122     $post_id    = isset( $post->ID ) ? $post->ID : 0;
     121    $post_title = $post->post_title ?? '';
     122    $post_id    = $post->ID ?? 0;
    123123
    124124    if ( ! is_admin() ) {
     
    192192
    193193    $post_guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
    194     $post_id   = isset( $post->ID ) ? $post->ID : 0;
     194    $post_id   = $post->ID ?? 0;
    195195
    196196    /**
     
    222222    $post = get_post( $post );
    223223
    224     $post_guid = isset( $post->guid ) ? $post->guid : '';
    225     $post_id   = isset( $post->ID ) ? $post->ID : 0;
     224    $post_guid = $post->guid ?? '';
     225    $post_id   = $post->ID ?? 0;
    226226
    227227    /**
  • trunk/src/wp-includes/post.php

    r61387 r61445  
    22022202
    22032203    if ( ! isset( $data_object->labels['name_admin_bar'] ) ) {
    2204         $data_object->labels['name_admin_bar'] =
    2205             isset( $data_object->labels['singular_name'] )
    2206             ? $data_object->labels['singular_name']
    2207             : $data_object->name;
     2204        $data_object->labels['name_admin_bar'] = $data_object->labels['singular_name'] ?? $data_object->name;
    22082205    }
    22092206
     
    28572854    $custom = get_post_custom( $post_id );
    28582855
    2859     return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
     2856    return $custom[ $key ] ?? null;
    28602857}
    28612858
     
    47314728    // These variables are needed by compact() later.
    47324729    $post_content_filtered = $postarr['post_content_filtered'];
    4733     $post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
     4730    $post_author           = $postarr['post_author'] ?? $user_id;
    47344731    $ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
    47354732    $to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
    4736     $pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
    4737     $import_id             = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
     4733    $pinged                = $postarr['pinged'] ?? '';
     4734    $import_id             = $postarr['import_id'] ?? 0;
    47384735
    47394736    /*
     
    47474744    }
    47484745
    4749     $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
     4746    $post_password = $postarr['post_password'] ?? '';
    47504747    if ( 'private' === $post_status ) {
    47514748        $post_password = '';
     
    48164813
    48174814    // Don't unslash.
    4818     $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : '';
     4815    $post_mime_type = $postarr['post_mime_type'] ?? '';
    48194816
    48204817    // Expected_slashed (everything!).
  • trunk/src/wp-includes/revision.php

    r61387 r61445  
    9090    $revision_data['post_type']     = 'revision';
    9191    $revision_data['post_name']     = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version.
    92     $revision_data['post_date']     = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
    93     $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
     92    $revision_data['post_date']     = $post['post_modified'] ?? '';
     93    $revision_data['post_date_gmt'] = $post['post_modified_gmt'] ?? '';
    9494
    9595    return $revision_data;
  • trunk/src/wp-includes/taxonomy.php

    r61387 r61445  
    17241724    $do_object = is_object( $term );
    17251725
    1726     $term_id = $do_object ? $term->term_id : ( isset( $term['term_id'] ) ? $term['term_id'] : 0 );
     1726    $term_id = $do_object ? $term->term_id : ( $term['term_id'] ?? 0 );
    17271727
    17281728    foreach ( (array) $fields as $field ) {
     
    32813281    $parsed_args['slug'] = $slug;
    32823282
    3283     $term_group = isset( $parsed_args['term_group'] ) ? $parsed_args['term_group'] : 0;
     3283    $term_group = $parsed_args['term_group'] ?? 0;
    32843284    if ( $args['alias_of'] ) {
    32853285        $alias = get_term_by( 'slug', $args['alias_of'], $taxonomy );
Note: See TracChangeset for help on using the changeset viewer.