Code Modernization: Administration: Use null coalescing operator instead of isset() ternaries.

Developed as a subset of https://github.com/WordPress/wordpress-develop/pull/10654
Initially developed in https://github.com/WordPress/wordpress-develop/pull/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.

Built from https://develop.svn.wordpress.org/trunk@61456


git-svn-id: http://core.svn.wordpress.org/trunk@60768 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2026-01-09 04:22:50 +00:00
parent f6cb67e746
commit 87cd08d8a4
17 changed files with 105 additions and 105 deletions

View File

@@ -1808,7 +1808,7 @@ function wp_ajax_closed_postboxes() {
$hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
$hidden = array_filter( $hidden );
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
$page = $_POST['page'] ?? '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
@@ -1839,7 +1839,7 @@ function wp_ajax_closed_postboxes() {
*/
function wp_ajax_hidden_columns() {
check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
$page = $_POST['page'] ?? '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
@@ -1988,13 +1988,13 @@ function wp_ajax_menu_locations_save() {
function wp_ajax_meta_box_order() {
check_ajax_referer( 'meta-box-order' );
$order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
$page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
$page_columns = $_POST['page_columns'] ?? 'auto';
if ( 'auto' !== $page_columns ) {
$page_columns = (int) $page_columns;
}
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
$page = $_POST['page'] ?? '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
@@ -2052,8 +2052,8 @@ function wp_ajax_get_permalink() {
function wp_ajax_sample_permalink() {
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
$title = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
$slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
$title = $_POST['new_title'] ?? '';
$slug = $_POST['new_slug'] ?? null;
wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
}
@@ -2393,7 +2393,7 @@ function wp_ajax_save_widget() {
$error = '<p>' . __( 'An error has occurred. Please reload the page and try again.' ) . '</p>';
$sidebars = wp_get_sidebars_widgets();
$sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array();
$sidebar = $sidebars[ $sidebar_id ] ?? array();
// Delete.
if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
@@ -3353,12 +3353,12 @@ function wp_ajax_send_attachment_to_editor() {
remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
$align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
$size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
$alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
$align = $attachment['align'] ?? 'none';
$size = $attachment['image-size'] ?? 'medium';
$alt = $attachment['image_alt'] ?? '';
// No whitespace-only captions.
$caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
$caption = $attachment['post_excerpt'] ?? '';
if ( '' === trim( $caption ) ) {
$caption = '';
}
@@ -3368,7 +3368,7 @@ function wp_ajax_send_attachment_to_editor() {
} elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) {
$html = stripslashes_deep( $_POST['html'] );
} else {
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
$html = $attachment['post_title'] ?? '';
$rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized.
if ( ! empty( $url ) ) {
@@ -3421,7 +3421,7 @@ function wp_ajax_send_link_to_editor() {
$link_text = wp_basename( $src );
}
$post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
$post = get_post( $_POST['post_id'] ?? 0 );
// Ping WordPress for an embed.
$check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
@@ -3647,7 +3647,7 @@ function wp_ajax_query_themes() {
}
}
$old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
$old_filter = $args['browse'] ?? 'search';
/** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
$args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );

View File

@@ -122,7 +122,7 @@ class WP_Community_Events {
} elseif ( ! isset( $response_body['location'], $response_body['events'] ) ) {
$response_error = new WP_Error(
'api-invalid-response',
isset( $response_body['error'] ) ? $response_body['error'] : __( 'Unknown API error.' )
$response_body['error'] ?? __( 'Unknown API error.' )
);
}

View File

@@ -29,7 +29,7 @@ class WP_Links_List_Table extends WP_List_Table {
parent::__construct(
array(
'plural' => 'bookmarks',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
'screen' => $args['screen'] ?? null,
)
);
}

View File

@@ -1451,11 +1451,11 @@ class WP_List_Table {
}
if ( isset( $sortable[ $column_key ] ) ) {
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
$orderby = $sortable[ $column_key ][0] ?? '';
$desc_first = $sortable[ $column_key ][1] ?? false;
$abbr = $sortable[ $column_key ][2] ?? '';
$orderby_text = $sortable[ $column_key ][3] ?? '';
$initial_order = $sortable[ $column_key ][4] ?? '';
/*
* We're in the initial view and there's no $_GET['orderby'] then check if the
@@ -1567,11 +1567,11 @@ class WP_List_Table {
foreach ( array_keys( $columns ) as $column_key ) {
if ( isset( $sortable[ $column_key ] ) ) {
$orderby = isset( $sortable[ $column_key ][0] ) ? $sortable[ $column_key ][0] : '';
$desc_first = isset( $sortable[ $column_key ][1] ) ? $sortable[ $column_key ][1] : false;
$abbr = isset( $sortable[ $column_key ][2] ) ? $sortable[ $column_key ][2] : '';
$orderby_text = isset( $sortable[ $column_key ][3] ) ? $sortable[ $column_key ][3] : '';
$initial_order = isset( $sortable[ $column_key ][4] ) ? $sortable[ $column_key ][4] : '';
$orderby = $sortable[ $column_key ][0] ?? '';
$desc_first = $sortable[ $column_key ][1] ?? false;
$abbr = $sortable[ $column_key ][2] ?? '';
$orderby_text = $sortable[ $column_key ][3] ?? '';
$initial_order = $sortable[ $column_key ][4] ?? '';
if ( ! is_string( $orderby_text ) || '' === $orderby_text ) {
return;

View File

@@ -556,8 +556,8 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
$author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '</cite>';
}
$requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
$requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
$requires_php = $plugin['requires_php'] ?? null;
$requires_wp = $plugin['requires'] ?? null;
$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );

View File

@@ -42,7 +42,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
parent::__construct(
array(
'plural' => 'plugins',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
'screen' => $args['screen'] ?? null,
)
);
@@ -726,7 +726,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
list( $plugin_file, $plugin_data ) = $item;
$plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] );
$plugin_slug = $plugin_data['slug'] ?? sanitize_title( $plugin_data['Name'] );
$plugin_id_attr = $plugin_slug;
// Ensure the ID attribute is unique.
@@ -753,8 +753,8 @@ class WP_Plugins_List_Table extends WP_List_Table {
$restrict_network_active = false;
$restrict_network_only = false;
$requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null;
$requires_wp = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null;
$requires_php = $plugin_data['RequiresPHP'] ?? null;
$requires_wp = $plugin_data['RequiresWP'] ?? null;
$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );

View File

@@ -808,7 +808,7 @@ final class WP_Screen {
'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()'
);
$old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
$old_help = self::$_old_compat_help[ $this->id ] ?? '';
/**
* Filters the legacy contextual help text.
@@ -1257,7 +1257,7 @@ final class WP_Screen {
}
if ( 'edit_comments_per_page' === $option ) {
$comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
$comment_status = $_REQUEST['comment_status'] ?? 'all';
/** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
$per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );

View File

@@ -32,7 +32,7 @@ class WP_Themes_List_Table extends WP_List_Table {
parent::__construct(
array(
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
'screen' => $args['screen'] ?? null,
)
);
}

View File

@@ -120,7 +120,7 @@ function wp_credits_section_title( $group_data = array() ) {
* @param string $slug The current group to display.
*/
function wp_credits_section_list( $credits = array(), $slug = '' ) {
$group_data = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
$group_data = $credits['groups'][ $slug ] ?? array();
$credits_data = $credits['data'];
if ( ! count( $group_data ) ) {
return;

View File

@@ -908,12 +908,12 @@ function _wp_handle_upload( &$file, $overrides, $time, $action ) {
}
// All tests are on by default. Most can be turned off by $overrides[{test_name}] = false;
$test_form = isset( $overrides['test_form'] ) ? $overrides['test_form'] : true;
$test_size = isset( $overrides['test_size'] ) ? $overrides['test_size'] : true;
$test_form = $overrides['test_form'] ?? true;
$test_size = $overrides['test_size'] ?? true;
// If you override this, you must provide $ext and $type!!
$test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : null;
$test_type = $overrides['test_type'] ?? true;
$mimes = $overrides['mimes'] ?? null;
// A correct form post will pass this test.
if ( $test_form && ( ! isset( $_POST['action'] ) || $_POST['action'] !== $action ) ) {
@@ -2496,12 +2496,12 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false,
return $credentials;
}
$hostname = isset( $credentials['hostname'] ) ? $credentials['hostname'] : '';
$username = isset( $credentials['username'] ) ? $credentials['username'] : '';
$public_key = isset( $credentials['public_key'] ) ? $credentials['public_key'] : '';
$private_key = isset( $credentials['private_key'] ) ? $credentials['private_key'] : '';
$port = isset( $credentials['port'] ) ? $credentials['port'] : '';
$connection_type = isset( $credentials['connection_type'] ) ? $credentials['connection_type'] : '';
$hostname = $credentials['hostname'] ?? '';
$username = $credentials['username'] ?? '';
$public_key = $credentials['public_key'] ?? '';
$private_key = $credentials['private_key'] ?? '';
$port = $credentials['port'] ?? '';
$connection_type = $credentials['connection_type'] ?? '';
if ( $error ) {
$error_string = __( '<strong>Error:</strong> Could not connect to the server. Please verify the settings are correct.' );

View File

@@ -1265,7 +1265,7 @@ function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) {
_deprecated_argument( __FUNCTION__, '2.5.0' ); // Never implemented.
}
$link_rel = isset( $link->link_rel ) ? $link->link_rel : '';
$link_rel = $link->link_rel ?? '';
$link_rels = preg_split( '/\s+/', $link_rel );
// Mark the specified value as checked if it matches the current link's relationship.
@@ -1454,7 +1454,7 @@ function link_advanced_meta_box( $link ) {
</tr>
<tr>
<th scope="row"><label for="link_notes"><?php _e( 'Notes' ); ?></label></th>
<td><textarea name="link_notes" id="link_notes" rows="10"><?php echo ( isset( $link->link_notes ) ? $link->link_notes : '' ); // textarea_escaped ?></textarea></td>
<td><textarea name="link_notes" id="link_notes" rows="10"><?php echo $link->link_notes ?? ''; // textarea_escaped ?></textarea></td>
</tr>
<tr>
<th scope="row"><label for="link_rating"><?php _e( 'Rating' ); ?></label></th>

View File

@@ -796,8 +796,8 @@ function install_plugin_information() {
</div>
<div id="section-holder">
<?php
$requires_php = isset( $api->requires_php ) ? $api->requires_php : null;
$requires_wp = isset( $api->requires ) ? $api->requires : null;
$requires_php = $api->requires_php ?? null;
$requires_wp = $api->requires ?? null;
$compatible_php = is_php_version_compatible( $requires_php );
$compatible_wp = is_wp_version_compatible( $requires_wp );

View File

@@ -732,8 +732,8 @@ function wp_prepare_themes_for_js( $themes = null ) {
$customize_action = esc_url( $customize_action );
}
$update_requires_wp = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
$update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
$update_requires_wp = $updates[ $slug ]['requires'] ?? null;
$update_requires_php = $updates[ $slug ]['requires_php'] ?? null;
$auto_update = in_array( $slug, $auto_updates, true );
$auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';

View File

@@ -30,7 +30,7 @@ add_filter(
}
);
$action = isset( $_POST['action'] ) ? $_POST['action'] : '';
$action = $_POST['action'] ?? '';
get_current_screen()->add_help_tab(
array(

View File

@@ -7,11 +7,6 @@
*/
return array(
array(
'handle' => 'wp-preferences',
'path' => 'preferences/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-nux',
'path' => 'nux/style',
@@ -22,6 +17,11 @@ return array(
'path' => 'list-reusable-blocks/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-preferences',
'path' => 'preferences/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-commands',
'path' => 'commands/style',
@@ -32,6 +32,11 @@ return array(
'path' => 'reusable-blocks/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-widgets',
'path' => 'widgets/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-components',
'path' => 'components/style',
@@ -42,36 +47,31 @@ return array(
'path' => 'patterns/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-widgets',
'path' => 'widgets/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-format-library',
'path' => 'format-library/style',
'dependencies' => array('wp-block-editor', 'wp-components'),
),
array(
'handle' => 'wp-media-utils',
'path' => 'media-utils/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-block-directory',
'path' => 'block-directory/style',
'dependencies' => array('wp-block-editor', 'wp-components', 'wp-editor'),
),
array(
'handle' => 'wp-customize-widgets',
'path' => 'customize-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-preferences', 'wp-widgets'),
'handle' => 'wp-media-utils',
'path' => 'media-utils/style',
'dependencies' => array('wp-components'),
),
array(
'handle' => 'wp-edit-widgets',
'path' => 'edit-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-customize-widgets',
'path' => 'customize-widgets/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-components', 'wp-media-utils', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-edit-post',
'path' => 'edit-post/style',
@@ -87,14 +87,14 @@ return array(
'path' => 'editor/style',
'dependencies' => array('wp-block-editor', 'wp-commands', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences'),
),
array(
'handle' => 'wp-block-editor',
'path' => 'block-editor/style',
'dependencies' => array('wp-commands', 'wp-components', 'wp-preferences'),
),
array(
'handle' => 'wp-edit-site',
'path' => 'edit-site/style',
'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-patterns', 'wp-preferences', 'wp-widgets'),
),
array(
'handle' => 'wp-block-editor',
'path' => 'block-editor/style',
'dependencies' => array('wp-commands', 'wp-components', 'wp-preferences'),
),
);

View File

@@ -7,36 +7,11 @@
*/
return array(
array(
'id' => '@wordpress/a11y',
'path' => 'a11y/index',
'asset' => 'a11y/index.min.asset.php',
),
array(
'id' => '@wordpress/interactivity',
'path' => 'interactivity/index',
'asset' => 'interactivity/index.min.asset.php',
),
array(
'id' => '@wordpress/abilities',
'path' => 'abilities/index',
'asset' => 'abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/latex-to-mathml',
'path' => 'latex-to-mathml/index',
'asset' => 'latex-to-mathml/index.min.asset.php',
),
array(
'id' => '@wordpress/latex-to-mathml/loader',
'path' => 'latex-to-mathml/loader',
'asset' => 'latex-to-mathml/loader.min.asset.php',
),
array(
'id' => '@wordpress/core-abilities',
'path' => 'core-abilities/index',
'asset' => 'core-abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/interactivity-router',
'path' => 'interactivity-router/index',
@@ -48,15 +23,40 @@ return array(
'asset' => 'interactivity-router/full-page.min.asset.php',
),
array(
'id' => '@wordpress/route',
'path' => 'route/index',
'asset' => 'route/index.min.asset.php',
'id' => '@wordpress/core-abilities',
'path' => 'core-abilities/index',
'asset' => 'core-abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/a11y',
'path' => 'a11y/index',
'asset' => 'a11y/index.min.asset.php',
),
array(
'id' => '@wordpress/latex-to-mathml',
'path' => 'latex-to-mathml/index',
'asset' => 'latex-to-mathml/index.min.asset.php',
),
array(
'id' => '@wordpress/latex-to-mathml/loader',
'path' => 'latex-to-mathml/loader',
'asset' => 'latex-to-mathml/loader.min.asset.php',
),
array(
'id' => '@wordpress/abilities',
'path' => 'abilities/index',
'asset' => 'abilities/index.min.asset.php',
),
array(
'id' => '@wordpress/edit-site-init',
'path' => 'edit-site-init/index',
'asset' => 'edit-site-init/index.min.asset.php',
),
array(
'id' => '@wordpress/route',
'path' => 'route/index',
'asset' => 'route/index.min.asset.php',
),
array(
'id' => '@wordpress/lazy-editor',
'path' => 'lazy-editor/index',

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61455';
$wp_version = '7.0-alpha-61456';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.