Skip to content

Commit 14b647c

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

19 files changed

+32
-32
lines changed

src/wp-admin/includes/class-wp-debug-data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ private static function get_wp_server(): array {
373373
);
374374
$fields['httpd_software'] = array(
375375
'label' => __( 'Web server' ),
376-
'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : __( 'Unable to determine what web server software is used' ) ),
377-
'debug' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : 'unknown' ),
376+
'value' => $_SERVER['SERVER_SOFTWARE'] ?? __( 'Unable to determine what web server software is used' ),
377+
'debug' => $_SERVER['SERVER_SOFTWARE'] ?? 'unknown',
378378
);
379379
$fields['php_version'] = array(
380380
'label' => __( 'PHP version' ),

src/wp-admin/includes/class-wp-ms-sites-list-table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct( $args = array() ) {
4444
parent::__construct(
4545
array(
4646
'plural' => 'sites',
47-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
47+
'screen' => $args['screen'] ?? null,
4848
)
4949
);
5050
}
@@ -135,7 +135,7 @@ public function prepare_items() {
135135
}
136136
}
137137

138-
$order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
138+
$order_by = $_REQUEST['orderby'] ?? '';
139139
if ( 'registered' === $order_by ) {
140140
// 'registered' is a valid field name.
141141
} elseif ( 'lastupdated' === $order_by ) {

src/wp-admin/includes/class-wp-ms-themes-list-table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public function __construct( $args = array() ) {
4848
parent::__construct(
4949
array(
5050
'plural' => 'themes',
51-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
51+
'screen' => $args['screen'] ?? null,
5252
)
5353
);
5454

55-
$status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
55+
$status = $_REQUEST['theme_status'] ?? 'all';
5656
if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) {
5757
$status = 'all';
5858
}
@@ -153,7 +153,7 @@ public function prepare_items() {
153153
$themes[ $filter ][ $key ] = $themes['all'][ $key ];
154154

155155
$theme_data = array(
156-
'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
156+
'update_supported' => $theme->update_supported ?? true,
157157
);
158158

159159
// Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.

src/wp-admin/includes/class-wp-ms-users-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function prepare_items() {
4141

4242
$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
4343

44-
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
44+
$role = $_REQUEST['role'] ?? '';
4545

4646
$paged = $this->get_pagenum();
4747

src/wp-admin/includes/class-wp-site-health.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ public function enqueue_scripts() {
150150
if ( is_string( $test['test'] ) ) {
151151
$health_check_js_variables['site_status']['async'][] = array(
152152
'test' => $test['test'],
153-
'has_rest' => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ),
153+
'has_rest' => $test['has_rest'] ?? false,
154154
'completed' => false,
155-
'headers' => isset( $test['headers'] ) ? $test['headers'] : array(),
155+
'headers' => $test['headers'] ?? array(),
156156
);
157157
}
158158
}
@@ -1052,10 +1052,10 @@ public function get_test_php_extensions() {
10521052
$failures = array();
10531053

10541054
foreach ( $modules as $library => $module ) {
1055-
$extension_name = ( isset( $module['extension'] ) ? $module['extension'] : null );
1056-
$function_name = ( isset( $module['function'] ) ? $module['function'] : null );
1057-
$constant_name = ( isset( $module['constant'] ) ? $module['constant'] : null );
1058-
$class_name = ( isset( $module['class'] ) ? $module['class'] : null );
1055+
$extension_name = $module['extension'] ?? null;
1056+
$function_name = $module['function'] ?? null;
1057+
$constant_name = $module['constant'] ?? null;
1058+
$class_name = $module['class'] ?? null;
10591059

10601060
// If this module is a fallback for another function, check if that other function passed.
10611061
if ( isset( $module['fallback_for'] ) ) {
@@ -3023,7 +3023,7 @@ private function get_cron_tasks() {
30233023
'sig' => $sig,
30243024
'args' => $data['args'],
30253025
'schedule' => $data['schedule'],
3026-
'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
3026+
'interval' => $data['interval'] ?? null,
30273027
);
30283028

30293029
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct( $args = array() ) {
4646
array(
4747
'singular' => 'user',
4848
'plural' => 'users',
49-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
49+
'screen' => $args['screen'] ?? null,
5050
)
5151
);
5252

@@ -85,7 +85,7 @@ public function prepare_items() {
8585

8686
$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
8787

88-
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
88+
$role = $_REQUEST['role'] ?? '';
8989

9090
$per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
9191
$users_per_page = $this->get_items_per_page( $per_page );

src/wp-admin/includes/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function edit_user( $user_id = 0 ) {
6262
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
6363
}
6464

65-
$potential_role = isset( $wp_roles->role_objects[ $new_role ] ) ? $wp_roles->role_objects[ $new_role ] : false;
65+
$potential_role = $wp_roles->role_objects[ $new_role ] ?? false;
6666

6767
/*
6868
* Don't let anyone with 'promote_users' edit their own role to something without it.

src/wp-admin/my-sites.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
wp_die( __( 'Sorry, you are not allowed to access this page.' ) );
1818
}
1919

20-
$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
20+
$action = $_POST['action'] ?? 'splash';
2121

2222
$blogs = get_blogs_of_user( $current_user->ID );
2323

src/wp-admin/network/site-themes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
$action = $wp_list_table->current_action();
3131

32-
$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
32+
$s = $_REQUEST['s'] ?? '';
3333

3434
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
3535
$temp_args = array( 'enabled', 'disabled', 'error' );

src/wp-admin/network/themes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
$action = $wp_list_table->current_action();
2121

22-
$s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
22+
$s = $_REQUEST['s'] ?? '';
2323

2424
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
2525
$temp_args = array(

0 commit comments

Comments
 (0)