From 2c79bbd39ed54bbf465b19f74772e60d50080686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Fri, 9 Jan 2026 15:44:11 +0100 Subject: [PATCH 1/2] Code Modernization: Use null coalescing operator instead of isset() ternaries in remaining core files. --- src/wp-admin/includes/class-wp-comments-list-table.php | 8 ++++---- src/wp-admin/network/edit.php | 2 +- .../themes/twentyfourteen/inc/featured-content.php | 2 +- src/wp-content/themes/twentyfourteen/inc/widgets.php | 4 ++-- .../themes/twentytwentyone/inc/template-functions.php | 2 +- src/wp-includes/class-wp-xmlrpc-server.php | 2 +- src/wp-includes/functions.php | 2 +- src/wp-includes/post-formats.php | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index d51c9655e9950..5f1716199bbe6 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -105,14 +105,14 @@ public function prepare_items() { $comment_type = $_REQUEST['comment_type']; } - $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; + $search = $_REQUEST['s'] ?? ''; $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : ''; - $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; + $user_id = $_REQUEST['user_id'] ?? ''; - $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : ''; - $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : ''; + $orderby = $_REQUEST['orderby'] ?? ''; + $order = $_REQUEST['order'] ?? ''; $comments_per_page = $this->get_per_page( $comment_status ); diff --git a/src/wp-admin/network/edit.php b/src/wp-admin/network/edit.php index f46896bd2b5be..f12251babeeb3 100644 --- a/src/wp-admin/network/edit.php +++ b/src/wp-admin/network/edit.php @@ -10,7 +10,7 @@ /** Load WordPress Administration Bootstrap */ require_once __DIR__ . '/admin.php'; -$action = ( isset( $_GET['action'] ) ) ? $_GET['action'] : ''; +$action = $_GET['action'] ?? ''; if ( empty( $action ) ) { wp_redirect( network_admin_url() ); diff --git a/src/wp-content/themes/twentyfourteen/inc/featured-content.php b/src/wp-content/themes/twentyfourteen/inc/featured-content.php index b98ab983919df..7ae41b6bde63f 100644 --- a/src/wp-content/themes/twentyfourteen/inc/featured-content.php +++ b/src/wp-content/themes/twentyfourteen/inc/featured-content.php @@ -468,7 +468,7 @@ public static function get_setting( $key = 'all' ) { $options = array_intersect_key( $options, $defaults ); if ( 'all' !== $key ) { - return isset( $options[ $key ] ) ? $options[ $key ] : false; + return $options[ $key ] ?? false; } return $options; diff --git a/src/wp-content/themes/twentyfourteen/inc/widgets.php b/src/wp-content/themes/twentyfourteen/inc/widgets.php index 7c4f237294b3a..aee688d4783ef 100644 --- a/src/wp-content/themes/twentyfourteen/inc/widgets.php +++ b/src/wp-content/themes/twentyfourteen/inc/widgets.php @@ -70,7 +70,7 @@ public function enqueue_scripts() { * @param array $instance An array of settings for this widget instance. */ public function widget( $args, $instance ) { - $format = isset( $instance['format'] ) ? $instance['format'] : ''; + $format = $instance['format'] ?? ''; if ( ! $format || ! in_array( $format, $this->formats, true ) ) { $format = 'aside'; @@ -289,7 +289,7 @@ public function update( $new_instance, $old_instance ) { public function form( $instance ) { $title = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2; - $format = isset( $instance['format'] ) ? $instance['format'] : ''; + $format = $instance['format'] ?? ''; if ( ! $format || ! in_array( $format, $this->formats, true ) ) { $format = 'aside'; diff --git a/src/wp-content/themes/twentytwentyone/inc/template-functions.php b/src/wp-content/themes/twentytwentyone/inc/template-functions.php index 689b1e22c9814..a07869b9e1a0c 100644 --- a/src/wp-content/themes/twentytwentyone/inc/template-functions.php +++ b/src/wp-content/themes/twentytwentyone/inc/template-functions.php @@ -473,7 +473,7 @@ function twenty_twenty_one_get_attachment_image_attributes( $attr, $attachment, if ( $width && $height ) { // Add style. - $attr['style'] = isset( $attr['style'] ) ? $attr['style'] : ''; + $attr['style'] = $attr['style'] ?? ''; $attr['style'] = 'width:100%;height:' . round( 100 * $height / $width, 2 ) . '%;max-width:' . $width . 'px;' . $attr['style']; } diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index 0ae193ed54d96..1213dcb1481c2 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -4448,7 +4448,7 @@ public function wp_getMediaLibrary( $args ) { do_action( 'xmlrpc_call', 'wp.getMediaLibrary', $args, $this ); $parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; - $mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; + $mime_type = $struct['mime_type'] ?? ''; $offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; $number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 82a95c265edd8..9cdeef75788f2 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3351,7 +3351,7 @@ function wp_get_image_mime( $file ) { $imagesize = @getimagesize( $file ); } - $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false; + $mime = $imagesize['mime'] ?? false; } else { $mime = false; } diff --git a/src/wp-includes/post-formats.php b/src/wp-includes/post-formats.php index 2c199e6dc052d..9205ecb6e71e2 100644 --- a/src/wp-includes/post-formats.php +++ b/src/wp-includes/post-formats.php @@ -134,7 +134,7 @@ function get_post_format_string( $slug ) { if ( ! $slug ) { return $strings['standard']; } else { - return ( isset( $strings[ $slug ] ) ) ? $strings[ $slug ] : ''; + return $strings[ $slug ] ?? ''; } } From 3f35dca55d6db410bc4d205cbe5e49c1d26c213d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jan 2026 21:03:50 -0800 Subject: [PATCH 2/2] Revert null coalescing operator from themes which require PHP 5.6 compat --- src/wp-content/themes/twentyfourteen/inc/featured-content.php | 2 +- src/wp-content/themes/twentyfourteen/inc/widgets.php | 4 ++-- .../themes/twentytwentyone/inc/template-functions.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-content/themes/twentyfourteen/inc/featured-content.php b/src/wp-content/themes/twentyfourteen/inc/featured-content.php index 7ae41b6bde63f..b98ab983919df 100644 --- a/src/wp-content/themes/twentyfourteen/inc/featured-content.php +++ b/src/wp-content/themes/twentyfourteen/inc/featured-content.php @@ -468,7 +468,7 @@ public static function get_setting( $key = 'all' ) { $options = array_intersect_key( $options, $defaults ); if ( 'all' !== $key ) { - return $options[ $key ] ?? false; + return isset( $options[ $key ] ) ? $options[ $key ] : false; } return $options; diff --git a/src/wp-content/themes/twentyfourteen/inc/widgets.php b/src/wp-content/themes/twentyfourteen/inc/widgets.php index aee688d4783ef..7c4f237294b3a 100644 --- a/src/wp-content/themes/twentyfourteen/inc/widgets.php +++ b/src/wp-content/themes/twentyfourteen/inc/widgets.php @@ -70,7 +70,7 @@ public function enqueue_scripts() { * @param array $instance An array of settings for this widget instance. */ public function widget( $args, $instance ) { - $format = $instance['format'] ?? ''; + $format = isset( $instance['format'] ) ? $instance['format'] : ''; if ( ! $format || ! in_array( $format, $this->formats, true ) ) { $format = 'aside'; @@ -289,7 +289,7 @@ public function update( $new_instance, $old_instance ) { public function form( $instance ) { $title = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2; - $format = $instance['format'] ?? ''; + $format = isset( $instance['format'] ) ? $instance['format'] : ''; if ( ! $format || ! in_array( $format, $this->formats, true ) ) { $format = 'aside'; diff --git a/src/wp-content/themes/twentytwentyone/inc/template-functions.php b/src/wp-content/themes/twentytwentyone/inc/template-functions.php index a07869b9e1a0c..689b1e22c9814 100644 --- a/src/wp-content/themes/twentytwentyone/inc/template-functions.php +++ b/src/wp-content/themes/twentytwentyone/inc/template-functions.php @@ -473,7 +473,7 @@ function twenty_twenty_one_get_attachment_image_attributes( $attr, $attachment, if ( $width && $height ) { // Add style. - $attr['style'] = $attr['style'] ?? ''; + $attr['style'] = isset( $attr['style'] ) ? $attr['style'] : ''; $attr['style'] = 'width:100%;height:' . round( 100 * $height / $width, 2 ) . '%;max-width:' . $width . 'px;' . $attr['style']; }