From f01baabaf2ac5f1e44968c4e926133d870c8830e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jan 2026 20:18:57 -0800 Subject: [PATCH 1/2] Use null coalescing operator instead of if/else statements Search: \bif\s*\(\s*isset\(\s*(\$.+?)\s*\)\s*\)\s*\{\s*(\$.+?)\s*=\s*\1;\s*\}\s*else\s*\{\s*\2\s*=\s*(\S*?);\s*} Replace: $2 = $1 ?? $3; --- src/wp-admin/includes/class-wp-importer.php | 6 +----- src/wp-admin/includes/post.php | 6 +----- src/wp-admin/includes/template.php | 6 +----- src/wp-admin/includes/theme.php | 6 +----- src/wp-admin/upgrade.php | 6 +----- src/wp-includes/class-wp-date-query.php | 6 +----- src/wp-includes/class-wp-http-streams.php | 6 +----- src/wp-includes/class-wp-post-type.php | 6 +----- src/wp-includes/class-wp-styles.php | 6 +----- src/wp-includes/class-wp-xmlrpc-server.php | 6 +----- src/wp-includes/general-template.php | 6 +----- src/wp-includes/media.php | 6 +----- src/wp-includes/meta.php | 6 +----- src/wp-includes/rest-api/class-wp-rest-server.php | 6 +----- src/wp-includes/theme.php | 6 +----- 15 files changed, 15 insertions(+), 75 deletions(-) diff --git a/src/wp-admin/includes/class-wp-importer.php b/src/wp-admin/includes/class-wp-importer.php index 8489919f8a5e2..16b08bf42b15a 100644 --- a/src/wp-admin/includes/class-wp-importer.php +++ b/src/wp-admin/includes/class-wp-importer.php @@ -311,11 +311,7 @@ function get_cli_args( $param, $required = false ) { $parts = explode( '=', $match[1] ); $key = preg_replace( '/[^a-z0-9]+/', '', $parts[0] ); - if ( isset( $parts[1] ) ) { - $out[ $key ] = $parts[1]; - } else { - $out[ $key ] = true; - } + $out[ $key ] = $parts[1] ?? true; $last_arg = $key; } elseif ( (bool) preg_match( '/^-([a-zA-Z0-9]+)/', $args[ $i ], $match ) ) { diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index e241989f5b48d..267a13492e5ec 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -122,11 +122,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { $post_data['post_status'] = 'pending'; } - if ( isset( $post_data['ID'] ) ) { - $post_id = $post_data['ID']; - } else { - $post_id = false; - } + $post_id = $post_data['ID'] ?? false; $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) { diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 2eaf67454394e..17f3c3e6ca156 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -2297,11 +2297,7 @@ function _post_states( $post, $display = true ) { function get_post_states( $post ) { $post_states = array(); - if ( isset( $_REQUEST['post_status'] ) ) { - $post_status = $_REQUEST['post_status']; - } else { - $post_status = ''; - } + $post_status = $_REQUEST['post_status'] ?? ''; if ( ! empty( $post->post_password ) ) { $post_states['protected'] = _x( 'Password protected', 'post status' ); diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 5220f98de9431..8fa5d06a16a3b 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -400,11 +400,7 @@ function get_theme_feature_list( $api = true ) { $wporg_features[ $feature_category ] = array(); foreach ( $feature_items as $feature ) { - if ( isset( $features[ $feature_category ][ $feature ] ) ) { - $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ]; - } else { - $wporg_features[ $feature_category ][ $feature ] = $feature; - } + $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ] ?? $feature; } } diff --git a/src/wp-admin/upgrade.php b/src/wp-admin/upgrade.php index 4847134a62a97..7db8d492cbcec 100644 --- a/src/wp-admin/upgrade.php +++ b/src/wp-admin/upgrade.php @@ -23,11 +23,7 @@ delete_site_transient( 'update_core' ); -if ( isset( $_GET['step'] ) ) { - $step = $_GET['step']; -} else { - $step = 0; -} +$step = $_GET['step'] ?? 0; // Do it. No output. if ( 'upgrade_db' === $step ) { diff --git a/src/wp-includes/class-wp-date-query.php b/src/wp-includes/class-wp-date-query.php index 2dc1d244f5a5b..62de2f211332f 100644 --- a/src/wp-includes/class-wp-date-query.php +++ b/src/wp-includes/class-wp-date-query.php @@ -208,11 +208,7 @@ public function sanitize_query( $queries, $parent_query = null ) { continue; } - if ( isset( $parent_query[ $dkey ] ) ) { - $queries[ $dkey ] = $parent_query[ $dkey ]; - } else { - $queries[ $dkey ] = $dvalue; - } + $queries[ $dkey ] = $parent_query[ $dkey ] ?? $dvalue; } // Validate the dates passed in the query. diff --git a/src/wp-includes/class-wp-http-streams.php b/src/wp-includes/class-wp-http-streams.php index 4ab23b813ba04..45a15a9565f77 100644 --- a/src/wp-includes/class-wp-http-streams.php +++ b/src/wp-includes/class-wp-http-streams.php @@ -77,11 +77,7 @@ public function request( $url, $args = array() ) { } if ( isset( $parsed_args['headers']['Host'] ) || isset( $parsed_args['headers']['host'] ) ) { - if ( isset( $parsed_args['headers']['Host'] ) ) { - $parsed_url['host'] = $parsed_args['headers']['Host']; - } else { - $parsed_url['host'] = $parsed_args['headers']['host']; - } + $parsed_url['host'] = $parsed_args['headers']['Host'] ?? $parsed_args['headers']['host']; unset( $parsed_args['headers']['Host'], $parsed_args['headers']['host'] ); } diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php index 8812c21f1b415..2f23edc733910 100644 --- a/src/wp-includes/class-wp-post-type.php +++ b/src/wp-includes/class-wp-post-type.php @@ -655,11 +655,7 @@ public function set_props( $args ) { $args['rewrite']['feeds'] = (bool) $args['has_archive']; } if ( ! isset( $args['rewrite']['ep_mask'] ) ) { - if ( isset( $args['permalink_epmask'] ) ) { - $args['rewrite']['ep_mask'] = $args['permalink_epmask']; - } else { - $args['rewrite']['ep_mask'] = EP_PERMALINK; - } + $args['rewrite']['ep_mask'] = $args['permalink_epmask'] ?? EP_PERMALINK; } } diff --git a/src/wp-includes/class-wp-styles.php b/src/wp-includes/class-wp-styles.php index b41ba1023907c..ad5564124c460 100644 --- a/src/wp-includes/class-wp-styles.php +++ b/src/wp-includes/class-wp-styles.php @@ -178,11 +178,7 @@ public function do_item( $handle, $group = false ) { } } - if ( isset( $obj->args ) ) { - $media = $obj->args; - } else { - $media = 'all'; - } + $media = $obj->args ?? 'all'; // A single item may alias a set of items, by having dependencies, but no source. if ( ! $src ) { diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 3b1870edf14cf..ce278a861c285 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -3673,11 +3673,7 @@ public function wp_getComments( $args ) { /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.getComments', $args, $this ); - if ( isset( $struct['status'] ) ) { - $status = $struct['status']; - } else { - $status = ''; - } + $status = $struct['status'] ?? ''; if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { return new IXR_Error( 401, __( 'Invalid comment status.' ) ); diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index ac5427e2ce7f6..66d78c7a5ba75 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1873,11 +1873,7 @@ function get_the_post_type_description() { $post_type_obj = get_post_type_object( $post_type ); // Check if a description is set. - if ( isset( $post_type_obj->description ) ) { - $description = $post_type_obj->description; - } else { - $description = ''; - } + $description = $post_type_obj->description ?? ''; /** * Filters the description for a post type archive. diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index f35da615b5344..6933ad69957e2 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -6036,11 +6036,7 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { * conflicting `decoding` attribute already present. */ if ( 'img' === $tag_name ) { - if ( isset( $attr['decoding'] ) ) { - $loading_attrs['decoding'] = $attr['decoding']; - } else { - $loading_attrs['decoding'] = 'async'; - } + $loading_attrs['decoding'] = $attr['decoding'] ?? 'async'; } // For any resources, width and height must be provided, to avoid layout shifts. diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index d60bf5e87527b..5f53c12bc3dbf 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -674,11 +674,7 @@ function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = fal if ( ! $meta_cache ) { $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); - if ( isset( $meta_cache[ $object_id ] ) ) { - $meta_cache = $meta_cache[ $object_id ]; - } else { - $meta_cache = null; - } + $meta_cache = $meta_cache[ $object_id ] ?? null; } if ( ! $meta_key ) { diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index 0a18be77cd24a..dbf605523d2dc 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -364,11 +364,7 @@ public function serve_request( $path = null ) { } if ( empty( $path ) ) { - if ( isset( $_SERVER['PATH_INFO'] ) ) { - $path = $_SERVER['PATH_INFO']; - } else { - $path = '/'; - } + $path = $_SERVER['PATH_INFO'] ?? '/'; } $request = new WP_REST_Request( $_SERVER['REQUEST_METHOD'], $path ); diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 49779728414c7..4f7205db21d88 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1535,11 +1535,7 @@ function get_uploaded_header_images() { $header_images[ $header_index ]['thumbnail_url'] = $url; $header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); - if ( isset( $header_data['attachment_parent'] ) ) { - $header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent']; - } else { - $header_images[ $header_index ]['attachment_parent'] = ''; - } + $header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent'] ?? ''; if ( isset( $header_data['width'] ) ) { $header_images[ $header_index ]['width'] = $header_data['width']; From dd160eff13709414ecca773e7347403f275275e5 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jan 2026 20:31:16 -0800 Subject: [PATCH 2/2] Improve assignment indentation --- src/wp-admin/includes/post.php | 2 +- src/wp-admin/includes/template.php | 1 - src/wp-includes/theme.php | 11 +++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 267a13492e5ec..eb0029a556169 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -122,7 +122,7 @@ function _wp_translate_postdata( $update = false, $post_data = null ) { $post_data['post_status'] = 'pending'; } - $post_id = $post_data['ID'] ?? false; + $post_id = $post_data['ID'] ?? false; $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) { diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 17f3c3e6ca156..951309523286c 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -2296,7 +2296,6 @@ function _post_states( $post, $display = true ) { */ function get_post_states( $post ) { $post_states = array(); - $post_status = $_REQUEST['post_status'] ?? ''; if ( ! empty( $post->post_password ) ) { diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 4f7205db21d88..da44810d4b8dc 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1529,12 +1529,11 @@ function get_uploaded_header_images() { $header_data = wp_get_attachment_metadata( $header->ID ); $header_index = $header->ID; - $header_images[ $header_index ] = array(); - $header_images[ $header_index ]['attachment_id'] = $header->ID; - $header_images[ $header_index ]['url'] = $url; - $header_images[ $header_index ]['thumbnail_url'] = $url; - $header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); - + $header_images[ $header_index ] = array(); + $header_images[ $header_index ]['attachment_id'] = $header->ID; + $header_images[ $header_index ]['url'] = $url; + $header_images[ $header_index ]['thumbnail_url'] = $url; + $header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); $header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent'] ?? ''; if ( isset( $header_data['width'] ) ) {