Code Modernization: Replace some isset() ternary checks with null coalescing.

Since PHP 7.0 introduced the [https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op null coalescing operator], and WordPress now requires at least PHP 7.2.24, `isset( $var ) ? $var : null` ternary checks can be safely replaced with the more concise `$var ?? null` syntax.

As some new code using the null coalescing operator has already been introduced into core in recent releases, this commit continues with the code modernization by implementing incremental changes for easier review.

Props seanwei, getsyash, krupalpanchal, wildworks, jorbin, SergeyBiryukov.
Fixes #63430. See #58874.
Built from https://develop.svn.wordpress.org/trunk@61403


git-svn-id: http://core.svn.wordpress.org/trunk@60715 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2025-12-22 23:14:38 +00:00
parent a12a6154c3
commit e1e3fc707b
8 changed files with 51 additions and 51 deletions

View File

@@ -949,12 +949,12 @@ class WP_Comment_Query {
*/
$clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$fields = $clauses['fields'] ?? '';
$join = $clauses['join'] ?? '';
$where = $clauses['where'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$limits = $clauses['limits'] ?? '';
$groupby = $clauses['groupby'] ?? '';
$this->filtered_where_clause = $where;

View File

@@ -1226,9 +1226,9 @@ final class WP_Customize_Manager {
$sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array();
$attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();
$posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();
$options = isset( $starter_content['options'] ) ? $starter_content['options'] : array();
$options = $starter_content['options'] ?? array();
$nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();
$theme_mods = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array();
$theme_mods = $starter_content['theme_mods'] ?? array();
// Widgets.
$max_widget_numbers = array();
@@ -1495,7 +1495,7 @@ final class WP_Customize_Manager {
$this->set_post_value(
$nav_menu_setting_id,
array(
'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location,
'name' => $nav_menu['name'] ?? $nav_menu_location,
)
);
$this->pending_starter_content_settings_ids[] = $nav_menu_setting_id;
@@ -5239,10 +5239,10 @@ final class WP_Customize_Manager {
'label' => __( 'Logo' ),
'section' => 'title_tagline',
'priority' => 8,
'height' => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null,
'width' => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null,
'flex_height' => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null,
'flex_width' => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null,
'height' => $custom_logo_args[0]['height'] ?? null,
'width' => $custom_logo_args[0]['width'] ?? null,
'flex_height' => $custom_logo_args[0]['flex-height'] ?? null,
'flex_width' => $custom_logo_args[0]['flex-width'] ?? null,
'button_labels' => array(
'select' => __( 'Select logo' ),
'change' => __( 'Change logo' ),

View File

@@ -164,10 +164,10 @@ class WP_HTTP_Requests_Response extends WP_HTTP_Response {
array(
'name' => $cookie->name,
'value' => urldecode( $cookie->value ),
'expires' => isset( $cookie->attributes['expires'] ) ? $cookie->attributes['expires'] : null,
'path' => isset( $cookie->attributes['path'] ) ? $cookie->attributes['path'] : null,
'domain' => isset( $cookie->attributes['domain'] ) ? $cookie->attributes['domain'] : null,
'host_only' => isset( $cookie->flags['host-only'] ) ? $cookie->flags['host-only'] : null,
'expires' => $cookie->attributes['expires'] ?? null,
'path' => $cookie->attributes['path'] ?? null,
'domain' => $cookie->attributes['domain'] ?? null,
'host_only' => $cookie->flags['host-only'] ?? null,
)
);
}

View File

@@ -460,12 +460,12 @@ class WP_Network_Query {
*/
$clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) );
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$fields = $clauses['fields'] ?? '';
$join = $clauses['join'] ?? '';
$where = $clauses['where'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$limits = $clauses['limits'] ?? '';
$groupby = $clauses['groupby'] ?? '';
if ( $where ) {
$where = 'WHERE ' . $where;

View File

@@ -3019,13 +3019,13 @@ class WP_Query {
*/
$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$where = $clauses['where'] ?? '';
$groupby = $clauses['groupby'] ?? '';
$join = $clauses['join'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$distinct = $clauses['distinct'] ?? '';
$fields = $clauses['fields'] ?? '';
$limits = $clauses['limits'] ?? '';
}
/**
@@ -3153,13 +3153,13 @@ class WP_Query {
*/
$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$where = $clauses['where'] ?? '';
$groupby = $clauses['groupby'] ?? '';
$join = $clauses['join'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$distinct = $clauses['distinct'] ?? '';
$fields = $clauses['fields'] ?? '';
$limits = $clauses['limits'] ?? '';
}
if ( ! empty( $groupby ) ) {

View File

@@ -674,12 +674,12 @@ class WP_Site_Query {
*/
$clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) );
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
$fields = $clauses['fields'] ?? '';
$join = $clauses['join'] ?? '';
$where = $clauses['where'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$limits = $clauses['limits'] ?? '';
$groupby = $clauses['groupby'] ?? '';
if ( $where ) {
$where = 'WHERE ' . $where;

View File

@@ -727,13 +727,13 @@ class WP_Term_Query {
*/
$clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
$order = isset( $clauses['order'] ) ? $clauses['order'] : '';
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
$fields = $clauses['fields'] ?? '';
$join = $clauses['join'] ?? '';
$where = $clauses['where'] ?? '';
$distinct = $clauses['distinct'] ?? '';
$orderby = $clauses['orderby'] ?? '';
$order = $clauses['order'] ?? '';
$limits = $clauses['limits'] ?? '';
$fields_is_filtered = implode( ', ', $selects ) !== $fields;

View File

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