Skip to content

Commit 537f3d5

Browse files
committed
Code Modernization: Upgrade/Install: Use null coalescing operator instead of isset() ternaries.
Developed as a subset of #10654 Initially developed in #4886 Follow-up to [61454], [61453], [61445], [61444], [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@61455 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 58c1e21 commit 537f3d5

11 files changed

+37
-37
lines changed

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-language-pack-upgrader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function bulk_upgrade( $language_updates = array(), $args = array() ) {
265265
$language_updates_results[] = array(
266266
'language' => $language_update->language,
267267
'type' => $language_update->type,
268-
'slug' => isset( $language_update->slug ) ? $language_update->slug : 'default',
268+
'slug' => $language_update->slug ?? 'default',
269269
'version' => $language_update->version,
270270
);
271271
}

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/update-core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ function update_core( $from, $to ) {
12381238
// Find the local version of the working directory.
12391239
$working_dir_local = WP_CONTENT_DIR . '/upgrade/' . basename( $from ) . $distro;
12401240

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

12431243
if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) ) {
12441244
$checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2.

src/wp-admin/includes/update.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ function wp_plugin_update_row( $file, $plugin_data ) {
470470
);
471471

472472
$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
473-
$plugin_slug = isset( $response->slug ) ? $response->slug : $response->id;
473+
$plugin_slug = $response->slug ?? $response->id;
474474

475475
if ( isset( $response->slug ) ) {
476476
$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . '&section=changelog' );
@@ -504,7 +504,7 @@ function wp_plugin_update_row( $file, $plugin_data ) {
504504
$active_class = is_plugin_active( $file ) ? ' active' : '';
505505
}
506506

507-
$requires_php = isset( $response->requires_php ) ? $response->requires_php : null;
507+
$requires_php = $response->requires_php ?? null;
508508
$compatible_php = is_php_version_compatible( $requires_php );
509509
$notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
510510

@@ -696,8 +696,8 @@ function wp_theme_update_row( $theme_key, $theme ) {
696696

697697
$active = $theme->is_allowed( 'network' ) ? ' active' : '';
698698

699-
$requires_wp = isset( $response['requires'] ) ? $response['requires'] : null;
700-
$requires_php = isset( $response['requires_php'] ) ? $response['requires_php'] : null;
699+
$requires_wp = $response['requires'] ?? null;
700+
$requires_php = $response['requires_php'] ?? null;
701701

702702
$compatible_wp = is_wp_version_compatible( $requires_wp );
703703
$compatible_php = is_php_version_compatible( $requires_php );

src/wp-admin/update-core.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ function list_plugin_updates() {
542542
}
543543
}
544544

545-
$requires_php = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
545+
$requires_php = $plugin_data->update->requires_php ?? null;
546546
$compatible_php = is_php_version_compatible( $requires_php );
547547

548548
if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
@@ -687,8 +687,8 @@ function list_theme_updates() {
687687
}
688688

689689
foreach ( $themes as $stylesheet => $theme ) {
690-
$requires_wp = isset( $theme->update['requires'] ) ? $theme->update['requires'] : null;
691-
$requires_php = isset( $theme->update['requires_php'] ) ? $theme->update['requires_php'] : null;
690+
$requires_wp = $theme->update['requires'] ?? null;
691+
$requires_php = $theme->update['requires_php'] ?? null;
692692

693693
$compatible_wp = is_wp_version_compatible( $requires_wp );
694694
$compatible_php = is_php_version_compatible( $requires_php );
@@ -854,8 +854,8 @@ function do_core_upgrade( $reinstall = false ) {
854854
}
855855
$url = wp_nonce_url( $url, 'upgrade-core' );
856856

857-
$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
858-
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
857+
$version = $_POST['version'] ?? false;
858+
$locale = $_POST['locale'] ?? 'en_US';
859859
$update = find_core_update( $version, $locale );
860860
if ( ! $update ) {
861861
return;
@@ -947,8 +947,8 @@ function do_core_upgrade( $reinstall = false ) {
947947
* @since 2.7.0
948948
*/
949949
function do_dismiss_core_update() {
950-
$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
951-
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
950+
$version = $_POST['version'] ?? false;
951+
$locale = $_POST['locale'] ?? 'en_US';
952952
$update = find_core_update( $version, $locale );
953953
if ( ! $update ) {
954954
return;
@@ -964,8 +964,8 @@ function do_dismiss_core_update() {
964964
* @since 2.7.0
965965
*/
966966
function do_undismiss_core_update() {
967-
$version = isset( $_POST['version'] ) ? $_POST['version'] : false;
968-
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
967+
$version = $_POST['version'] ?? false;
968+
$locale = $_POST['locale'] ?? 'en_US';
969969
$update = find_core_update( $version, $locale );
970970
if ( ! $update ) {
971971
return;
@@ -975,7 +975,7 @@ function do_undismiss_core_update() {
975975
exit;
976976
}
977977

978-
$action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
978+
$action = $_GET['action'] ?? 'upgrade-core';
979979

980980
$upgrade_error = false;
981981
if ( ( 'do-theme-upgrade' === $action || ( 'do-plugin-upgrade' === $action && ! isset( $_GET['plugins'] ) ) )

src/wp-admin/update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if ( isset( $_GET['action'] ) ) {
2323
$plugin = isset( $_REQUEST['plugin'] ) ? trim( $_REQUEST['plugin'] ) : '';
2424
$theme = isset( $_REQUEST['theme'] ) ? urldecode( $_REQUEST['theme'] ) : '';
25-
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
25+
$action = $_REQUEST['action'] ?? '';
2626

2727
if ( 'update-selected' === $action ) {
2828
if ( ! current_user_can( 'update_plugins' ) ) {

0 commit comments

Comments
 (0)