Skip to content

Commit e142030

Browse files
committed
Code Modernization: Comments: Use null coalescing operator instead of isset() ternaries.
Developed as a subset of #10654 Initially developed in #4886 Follow-up to [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. Props costdev, westonruter. See #58874, #63430. git-svn-id: https://develop.svn.wordpress.org/trunk@61434 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a00cc83 commit e142030

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/wp-admin/edit-comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
}
338338

339339
if ( $spammed > 0 ) {
340-
$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
340+
$ids = $_REQUEST['ids'] ?? 0;
341341

342342
$messages[] = sprintf(
343343
/* translators: %s: Number of comments. */
@@ -359,7 +359,7 @@
359359
}
360360

361361
if ( $trashed > 0 ) {
362-
$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
362+
$ids = $_REQUEST['ids'] ?? 0;
363363

364364
$messages[] = sprintf(
365365
/* translators: %s: Number of comments. */

src/wp-admin/includes/class-wp-comments-list-table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct( $args = array() ) {
4949
'plural' => 'comments',
5050
'singular' => 'comment',
5151
'ajax' => true,
52-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
52+
'screen' => $args['screen'] ?? null,
5353
)
5454
);
5555
}
@@ -93,7 +93,7 @@ public function prepare_items() {
9393
$mode = get_user_setting( 'posts_list_mode', 'list' );
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 ) ) {
9999
$comment_status = 'all';
@@ -144,7 +144,7 @@ public function prepare_items() {
144144
);
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,
150150
'offset' => $start,

src/wp-includes/comment.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ function wp_filter_comment( $commentdata ) {
22152215
*
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'] );
22212221
/**
@@ -2333,7 +2333,7 @@ function wp_new_comment( $commentdata, $wp_error = false ) {
23332333
}
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

23392339
/**
@@ -2632,7 +2632,7 @@ function wp_update_comment( $commentarr, $wp_error = false ) {
26322632

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

26382638
if ( $filter_comment ) {

0 commit comments

Comments
 (0)