From bab19a4cf59c0339c52bd38b56722eb3001b7772 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jan 2026 02:40:53 +0000 Subject: [PATCH] Code Modernization: Menus, Template, XML-RPC: Use null coalescing operator instead of `isset()` ternaries. Developed as a subset of https://github.com/WordPress/wordpress-develop/pull/10654 Initially developed in https://github.com/WordPress/wordpress-develop/pull/4886 Follow-up to [61453], [61445], [61444], [61443], [61442], [61436], [61435], [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403]. Props costdev, westonruter. See #58874, #63430. Built from https://develop.svn.wordpress.org/trunk@61454 git-svn-id: http://core.svn.wordpress.org/trunk@60766 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/nav-menu.php | 36 +++++++-------- wp-admin/link-parse-opml.php | 6 +-- wp-admin/nav-menus.php | 2 +- wp-includes/author-template.php | 6 +-- wp-includes/category-template.php | 2 +- wp-includes/class-wp-xmlrpc-server.php | 40 ++++++++--------- wp-includes/css/dist/index.php | 46 ++++++++++---------- wp-includes/general-template.php | 4 +- wp-includes/js/dist/script-modules/index.php | 20 ++++----- wp-includes/link-template.php | 2 +- wp-includes/nav-menu.php | 4 +- wp-includes/version.php | 2 +- 12 files changed, 85 insertions(+), 85 deletions(-) diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index 4fb6afe36c..d893be35aa 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -22,10 +22,10 @@ require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php'; */ function _wp_ajax_menu_quick_search( $request = array() ) { $args = array(); - $type = isset( $request['type'] ) ? $request['type'] : ''; - $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; - $query = isset( $request['q'] ) ? $request['q'] : ''; - $response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; + $type = $request['type'] ?? ''; + $object_type = $request['object_type'] ?? ''; + $query = $request['q'] ?? ''; + $response_format = $request['response-format'] ?? ''; if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { $response_format = 'json'; @@ -1183,19 +1183,19 @@ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { } $args = array( - 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), - 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), - 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), - 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), - 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), - 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), - 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), - 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), - 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), - 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), - 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), - 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), - 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), + 'menu-item-db-id' => $_item_object_data['menu-item-db-id'] ?? '', + 'menu-item-object-id' => $_item_object_data['menu-item-object-id'] ?? '', + 'menu-item-object' => $_item_object_data['menu-item-object'] ?? '', + 'menu-item-parent-id' => $_item_object_data['menu-item-parent-id'] ?? '', + 'menu-item-position' => $_item_object_data['menu-item-position'] ?? '', + 'menu-item-type' => $_item_object_data['menu-item-type'] ?? '', + 'menu-item-title' => $_item_object_data['menu-item-title'] ?? '', + 'menu-item-url' => $_item_object_data['menu-item-url'] ?? '', + 'menu-item-description' => $_item_object_data['menu-item-description'] ?? '', + 'menu-item-attr-title' => $_item_object_data['menu-item-attr-title'] ?? '', + 'menu-item-target' => $_item_object_data['menu-item-target'] ?? '', + 'menu-item-classes' => $_item_object_data['menu-item-classes'] ?? '', + 'menu-item-xfn' => $_item_object_data['menu-item-xfn'] ?? '', ); $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); @@ -1447,7 +1447,7 @@ function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte $args = array(); foreach ( $post_fields as $field ) { - $args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; + $args[ $field ] = $_POST[ $field ][ $_key ] ?? ''; } $menu_item_db_id = wp_update_nav_menu_item( diff --git a/wp-admin/link-parse-opml.php b/wp-admin/link-parse-opml.php index 513ed074dc..ba31fbef83 100644 --- a/wp-admin/link-parse-opml.php +++ b/wp-admin/link-parse-opml.php @@ -55,9 +55,9 @@ function startElement( $parser, $tag_name, $attrs ) { // phpcs:ignore WordPress. // Save the data away. $names[] = $name; $urls[] = $url; - $targets[] = isset( $attrs['TARGET'] ) ? $attrs['TARGET'] : ''; - $feeds[] = isset( $attrs['XMLURL'] ) ? $attrs['XMLURL'] : ''; - $descriptions[] = isset( $attrs['DESCRIPTION'] ) ? $attrs['DESCRIPTION'] : ''; + $targets[] = $attrs['TARGET'] ?? ''; + $feeds[] = $attrs['XMLURL'] ?? ''; + $descriptions[] = $attrs['DESCRIPTION'] ?? ''; } // End if outline. } diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 5b1a48c123..f42f51e266 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -52,7 +52,7 @@ $menu_locations = get_nav_menu_locations(); $num_locations = count( array_keys( $locations ) ); // Allowed actions: add, update, delete. -$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit'; +$action = $_REQUEST['action'] ?? 'edit'; /* * If a JSON blob of navigation menu data is found, expand it and inject it diff --git a/wp-includes/author-template.php b/wp-includes/author-template.php index 3de4432b5e..3cd21248b7 100644 --- a/wp-includes/author-template.php +++ b/wp-includes/author-template.php @@ -169,7 +169,7 @@ function get_the_author_meta( $field = '', $user_id = false ) { if ( ! $user_id ) { global $authordata; - $user_id = isset( $authordata->ID ) ? $authordata->ID : 0; + $user_id = $authordata->ID ?? 0; } else { $authordata = get_userdata( $user_id ); } @@ -178,7 +178,7 @@ function get_the_author_meta( $field = '', $user_id = false ) { $field = 'user_' . $field; } - $value = isset( $authordata->$field ) ? $authordata->$field : ''; + $value = $authordata->$field ?? ''; /** * Filters the value of the requested user metadata. @@ -502,7 +502,7 @@ function wp_list_authors( $args = '' ) { } foreach ( $authors as $author_id ) { - $posts = isset( $post_counts[ $author_id ] ) ? $post_counts[ $author_id ] : 0; + $posts = $post_counts[ $author_id ] ?? 0; if ( ! $posts && $parsed_args['hide_empty'] ) { continue; diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index b2c88c9c25..37427b25dd 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -963,7 +963,7 @@ function wp_generate_tag_cloud( $tags, $args = '' ) { // Assemble the data that will be used to generate the tag cloud markup. $tags_data = array(); foreach ( $tags as $key => $tag ) { - $tag_id = isset( $tag->id ) ? $tag->id : $key; + $tag_id = $tag->id ?? $key; $count = $counts[ $key ]; $real_count = $real_counts[ $key ]; diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index 7c1e101e1e..0ae193ed54 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -1680,7 +1680,7 @@ class wp_xmlrpc_server extends IXR_Server { } // Handle enclosures. - $enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; + $enclosure = $post_data['enclosure'] ?? null; $this->add_enclosure_if_new( $post_id, $enclosure ); $this->attach_uploads( $post_id, $post_data['post_content'] ); @@ -1986,7 +1986,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $filter = isset( $args[3] ) ? $args[3] : array(); + $filter = $args[3] ?? array(); if ( isset( $args[4] ) ) { $fields = $args[4]; @@ -2457,7 +2457,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; $taxonomy = $args[3]; - $filter = isset( $args[4] ) ? $args[4] : array(); + $filter = $args[4] ?? array(); $user = $this->login( $username, $password ); if ( ! $user ) { @@ -2615,7 +2615,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); + $filter = $args[3] ?? array( 'public' => true ); if ( isset( $args[4] ) ) { $fields = $args[4]; @@ -2764,7 +2764,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $filter = isset( $args[3] ) ? $args[3] : array(); + $filter = $args[3] ?? array(); if ( isset( $args[4] ) ) { $fields = $args[4]; @@ -3658,7 +3658,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $struct = isset( $args[3] ) ? $args[3] : array(); + $struct = $args[3] ?? array(); $user = $this->login( $username, $password ); if ( ! $user ) { @@ -4433,7 +4433,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $struct = isset( $args[3] ) ? $args[3] : array(); + $struct = $args[3] ?? array(); $user = $this->login( $username, $password ); if ( ! $user ) { @@ -4624,7 +4624,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; - $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); + $filter = $args[3] ?? array( 'public' => true ); if ( isset( $args[4] ) ) { $fields = $args[4]; @@ -5375,7 +5375,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; - $publish = isset( $args[4] ) ? $args[4] : 0; + $publish = $args[4] ?? 0; $user = $this->login( $username, $password ); if ( ! $user ) { @@ -5491,8 +5491,8 @@ class wp_xmlrpc_server extends IXR_Server { $post_author = $content_struct['wp_author_id']; } - $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : ''; - $post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : ''; + $post_title = $content_struct['title'] ?? ''; + $post_content = $content_struct['description'] ?? ''; $post_status = $publish ? 'publish' : 'draft'; @@ -5510,10 +5510,10 @@ class wp_xmlrpc_server extends IXR_Server { } } - $post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : ''; - $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; + $post_excerpt = $content_struct['mt_excerpt'] ?? ''; + $post_more = $content_struct['mt_text_more'] ?? ''; - $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); + $tags_input = $content_struct['mt_keywords'] ?? array(); if ( isset( $content_struct['mt_allow_comments'] ) ) { if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { @@ -5661,7 +5661,7 @@ class wp_xmlrpc_server extends IXR_Server { } // Handle enclosures. - $enclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; + $enclosure = $content_struct['enclosure'] ?? null; $this->add_enclosure_if_new( $post_id, $enclosure ); $this->attach_uploads( $post_id, $post_content ); @@ -5771,7 +5771,7 @@ class wp_xmlrpc_server extends IXR_Server { $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; - $publish = isset( $args[4] ) ? $args[4] : 0; + $publish = $args[4] ?? 0; $user = $this->login( $username, $password ); if ( ! $user ) { @@ -5955,7 +5955,7 @@ class wp_xmlrpc_server extends IXR_Server { $post_excerpt = $content_struct['mt_excerpt']; } - $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; + $post_more = $content_struct['mt_text_more'] ?? ''; $post_status = $publish ? 'publish' : 'draft'; if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { @@ -5972,7 +5972,7 @@ class wp_xmlrpc_server extends IXR_Server { } } - $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); + $tags_input = $content_struct['mt_keywords'] ?? array(); if ( 'publish' === $post_status || 'private' === $post_status ) { if ( 'page' === $post_type && ! current_user_can( 'publish_pages' ) ) { @@ -6080,7 +6080,7 @@ class wp_xmlrpc_server extends IXR_Server { } // Handle enclosures. - $enclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; + $enclosure = $content_struct['enclosure'] ?? null; $this->add_enclosure_if_new( $post_id, $enclosure ); $this->attach_uploads( $post_id, $post_content ); @@ -7059,7 +7059,7 @@ class wp_xmlrpc_server extends IXR_Server { $remote_source = preg_replace( '/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/', "\n\n", $remote_source ); preg_match( '|([^<]*?)|is', $remote_source, $matchtitle ); - $title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; + $title = $matchtitle[1] ?? ''; if ( empty( $title ) ) { return $this->pingback_error( 32, __( 'A title on that page cannot be found.' ) ); } diff --git a/wp-includes/css/dist/index.php b/wp-includes/css/dist/index.php index 77d1f53a44..8225275629 100644 --- a/wp-includes/css/dist/index.php +++ b/wp-includes/css/dist/index.php @@ -13,13 +13,13 @@ return array( 'dependencies' => array('wp-components'), ), array( - 'handle' => 'wp-list-reusable-blocks', - 'path' => 'list-reusable-blocks/style', + 'handle' => 'wp-nux', + 'path' => 'nux/style', 'dependencies' => array('wp-components'), ), array( - 'handle' => 'wp-nux', - 'path' => 'nux/style', + 'handle' => 'wp-list-reusable-blocks', + 'path' => 'list-reusable-blocks/style', 'dependencies' => array('wp-components'), ), array( @@ -33,18 +33,13 @@ return array( 'dependencies' => array('wp-block-editor', 'wp-components'), ), array( - 'handle' => 'wp-patterns', - 'path' => 'patterns/style', + 'handle' => 'wp-widgets', + 'path' => 'widgets/style', 'dependencies' => array('wp-block-editor', 'wp-components'), ), array( - 'handle' => 'wp-components', - 'path' => 'components/style', - 'dependencies' => array(), - ), - array( - 'handle' => 'wp-widgets', - 'path' => 'widgets/style', + 'handle' => 'wp-patterns', + 'path' => 'patterns/style', 'dependencies' => array('wp-block-editor', 'wp-components'), ), array( @@ -52,16 +47,16 @@ return array( 'path' => 'format-library/style', 'dependencies' => array('wp-block-editor', 'wp-components'), ), + array( + 'handle' => 'wp-components', + 'path' => 'components/style', + 'dependencies' => array(), + ), array( 'handle' => 'wp-block-directory', 'path' => 'block-directory/style', 'dependencies' => array('wp-block-editor', 'wp-components', 'wp-editor'), ), - array( - 'handle' => 'wp-media-utils', - 'path' => 'media-utils/style', - 'dependencies' => array('wp-components'), - ), array( 'handle' => 'wp-customize-widgets', 'path' => 'customize-widgets/style', @@ -72,6 +67,11 @@ return array( 'path' => 'edit-post/style', 'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-preferences', 'wp-widgets'), ), + array( + 'handle' => 'wp-media-utils', + 'path' => 'media-utils/style', + 'dependencies' => array('wp-components'), + ), array( 'handle' => 'wp-edit-widgets', 'path' => 'edit-widgets/style', @@ -87,14 +87,14 @@ return array( 'path' => 'editor/style', 'dependencies' => array('wp-block-editor', 'wp-commands', 'wp-components', 'wp-media-utils', 'wp-patterns', 'wp-preferences'), ), - array( - 'handle' => 'wp-block-editor', - 'path' => 'block-editor/style', - 'dependencies' => array('wp-commands', 'wp-components', 'wp-preferences'), - ), array( 'handle' => 'wp-edit-site', 'path' => 'edit-site/style', 'dependencies' => array('wp-block-editor', 'wp-block-library', 'wp-commands', 'wp-components', 'wp-editor', 'wp-patterns', 'wp-preferences', 'wp-widgets'), ), + array( + 'handle' => 'wp-block-editor', + 'path' => 'block-editor/style', + 'dependencies' => array('wp-commands', 'wp-components', 'wp-preferences'), + ), ); diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index df18cc9731..ac5427e2ce 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -4658,7 +4658,7 @@ function paginate_links( $args = '' ) { $url_parts = explode( '?', $pagenum_link ); // Get max pages and current page out of the current query, if available. - $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; + $total = $wp_query->max_num_pages ?? 1; $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; // Append the format placeholder to the base URL. @@ -4697,7 +4697,7 @@ function paginate_links( $args = '' ) { if ( isset( $url_parts[1] ) ) { // Find the format argument. $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); - $format_query = isset( $format[1] ) ? $format[1] : ''; + $format_query = $format[1] ?? ''; wp_parse_str( $format_query, $format_args ); // Find the query args of the requested URL. diff --git a/wp-includes/js/dist/script-modules/index.php b/wp-includes/js/dist/script-modules/index.php index 5092400493..d1589d51ab 100644 --- a/wp-includes/js/dist/script-modules/index.php +++ b/wp-includes/js/dist/script-modules/index.php @@ -7,11 +7,6 @@ */ return array( - array( - 'id' => '@wordpress/interactivity', - 'path' => 'interactivity/index', - 'asset' => 'interactivity/index.min.asset.php', - ), array( 'id' => '@wordpress/a11y', 'path' => 'a11y/index', @@ -22,6 +17,11 @@ return array( 'path' => 'core-abilities/index', 'asset' => 'core-abilities/index.min.asset.php', ), + array( + 'id' => '@wordpress/interactivity', + 'path' => 'interactivity/index', + 'asset' => 'interactivity/index.min.asset.php', + ), array( 'id' => '@wordpress/interactivity-router', 'path' => 'interactivity-router/index', @@ -37,6 +37,11 @@ return array( 'path' => 'abilities/index', 'asset' => 'abilities/index.min.asset.php', ), + array( + 'id' => '@wordpress/route', + 'path' => 'route/index', + 'asset' => 'route/index.min.asset.php', + ), array( 'id' => '@wordpress/latex-to-mathml', 'path' => 'latex-to-mathml/index', @@ -47,11 +52,6 @@ return array( 'path' => 'latex-to-mathml/loader', 'asset' => 'latex-to-mathml/loader.min.asset.php', ), - array( - 'id' => '@wordpress/route', - 'path' => 'route/index', - 'asset' => 'route/index.min.asset.php', - ), array( 'id' => '@wordpress/edit-site-init', 'path' => 'edit-site-init/index', diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index d1af2996bc..beafac3226 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -2438,7 +2438,7 @@ function get_pagenum_link( $pagenum = 1, $escape = true ) { $request = remove_query_arg( 'paged' ); $home_root = parse_url( home_url() ); - $home_root = ( isset( $home_root['path'] ) ) ? $home_root['path'] : ''; + $home_root = $home_root['path'] ?? ''; $home_root = preg_quote( $home_root, '|' ); $request = preg_replace( '|^' . $home_root . '|i', '', $request ); diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index d808c4e212..83a67cfe2a 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -319,8 +319,8 @@ function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) { $_menu = wp_get_nav_menu_object( $menu_id ); $args = array( - 'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ), - 'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ), + 'description' => $menu_data['description'] ?? '', + 'name' => $menu_data['menu-name'] ?? '', 'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ), 'slug' => null, ); diff --git a/wp-includes/version.php b/wp-includes/version.php index b78b2f9a1f..14d8fe1244 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '7.0-alpha-61453'; +$wp_version = '7.0-alpha-61454'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.