Skip to content

Commit a8f43c5

Browse files
committed
Code Modernization: Use null coalescing operator instead of isset() with if/else statements.
Developed in WordPress#10711 Follow-up to [61457], [61456], [61455], [61454], [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. See #58874, #63430. git-svn-id: https://develop.svn.wordpress.org/trunk@61463 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9c67aa4 commit a8f43c5

15 files changed

Lines changed: 20 additions & 82 deletions

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,7 @@ function get_cli_args( $param, $required = false ) {
311311
$parts = explode( '=', $match[1] );
312312
$key = preg_replace( '/[^a-z0-9]+/', '', $parts[0] );
313313

314-
if ( isset( $parts[1] ) ) {
315-
$out[ $key ] = $parts[1];
316-
} else {
317-
$out[ $key ] = true;
318-
}
314+
$out[ $key ] = $parts[1] ?? true;
319315

320316
$last_arg = $key;
321317
} elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) {

src/wp-admin/includes/post.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
122122
$post_data['post_status'] = 'pending';
123123
}
124124

125-
if ( isset( $post_data['ID'] ) ) {
126-
$post_id = $post_data['ID'];
127-
} else {
128-
$post_id = false;
129-
}
125+
$post_id = $post_data['ID'] ?? false;
130126
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
131127

132128
if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {

src/wp-admin/includes/template.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,12 +2296,7 @@ function _post_states( $post, $display = true ) {
22962296
*/
22972297
function get_post_states( $post ) {
22982298
$post_states = array();
2299-
2300-
if ( isset( $_REQUEST['post_status'] ) ) {
2301-
$post_status = $_REQUEST['post_status'];
2302-
} else {
2303-
$post_status = '';
2304-
}
2299+
$post_status = $_REQUEST['post_status'] ?? '';
23052300

23062301
if ( ! empty( $post->post_password ) ) {
23072302
$post_states['protected'] = _x( 'Password protected', 'post status' );

src/wp-admin/includes/theme.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,7 @@ function get_theme_feature_list( $api = true ) {
400400
$wporg_features[ $feature_category ] = array();
401401

402402
foreach ( $feature_items as $feature ) {
403-
if ( isset( $features[ $feature_category ][ $feature ] ) ) {
404-
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ];
405-
} else {
406-
$wporg_features[ $feature_category ][ $feature ] = $feature;
407-
}
403+
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ] ?? $feature;
408404
}
409405
}
410406

src/wp-admin/upgrade.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323

2424
delete_site_transient( 'update_core' );
2525

26-
if ( isset( $_GET['step'] ) ) {
27-
$step = $_GET['step'];
28-
} else {
29-
$step = 0;
30-
}
26+
$step = $_GET['step'] ?? 0;
3127

3228
// Do it. No output.
3329
if ( 'upgrade_db' === $step ) {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ public function sanitize_query( $queries, $parent_query = null ) {
208208
continue;
209209
}
210210

211-
if ( isset( $parent_query[ $dkey ] ) ) {
212-
$queries[ $dkey ] = $parent_query[ $dkey ];
213-
} else {
214-
$queries[ $dkey ] = $dvalue;
215-
}
211+
$queries[ $dkey ] = $parent_query[ $dkey ] ?? $dvalue;
216212
}
217213

218214
// Validate the dates passed in the query.

src/wp-includes/class-wp-http-streams.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ public function request( $url, $args = array() ) {
7777
}
7878

7979
if ( isset( $parsed_args['headers']['Host'] ) || isset( $parsed_args['headers']['host'] ) ) {
80-
if ( isset( $parsed_args['headers']['Host'] ) ) {
81-
$parsed_url['host'] = $parsed_args['headers']['Host'];
82-
} else {
83-
$parsed_url['host'] = $parsed_args['headers']['host'];
84-
}
80+
$parsed_url['host'] = $parsed_args['headers']['Host'] ?? $parsed_args['headers']['host'];
8581
unset( $parsed_args['headers']['Host'], $parsed_args['headers']['host'] );
8682
}
8783

src/wp-includes/class-wp-post-type.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,7 @@ public function set_props( $args ) {
655655
$args['rewrite']['feeds'] = (bool) $args['has_archive'];
656656
}
657657
if ( ! isset( $args['rewrite']['ep_mask'] ) ) {
658-
if ( isset( $args['permalink_epmask'] ) ) {
659-
$args['rewrite']['ep_mask'] = $args['permalink_epmask'];
660-
} else {
661-
$args['rewrite']['ep_mask'] = EP_PERMALINK;
662-
}
658+
$args['rewrite']['ep_mask'] = $args['permalink_epmask'] ?? EP_PERMALINK;
663659
}
664660
}
665661

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,7 @@ public function do_item( $handle, $group = false ) {
178178
}
179179
}
180180

181-
if ( isset( $obj->args ) ) {
182-
$media = $obj->args;
183-
} else {
184-
$media = 'all';
185-
}
181+
$media = $obj->args ?? 'all';
186182

187183
// A single item may alias a set of items, by having dependencies, but no source.
188184
if ( ! $src ) {

src/wp-includes/class-wp-xmlrpc-server.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,11 +3673,7 @@ public function wp_getComments( $args ) {
36733673
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
36743674
do_action( 'xmlrpc_call', 'wp.getComments', $args, $this );
36753675

3676-
if ( isset( $struct['status'] ) ) {
3677-
$status = $struct['status'];
3678-
} else {
3679-
$status = '';
3680-
}
3676+
$status = $struct['status'] ?? '';
36813677

36823678
if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) {
36833679
return new IXR_Error( 401, __( 'Invalid comment status.' ) );

0 commit comments

Comments
 (0)