Make WordPress Core

Changeset 61434


Ignore:
Timestamp:
01/05/2026 05:51:15 AM (9 months ago)
Author:
westonruter
Message:

Code Modernization: Comments: 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 [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

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

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-comments.php

    r60235 r61434  
    338338
    339339                if ( $spammed > 0 ) {
    340                         $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
     340                        $ids = $_REQUEST['ids'] ?? 0;
    341341
    342342                        $messages[] = sprintf(
    … …  
    360360
    361361                if ( $trashed > 0 ) {
    362                         $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
     362                        $ids = $_REQUEST['ids'] ?? 0;
    363363
    364364                        $messages[] = sprintf(
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r61183 r61434  
    5050                                'singular' => 'comment',
    5151                                'ajax'     => true,
    52                                 'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
     52                                'screen'   => $args['screen'] ?? null,
    5353                        )
    5454                );
    … …  
    9494                }
    9595
    96                 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
     96                $comment_status = $_REQUEST['comment_status'] ?? 'all';
    9797
    9898                if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ), true ) ) {
    … …  
    145145
    146146                $args = array(
    147                         'status'                    => isset( $status_map[ $comment_status ] ) ? $status_map[ $comment_status ] : $comment_status,
     147                        'status'                    => $status_map[ $comment_status ] ?? $comment_status,
    148148                        'search'                    => $search,
    149149                        'user_id'                   => $user_id,
  • trunk/src/wp-includes/comment.php

    r61387 r61434  
    22162216         * @param string $comment_agent The comment author's browser user agent.
    22172217         */
    2218         $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) );
     2218        $commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( $commentdata['comment_agent'] ?? '' ) );
    22192219        /** This filter is documented in wp-includes/comment.php */
    22202220        $commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] );
    … …  
    23342334
    23352335        if ( ! isset( $commentdata['comment_agent'] ) ) {
    2336                 $commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
     2336                $commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT'] ?? '';
    23372337        }
    23382338
    … …  
    26332633        $filter_comment = false;
    26342634        if ( ! has_filter( 'pre_comment_content', 'wp_filter_kses' ) ) {
    2635                 $filter_comment = ! user_can( isset( $comment['user_id'] ) ? $comment['user_id'] : 0, 'unfiltered_html' );
     2635                $filter_comment = ! user_can( $comment['user_id'] ?? 0, 'unfiltered_html' );
    26362636        }
    26372637
Note: See TracChangeset for help on using the changeset viewer.