Skip to content

Commit e800ced

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

14 files changed

+53
-53
lines changed

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

Lines changed: 14 additions & 14 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,8 +2052,8 @@ 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'] : '';
2056-
$slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
2055+
$title = $_POST['new_title'] ?? '';
2056+
$slug = $_POST['new_slug'] ?? null;
20572057
wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
20582058
}
20592059

@@ -2393,7 +2393,7 @@ function wp_ajax_save_widget() {
23932393
$error = '<p>' . __( 'An error has occurred. Please reload the page and try again.' ) . '</p>';
23942394

23952395
$sidebars = wp_get_sidebars_widgets();
2396-
$sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array();
2396+
$sidebar = $sidebars[ $sidebar_id ] ?? array();
23972397

23982398
// Delete.
23992399
if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
@@ -3353,12 +3353,12 @@ function wp_ajax_send_attachment_to_editor() {
33533353
remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
33543354

33553355
if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
3356-
$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
3357-
$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
3358-
$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
3356+
$align = $attachment['align'] ?? 'none';
3357+
$size = $attachment['image-size'] ?? 'medium';
3358+
$alt = $attachment['image_alt'] ?? '';
33593359

33603360
// No whitespace-only captions.
3361-
$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
3361+
$caption = $attachment['post_excerpt'] ?? '';
33623362
if ( '' === trim( $caption ) ) {
33633363
$caption = '';
33643364
}
@@ -3368,7 +3368,7 @@ function wp_ajax_send_attachment_to_editor() {
33683368
} elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) {
33693369
$html = stripslashes_deep( $_POST['html'] );
33703370
} else {
3371-
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
3371+
$html = $attachment['post_title'] ?? '';
33723372
$rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized.
33733373

33743374
if ( ! empty( $url ) ) {
@@ -3421,7 +3421,7 @@ function wp_ajax_send_link_to_editor() {
34213421
$link_text = wp_basename( $src );
34223422
}
34233423

3424-
$post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
3424+
$post = get_post( $_POST['post_id'] ?? 0 );
34253425

34263426
// Ping WordPress for an embed.
34273427
$check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
@@ -3647,7 +3647,7 @@ function wp_ajax_query_themes() {
36473647
}
36483648
}
36493649

3650-
$old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
3650+
$old_filter = $args['browse'] ?? 'search';
36513651

36523652
/** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
36533653
$args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct( $args = array() ) {
2929
parent::__construct(
3030
array(
3131
'plural' => 'bookmarks',
32-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
32+
'screen' => $args['screen'] ?? null,
3333
)
3434
);
3535
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,11 +1451,11 @@ public function print_column_headers( $with_id = true ) {
14511451
}
14521452

14531453
if ( isset( $sortable[ $column_key ] ) ) {
1454-
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
1455-
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
1456-
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
1457-
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
1458-
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
1454+
$orderby = $sortable[ $column_key ][0] ?? '';
1455+
$desc_first = $sortable[ $column_key ][1] ?? false;
1456+
$abbr = $sortable[ $column_key ][2] ?? '';
1457+
$orderby_text = $sortable[ $column_key ][3] ?? '';
1458+
$initial_order = $sortable[ $column_key ][4] ?? '';
14591459

14601460
/*
14611461
* We're in the initial view and there's no $_GET['orderby'] then check if the
@@ -1567,11 +1567,11 @@ public function print_table_description() {
15671567
foreach ( array_keys( $columns ) as $column_key ) {
15681568

15691569
if ( isset( $sortable[ $column_key ] ) ) {
1570-
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
1571-
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
1572-
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
1573-
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
1574-
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
1570+
$orderby = $sortable[ $column_key ][0] ?? '';
1571+
$desc_first = $sortable[ $column_key ][1] ?? false;
1572+
$abbr = $sortable[ $column_key ][2] ?? '';
1573+
$orderby_text = $sortable[ $column_key ][3] ?? '';
1574+
$initial_order = $sortable[ $column_key ][4] ?? '';
15751575

15761576
if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
15771577
return;

src/wp-admin/includes/class-wp-plugin-install-list-table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ public function display_rows() {
556556
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
557557
}
558558

559-
$requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
560-
$requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
559+
$requires_php = $plugin['requires_php'] ?? null;
560+
$requires_wp = $plugin['requires'] ?? null;
561561

562562
$compatible_php = is_php_version_compatible( $requires_php );
563563
$compatible_wp = is_wp_version_compatible( $requires_wp );

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct( $args = array() ) {
4242
parent::__construct(
4343
array(
4444
'plural' => 'plugins',
45-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
45+
'screen' => $args['screen'] ?? null,
4646
)
4747
);
4848

@@ -726,7 +726,7 @@ public function single_row( $item ) {
726726

727727
list( $plugin_file, $plugin_data ) = $item;
728728

729-
$plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] );
729+
$plugin_slug = $plugin_data['slug'] ?? sanitize_title( $plugin_data['Name'] );
730730
$plugin_id_attr = $plugin_slug;
731731

732732
// Ensure the ID attribute is unique.
@@ -753,8 +753,8 @@ public function single_row( $item ) {
753753
$restrict_network_active = false;
754754
$restrict_network_only = false;
755755

756-
$requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null;
757-
$requires_wp = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null;
756+
$requires_php = $plugin_data['RequiresPHP'] ?? null;
757+
$requires_wp = $plugin_data['RequiresWP'] ?? null;
758758

759759
$compatible_php = is_php_version_compatible( $requires_php );
760760
$compatible_wp = is_wp_version_compatible( $requires_wp );

src/wp-admin/includes/class-wp-screen.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ public function render_screen_meta() {
808808
'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()'
809809
);
810810

811-
$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
811+
$old_help = self::$_old_compat_help[ $this->id ] ?? '';
812812

813813
/**
814814
* Filters the legacy contextual help text.
@@ -1257,7 +1257,7 @@ public function render_per_page_options() {
12571257
}
12581258

12591259
if ( 'edit_comments_per_page' === $option ) {
1260-
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
1260+
$comment_status = $_REQUEST['comment_status'] ?? 'all';
12611261

12621262
/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
12631263
$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct( $args = array() ) {
3232
parent::__construct(
3333
array(
3434
'ajax' => true,
35-
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
35+
'screen' => $args['screen'] ?? null,
3636
)
3737
);
3838
}

src/wp-admin/includes/credits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function wp_credits_section_title( $group_data = array() ) {
120120
* @param string $slug The current group to display.
121121
*/
122122
function wp_credits_section_list( $credits = array(), $slug = '' ) {
123-
$group_data = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
123+
$group_data = $credits['groups'][ $slug ] ?? array();
124124
$credits_data = $credits['data'];
125125
if ( ! count( $group_data ) ) {
126126
return;

src/wp-admin/includes/file.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,12 @@ function wp_handle_upload_error( &$file, $message ) {
908908
}
909909

910910
// All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
911-
$test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
912-
$test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
911+
$test_form = $overrides['test_form'] ?? true;
912+
$test_size = $overrides['test_size'] ?? true;
913913

914914
// If you override this, you must provide $ext and $type!!
915-
$test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
916-
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : null;
915+
$test_type = $overrides['test_type'] ?? true;
916+
$mimes = $overrides['mimes'] ?? null;
917917

918918
// A correct form post will pass this test.
919919
if ( $test_form && ( ! isset( $_POST['action'] ) || $_POST['action'] !== $action ) ) {
@@ -2496,12 +2496,12 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false,
24962496
return $credentials;
24972497
}
24982498

2499-
$hostname = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
2500-
$username = isset( $credentials['username'] ) ? $credentials['username'] : '';
2501-
$public_key = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
2502-
$private_key = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
2503-
$port = isset( $credentials['port'] ) ? $credentials['port'] : '';
2504-
$connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
2499+
$hostname = $credentials['hostname'] ?? '';
2500+
$username = $credentials['username'] ?? '';
2501+
$public_key = $credentials['public_key'] ?? '';
2502+
$private_key = $credentials['private_key'] ?? '';
2503+
$port = $credentials['port'] ?? '';
2504+
$connection_type = $credentials['connection_type'] ?? '';
25052505

25062506
if ( $error ) {
25072507
$error_string = __( '<strong>Error:</strong> Could not connect to the server. Please verify the settings are correct.' );

0 commit comments

Comments
 (0)