Skip to content

Commit 87f0388

Browse files
committed
Use null coalescing operator for remaining uses of isset()
1 parent 3d9fde3 commit 87f0388

File tree

65 files changed

+138
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+138
-139
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/edit-form-advanced.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
*/
7070
$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
7171
$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
72-
$action = isset( $action ) ? $action : '';
72+
$action = $action ?? '';
7373

7474
if ( (int) get_option( 'page_for_posts' ) === $post->ID && empty( $post->post_content ) ) {
7575
add_action( 'edit_form_after_title', '_wp_posts_page_notice' );

src/wp-admin/includes/ajax-actions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ function wp_ajax_closed_postboxes() {
18081808
$hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
18091809
$hidden = array_filter( $hidden );
18101810

1811-
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
1811+
$page = $_POST['page'] ?? '';
18121812

18131813
if ( sanitize_key( $page ) !== $page ) {
18141814
wp_die( 0 );
@@ -1839,7 +1839,7 @@ function wp_ajax_closed_postboxes() {
18391839
*/
18401840
function 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 ) {
18451845
wp_die( 0 );
@@ -1988,13 +1988,13 @@ function wp_ajax_menu_locations_save() {
19881988
function wp_ajax_meta_box_order() {
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 ) {
19941994
$page_columns = (int) $page_columns;
19951995
}
19961996

1997-
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
1997+
$page = $_POST['page'] ?? '';
19981998

19991999
if ( sanitize_key( $page ) !== $page ) {
20002000
wp_die( 0 );
@@ -2052,7 +2052,7 @@ function wp_ajax_get_permalink() {
20522052
function wp_ajax_sample_permalink() {
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'] : '';
2055+
$title = $_POST['new_title'] ?? '';
20562056
$slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
20572057
wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
20582058
}

src/wp-admin/includes/class-core-upgrader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public static function should_update_to_version( $offered_ver ) {
403403
public function check_files() {
404404
global $wp_version, $wp_local_package;
405405

406-
$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
406+
$checksums = get_core_checksums( $wp_version, $wp_local_package ?? 'en_US' );
407407

408408
if ( ! is_array( $checksums ) ) {
409409
return false;

src/wp-admin/includes/class-custom-image-header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ final public function create_attachment_object( $cropped, $parent_attachment_id
13511351
* @return int Attachment ID.
13521352
*/
13531353
final public function insert_attachment( $attachment, $cropped ) {
1354-
$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
1354+
$parent_id = $attachment['post_parent'] ?? null;
13551355
unset( $attachment['post_parent'] );
13561356

13571357
$attachment_id = wp_insert_attachment( $attachment, $cropped );
@@ -1584,8 +1584,8 @@ public function get_uploaded_header_images() {
15841584

15851585
foreach ( $header_images as &$header_image ) {
15861586
$header_meta = get_post_meta( $header_image['attachment_id'] );
1587-
$header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
1588-
$header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
1587+
$header_image['timestamp'] = $header_meta[ $timestamp_key ] ?? '';
1588+
$header_image['alt_text'] = $header_meta[ $alt_text_key ] ?? '';
15891589
}
15901590

15911591
return $header_images;

src/wp-admin/includes/class-plugin-installer-skin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct( $args = array() ) {
4545

4646
$this->type = $args['type'];
4747
$this->url = $args['url'];
48-
$this->api = isset( $args['api'] ) ? $args['api'] : array();
48+
$this->api = $args['api'] ?? array();
4949
$this->overwrite = $args['overwrite'];
5050

5151
parent::__construct( $args );
@@ -265,8 +265,8 @@ private function do_overwrite() {
265265
$blocked_message = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>';
266266
$blocked_message .= '<ul class="ul-disc">';
267267

268-
$requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
269-
$requires_wp = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
268+
$requires_php = $new_plugin_data['RequiresPHP'] ?? null;
269+
$requires_wp = $new_plugin_data['RequiresWP'] ?? null;
270270

271271
if ( ! is_php_version_compatible( $requires_php ) ) {
272272
$error = sprintf(

src/wp-admin/includes/class-plugin-upgrader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ public function check_package( $source ) {
490490
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
491491
}
492492

493-
$requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
494-
$requires_wp = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
493+
$requires_php = $new_plugin_data['RequiresPHP'] ?? null;
494+
$requires_wp = $new_plugin_data['RequiresWP'] ?? null;
495495

496496
if ( ! is_php_version_compatible( $requires_php ) ) {
497497
$error = sprintf(
@@ -570,7 +570,7 @@ public function deactivate_plugin_before_upgrade( $response, $plugin ) {
570570
return $response;
571571
}
572572

573-
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
573+
$plugin = $plugin['plugin'] ?? '';
574574
if ( empty( $plugin ) ) {
575575
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
576576
}
@@ -604,7 +604,7 @@ public function active_before( $response, $plugin ) {
604604
return $response;
605605
}
606606

607-
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
607+
$plugin = $plugin['plugin'] ?? '';
608608

609609
// Only run if plugin is active.
610610
if ( ! is_plugin_active( $plugin ) ) {
@@ -640,7 +640,7 @@ public function active_after( $response, $plugin ) {
640640
return $response;
641641
}
642642

643-
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
643+
$plugin = $plugin['plugin'] ?? '';
644644

645645
// Only run if plugin is active.
646646
if ( ! is_plugin_active( $plugin ) ) {
@@ -679,7 +679,7 @@ public function delete_old_plugin( $removed, $local_destination, $remote_destina
679679
return $removed; // Pass errors through.
680680
}
681681

682-
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
682+
$plugin = $plugin['plugin'] ?? '';
683683
if ( empty( $plugin ) ) {
684684
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
685685
}

src/wp-admin/includes/class-theme-installer-skin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct( $args = array() ) {
4545

4646
$this->type = $args['type'];
4747
$this->url = $args['url'];
48-
$this->api = isset( $args['api'] ) ? $args['api'] : array();
48+
$this->api = $args['api'] ?? array();
4949
$this->overwrite = $args['overwrite'];
5050

5151
parent::__construct( $args );
@@ -310,8 +310,8 @@ private function do_overwrite() {
310310
$blocked_message = '<p>' . esc_html__( 'The theme cannot be updated due to the following:' ) . '</p>';
311311
$blocked_message .= '<ul class="ul-disc">';
312312

313-
$requires_php = isset( $new_theme_data['RequiresPHP'] ) ? $new_theme_data['RequiresPHP'] : null;
314-
$requires_wp = isset( $new_theme_data['RequiresWP'] ) ? $new_theme_data['RequiresWP'] : null;
313+
$requires_php = $new_theme_data['RequiresPHP'] ?? null;
314+
$requires_wp = $new_theme_data['RequiresWP'] ?? null;
315315

316316
if ( ! is_php_version_compatible( $requires_php ) ) {
317317
$error = sprintf(

src/wp-admin/includes/class-theme-upgrader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ public function check_package( $source ) {
639639
);
640640
}
641641

642-
$requires_php = isset( $new_theme_data['RequiresPHP'] ) ? $new_theme_data['RequiresPHP'] : null;
643-
$requires_wp = isset( $new_theme_data['RequiresWP'] ) ? $new_theme_data['RequiresWP'] : null;
642+
$requires_php = $new_theme_data['RequiresPHP'] ?? null;
643+
$requires_wp = $new_theme_data['RequiresWP'] ?? null;
644644

645645
if ( ! is_php_version_compatible( $requires_php ) ) {
646646
$error = sprintf(
@@ -685,7 +685,7 @@ public function current_before( $response, $theme ) {
685685
return $response;
686686
}
687687

688-
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
688+
$theme = $theme['theme'] ?? '';
689689

690690
// Only run if active theme.
691691
if ( get_stylesheet() !== $theme ) {
@@ -717,7 +717,7 @@ public function current_after( $response, $theme ) {
717717
return $response;
718718
}
719719

720-
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
720+
$theme = $theme['theme'] ?? '';
721721

722722
// Only run if active theme.
723723
if ( get_stylesheet() !== $theme ) {

src/wp-admin/includes/class-wp-community-events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function get_events( $location_search = '', $timezone = '' ) {
122122
} elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) {
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
}
128128

0 commit comments

Comments
 (0)