Skip to content

Commit 3d9fde3

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@61403 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 20de6d8 commit 3d9fde3

File tree

7 files changed

+50
-50
lines changed

7 files changed

+50
-50
lines changed

src/wp-includes/class-wp-comment-query.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,12 +949,12 @@ protected function get_comment_ids() {
949949
*/
950950
$clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
951951

952-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
953-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
954-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
955-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
956-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
957-
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
952+
$fields = $clauses['fields'] ?? '';
953+
$join = $clauses['join'] ?? '';
954+
$where = $clauses['where'] ?? '';
955+
$orderby = $clauses['orderby'] ?? '';
956+
$limits = $clauses['limits'] ?? '';
957+
$groupby = $clauses['groupby'] ?? '';
958958

959959
$this->filtered_where_clause = $where;
960960

src/wp-includes/class-wp-customize-manager.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,9 +1226,9 @@ public function import_theme_starter_content( $starter_content = array() ) {
12261226
$sidebars_widgets = isset( $starter_content['widgets'] ) && ! empty( $this->widgets ) ? $starter_content['widgets'] : array();
12271227
$attachments = isset( $starter_content['attachments'] ) && ! empty( $this->nav_menus ) ? $starter_content['attachments'] : array();
12281228
$posts = isset( $starter_content['posts'] ) && ! empty( $this->nav_menus ) ? $starter_content['posts'] : array();
1229-
$options = isset( $starter_content['options'] ) ? $starter_content['options'] : array();
1229+
$options = $starter_content['options'] ?? array();
12301230
$nav_menus = isset( $starter_content['nav_menus'] ) && ! empty( $this->nav_menus ) ? $starter_content['nav_menus'] : array();
1231-
$theme_mods = isset( $starter_content['theme_mods'] ) ? $starter_content['theme_mods'] : array();
1231+
$theme_mods = $starter_content['theme_mods'] ?? array();
12321232

12331233
// Widgets.
12341234
$max_widget_numbers = array();
@@ -1495,7 +1495,7 @@ public function import_theme_starter_content( $starter_content = array() ) {
14951495
$this->set_post_value(
14961496
$nav_menu_setting_id,
14971497
array(
1498-
'name' => isset( $nav_menu['name'] ) ? $nav_menu['name'] : $nav_menu_location,
1498+
'name' => $nav_menu['name'] ?? $nav_menu_location,
14991499
)
15001500
);
15011501
$this->pending_starter_content_settings_ids[] = $nav_menu_setting_id;
@@ -5239,10 +5239,10 @@ public function register_controls() {
52395239
'label' => __( 'Logo' ),
52405240
'section' => 'title_tagline',
52415241
'priority' => 8,
5242-
'height' => isset( $custom_logo_args[0]['height'] ) ? $custom_logo_args[0]['height'] : null,
5243-
'width' => isset( $custom_logo_args[0]['width'] ) ? $custom_logo_args[0]['width'] : null,
5244-
'flex_height' => isset( $custom_logo_args[0]['flex-height'] ) ? $custom_logo_args[0]['flex-height'] : null,
5245-
'flex_width' => isset( $custom_logo_args[0]['flex-width'] ) ? $custom_logo_args[0]['flex-width'] : null,
5242+
'height' => $custom_logo_args[0]['height'] ?? null,
5243+
'width' => $custom_logo_args[0]['width'] ?? null,
5244+
'flex_height' => $custom_logo_args[0]['flex-height'] ?? null,
5245+
'flex_width' => $custom_logo_args[0]['flex-width'] ?? null,
52465246
'button_labels' => array(
52475247
'select' => __( 'Select logo' ),
52485248
'change' => __( 'Change logo' ),

src/wp-includes/class-wp-http-requests-response.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ public function get_cookies() {
164164
array(
165165
'name' => $cookie->name,
166166
'value' => urldecode( $cookie->value ),
167-
'expires' => isset( $cookie->attributes['expires'] ) ? $cookie->attributes['expires'] : null,
168-
'path' => isset( $cookie->attributes['path'] ) ? $cookie->attributes['path'] : null,
169-
'domain' => isset( $cookie->attributes['domain'] ) ? $cookie->attributes['domain'] : null,
170-
'host_only' => isset( $cookie->flags['host-only'] ) ? $cookie->flags['host-only'] : null,
167+
'expires' => $cookie->attributes['expires'] ?? null,
168+
'path' => $cookie->attributes['path'] ?? null,
169+
'domain' => $cookie->attributes['domain'] ?? null,
170+
'host_only' => $cookie->flags['host-only'] ?? null,
171171
)
172172
);
173173
}

src/wp-includes/class-wp-network-query.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,12 @@ protected function get_network_ids() {
460460
*/
461461
$clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) );
462462

463-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
464-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
465-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
466-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
467-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
468-
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
463+
$fields = $clauses['fields'] ?? '';
464+
$join = $clauses['join'] ?? '';
465+
$where = $clauses['where'] ?? '';
466+
$orderby = $clauses['orderby'] ?? '';
467+
$limits = $clauses['limits'] ?? '';
468+
$groupby = $clauses['groupby'] ?? '';
469469

470470
if ( $where ) {
471471
$where = 'WHERE ' . $where;

src/wp-includes/class-wp-query.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,13 +3019,13 @@ public function get_posts() {
30193019
*/
30203020
$clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
30213021

3022-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
3023-
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
3024-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
3025-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
3026-
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
3027-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
3028-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
3022+
$where = $clauses['where'] ?? '';
3023+
$groupby = $clauses['groupby'] ?? '';
3024+
$join = $clauses['join'] ?? '';
3025+
$orderby = $clauses['orderby'] ?? '';
3026+
$distinct = $clauses['distinct'] ?? '';
3027+
$fields = $clauses['fields'] ?? '';
3028+
$limits = $clauses['limits'] ?? '';
30293029
}
30303030

30313031
/**
@@ -3153,13 +3153,13 @@ public function get_posts() {
31533153
*/
31543154
$clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
31553155

3156-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
3157-
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
3158-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
3159-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
3160-
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
3161-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
3162-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
3156+
$where = $clauses['where'] ?? '';
3157+
$groupby = $clauses['groupby'] ?? '';
3158+
$join = $clauses['join'] ?? '';
3159+
$orderby = $clauses['orderby'] ?? '';
3160+
$distinct = $clauses['distinct'] ?? '';
3161+
$fields = $clauses['fields'] ?? '';
3162+
$limits = $clauses['limits'] ?? '';
31633163
}
31643164

31653165
if ( ! empty( $groupby ) ) {

src/wp-includes/class-wp-site-query.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,12 @@ protected function get_site_ids() {
674674
*/
675675
$clauses = apply_filters_ref_array( 'sites_clauses', array( compact( $pieces ), &$this ) );
676676

677-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
678-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
679-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
680-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
681-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
682-
$groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
677+
$fields = $clauses['fields'] ?? '';
678+
$join = $clauses['join'] ?? '';
679+
$where = $clauses['where'] ?? '';
680+
$orderby = $clauses['orderby'] ?? '';
681+
$limits = $clauses['limits'] ?? '';
682+
$groupby = $clauses['groupby'] ?? '';
683683

684684
if ( $where ) {
685685
$where = 'WHERE ' . $where;

src/wp-includes/class-wp-term-query.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,13 @@ public function get_terms() {
727727
*/
728728
$clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
729729

730-
$fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
731-
$join = isset( $clauses['join'] ) ? $clauses['join'] : '';
732-
$where = isset( $clauses['where'] ) ? $clauses['where'] : '';
733-
$distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
734-
$orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
735-
$order = isset( $clauses['order'] ) ? $clauses['order'] : '';
736-
$limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
730+
$fields = $clauses['fields'] ?? '';
731+
$join = $clauses['join'] ?? '';
732+
$where = $clauses['where'] ?? '';
733+
$distinct = $clauses['distinct'] ?? '';
734+
$orderby = $clauses['orderby'] ?? '';
735+
$order = $clauses['order'] ?? '';
736+
$limits = $clauses['limits'] ?? '';
737737

738738
$fields_is_filtered = implode( ', ', $selects ) !== $fields;
739739

0 commit comments

Comments
 (0)