diff --git a/wp-admin/site-editor.php b/wp-admin/site-editor.php index b858d7ee53a0..14eec7c6c148 100644 --- a/wp-admin/site-editor.php +++ b/wp-admin/site-editor.php @@ -99,17 +99,8 @@ static function( $classes ) { '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', '/wp/v2/global-styles/' . $active_global_styles_id, '/wp/v2/themes/' . $active_theme . '/global-styles', - '/wp/v2/block-navigation-areas?context=edit', ); - $areas = get_option( 'wp_navigation_areas', array() ); - $active_areas = array_intersect_key( $areas, get_navigation_areas() ); - foreach ( $active_areas as $post_id ) { - if ( $post_id ) { - $preload_paths[] = add_query_arg( 'context', 'edit', rest_get_route_for_post( $post_id ) ); - } - } - block_editor_rest_api_preload( $preload_paths, $block_editor_context ); wp_add_inline_script( diff --git a/wp-includes/blocks/index.php b/wp-includes/blocks/index.php index 3ff63f5738db..727c7f313bf8 100644 --- a/wp-includes/blocks/index.php +++ b/wp-includes/blocks/index.php @@ -15,7 +15,6 @@ require ABSPATH . WPINC . '/blocks/latest-posts.php'; require ABSPATH . WPINC . '/blocks/legacy-widget.php'; require ABSPATH . WPINC . '/blocks/loginout.php'; -require ABSPATH . WPINC . '/blocks/navigation-area.php'; require ABSPATH . WPINC . '/blocks/navigation-link.php'; require ABSPATH . WPINC . '/blocks/navigation-submenu.php'; require ABSPATH . WPINC . '/blocks/navigation.php'; diff --git a/wp-includes/blocks/navigation-area.php b/wp-includes/blocks/navigation-area.php deleted file mode 100644 index 65c64428d0c2..000000000000 --- a/wp-includes/blocks/navigation-area.php +++ /dev/null @@ -1,22 +0,0 @@ - array( - 'navigationArea' => 'area', - ), - ) - ); -} -add_action( 'init', 'register_block_core_navigation_area' ); diff --git a/wp-includes/blocks/navigation-area/block.json b/wp-includes/blocks/navigation-area/block.json deleted file mode 100644 index 95ad0a513e65..000000000000 --- a/wp-includes/blocks/navigation-area/block.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "apiVersion": 2, - "name": "core/navigation-area", - "title": "Navigation Area", - "category": "theme", - "description": "Define a navigation area for your theme. The navigation block associated with this area will be automatically displayed.", - "keywords": [ - "menu", - "navigation", - "links", - "location" - ], - "textdomain": "default", - "attributes": { - "area": { - "type": "string", - "default": "primary" - } - }, - "providesContext": { - "navigationArea": "area" - }, - "supports": { - "html": false, - "inserter": true - } -} diff --git a/wp-includes/blocks/navigation.php b/wp-includes/blocks/navigation.php index e3848190c6e7..71c999e4a53a 100644 --- a/wp-includes/blocks/navigation.php +++ b/wp-includes/blocks/navigation.php @@ -183,14 +183,6 @@ function render_block_core_navigation( $attributes, $content, $block ) { $inner_blocks = new WP_Block_List( $parsed_blocks, $attributes ); } - if ( ! empty( $block->context['navigationArea'] ) ) { - $area = $block->context['navigationArea']; - $mapping = get_option( 'wp_navigation_areas', array() ); - if ( ! empty( $mapping[ $area ] ) ) { - $attributes['navigationMenuId'] = $mapping[ $area ]; - } - } - // Load inner blocks from the navigation post. if ( array_key_exists( 'navigationMenuId', $attributes ) ) { $navigation_post = get_post( $attributes['navigationMenuId'] ); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 5c1ed7178ad3..24396236484f 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -681,8 +681,4 @@ add_action( 'wp_footer', 'the_block_template_skip_link' ); add_action( 'setup_theme', 'wp_enable_block_templates' ); -// Navigation areas. -add_action( 'setup_theme', '_wp_register_default_navigation_areas' ); -add_action( 'switch_theme', '_wp_migrate_menu_to_navigation_post', 99, 3 ); - unset( $filter, $action ); diff --git a/wp-includes/navigation-areas.php b/wp-includes/navigation-areas.php deleted file mode 100644 index 5d946973bb80..000000000000 --- a/wp-includes/navigation-areas.php +++ /dev/null @@ -1,262 +0,0 @@ - 'Primary', - * 'secondary' => 'Secondary', - * 'tertiary' => 'Tertiary', - * ) - * - * @since 5.9.0 - * - * @param array $new_areas Supported navigation areas. - */ -function register_navigation_areas( $new_areas ) { - global $navigation_areas; - $navigation_areas = $new_areas; -} - -/** - * Register the default navigation areas. - * - * @since 5.9.0 - * @access private - */ -function _wp_register_default_navigation_areas() { - register_navigation_areas( - array( - 'primary' => _x( 'Primary', 'navigation area' ), - 'secondary' => _x( 'Secondary', 'navigation area' ), - 'tertiary' => _x( 'Tertiary', 'navigation area' ), - ) - ); -} - -/** - * Returns the available navigation areas. - * - * @since 5.9.0 - * - * @return array Registered navigation areas. - */ -function get_navigation_areas() { - global $navigation_areas; - return $navigation_areas; -} - -/** - * Migrates classic menus to a block-based navigation post on theme switch. - * Assigns the created navigation post to the corresponding navigation area. - * - * @since 5.9.0 - * @access private - * - * @param string $new_name Name of the new theme. - * @param WP_Theme $new_theme New theme. - * @param WP_Theme $old_theme Old theme. - */ -function _wp_migrate_menu_to_navigation_post( $new_name, WP_Theme $new_theme, WP_Theme $old_theme ) { - // Do nothing when switching to a theme that does not support site editor. - if ( ! wp_is_block_template_theme() ) { - return; - } - - // get_nav_menu_locations() calls get_theme_mod() which depends on the stylesheet option. - // At the same time, switch_theme runs only after the stylesheet option was updated to $new_theme. - // To retrieve theme mods of the old theme, the getter is hooked to get_option( 'stylesheet' ) so that we - // get the old theme, which causes the get_nav_menu_locations to get the locations of the old theme. - $get_old_theme_stylesheet = static function() use ( $old_theme ) { - return $old_theme->get_stylesheet(); - }; - add_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - $locations = get_nav_menu_locations(); - $area_mapping = get_option( 'wp_navigation_areas', array() ); - - foreach ( $locations as $location_name => $menu_id ) { - // Get the menu from the location, skipping if there is no - // menu or there was an error. - $menu = wp_get_nav_menu_object( $menu_id ); - if ( ! $menu || is_wp_error( $menu ) ) { - continue; - } - - $menu_items = _wp_get_menu_items_at_location( $location_name ); - if ( empty( $menu_items ) ) { - continue; - } - - $post_name = 'classic_menu_' . $menu_id; - - // Get or create to avoid creating too many wp_navigation posts. - $query = new WP_Query; - $matching_posts = $query->query( - array( - 'name' => $post_name, - 'post_status' => 'publish', - 'post_type' => 'wp_navigation', - 'posts_per_page' => 1, - 'fields' => 'ids', - ) - ); - - if ( ! empty( $matching_posts ) ) { - $navigation_post_id = $matching_posts[0]; - } else { - $menu_items_by_parent_id = _wp_sort_menu_items_by_parent_id( $menu_items ); - $parsed_blocks = _wp_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id ); - $post_data = array( - 'post_type' => 'wp_navigation', - 'post_title' => sprintf( - /* translators: %s: the name of the menu, e.g. "Main Menu". */ - __( 'Classic menu: %s' ), - $menu->name - ), - 'post_name' => $post_name, - 'post_content' => serialize_blocks( $parsed_blocks ), - 'post_status' => 'publish', - ); - $navigation_post_id = wp_insert_post( $post_data, true ); - // If wp_insert_post fails *at any time*, then bail out of the - // entire migration attempt returning the WP_Error object. - if ( is_wp_error( $navigation_post_id ) ) { - return $navigation_post_id; - } - } - - $area_mapping[ $location_name ] = $navigation_post_id; - } - remove_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - update_option( 'wp_navigation_areas', $area_mapping ); -} - -/** - * Returns the menu items for a WordPress menu location. - * - * @since 5.9.0 - * @access private - * - * @param string $location The menu location. - * @return array Menu items for the location. - */ -function _wp_get_menu_items_at_location( $location ) { - if ( empty( $location ) ) { - return; - } - - // Build menu data. The following approximates the code in `wp_nav_menu()`. - - // Find the location in the list of locations, returning early if the - // location can't be found. - $locations = get_nav_menu_locations(); - if ( ! isset( $locations[ $location ] ) ) { - return; - } - - // Get the menu from the location, returning early if there is no - // menu or there was an error. - $menu = wp_get_nav_menu_object( $locations[ $location ] ); - if ( ! $menu || is_wp_error( $menu ) ) { - return; - } - - $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); - _wp_menu_item_classes_by_context( $menu_items ); - - return $menu_items; -} - -/** - * Sorts a standard array of menu items into a nested structure keyed by the - * id of the parent menu. - * - * @since 5.9.0 - * @access private - * - * @param array $menu_items Menu items to sort. - * @return array An array keyed by the id of the parent menu where each element - * is an array of menu items that belong to that parent. - */ -function _wp_sort_menu_items_by_parent_id( $menu_items ) { - $sorted_menu_items = array(); - foreach ( $menu_items as $menu_item ) { - $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; - } - unset( $menu_items, $menu_item ); - - $menu_items_by_parent_id = array(); - foreach ( $sorted_menu_items as $menu_item ) { - $menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item; - } - - return $menu_items_by_parent_id; -} - -/** - * Turns menu item data into a nested array of parsed blocks - * - * @since 5.9.0 - * @access private - * - * @param array $menu_items An array of menu items that represent - * an individual level of a menu. - * @param array $menu_items_by_parent_id An array keyed by the id of the - * parent menu where each element is an - * array of menu items that belong to - * that parent. - * @return array An array of parsed block data. - */ -function _wp_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { - if ( empty( $menu_items ) ) { - return array(); - } - - $blocks = array(); - - foreach ( $menu_items as $menu_item ) { - $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null; - $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null; - $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; - $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; - $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; - - $block = array( - 'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link', - 'attrs' => array( - 'className' => $class_name, - 'description' => $menu_item->description, - 'id' => $id, - 'kind' => $kind, - 'label' => $menu_item->title, - 'opensInNewTab' => $opens_in_new_tab, - 'rel' => $rel, - 'title' => $menu_item->attr_title, - 'type' => $menu_item->object, - 'url' => $menu_item->url, - ), - ); - - if ( isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ) { - $block['innerBlocks'] = _wp_parse_blocks_from_menu_items( - $menu_items_by_parent_id[ $menu_item->ID ], - $menu_items_by_parent_id - ); - } else { - $block['innerBlocks'] = array(); - } - - $block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] ); - - $blocks[] = $block; - } - - return $blocks; -} diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 9f385efcf207..25f23fae6439 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -349,10 +349,6 @@ function create_initial_rest_routes() { // Menu Locations. $controller = new WP_REST_Menu_Locations_Controller(); $controller->register_routes(); - - // Block Navigation Areas - $controller = new WP_REST_Block_Navigation_Areas_Controller(); - $controller->register_routes(); } /** diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php deleted file mode 100644 index 84f09fac2198..000000000000 --- a/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php +++ /dev/null @@ -1,310 +0,0 @@ -namespace = 'wp/v2'; - $this->rest_base = 'block-navigation-areas'; - } - - /** - * Registers the routes for the objects of the controller. - * - * @since 5.9.0 - * - * @see register_rest_route() - */ - public function register_routes() { - register_rest_route( - $this->namespace, - '/' . $this->rest_base, - array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - - register_rest_route( - $this->namespace, - '/' . $this->rest_base . '/(?P[\w-]+)', - array( - 'args' => array( - 'area' => array( - 'description' => __( 'An alphanumeric identifier for the navigation area.' ), - 'type' => 'string', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - 'allow_batch' => array( 'v1' => true ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - } - - /** - * Checks whether a given request has permission to read navigation areas. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|bool True if the request has read access, WP_Error object otherwise. - */ - public function get_items_permissions_check( $request ) { - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - - return true; - } - - /** - * Retrieves all navigation areas, depending on user context. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_items( $request ) { - $data = array(); - foreach ( get_navigation_areas() as $name => $description ) { - $area = $this->get_navigation_area_object( $name ); - $area = $this->prepare_item_for_response( $area, $request ); - $data[] = $this->prepare_response_for_collection( $area ); - } - return rest_ensure_response( $data ); - } - - /** - * Checks if a given request has access to read a navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. - */ - public function get_item_permissions_check( $request ) { - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - if ( ! array_key_exists( $request['area'], get_navigation_areas() ) ) { - return new WP_Error( 'rest_navigation_area_invalid', __( 'Invalid navigation area.' ), array( 'status' => 404 ) ); - } - - return true; - } - - /** - * Checks if a request has access to update the specified term. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise. - */ - public function update_item_permissions_check( $request ) { - return $this->get_item_permissions_check( $request ); - } - - /** - * Retrieves a specific navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_item( $request ) { - $name = $request['area']; - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - - return rest_ensure_response( $data ); - } - - /** - * Updates a specific navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function update_item( $request ) { - $name = $request['area']; - - $mapping = get_option( 'wp_navigation_areas', array() ); - $mapping[ $name ] = $request['navigation']; - update_option( 'wp_navigation_areas', $mapping ); - - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - return rest_ensure_response( $data ); - } - - /** - * Converts navigation area name to a convenient object that this endpoint can reason about. - * - * @since 5.9.0 - * - * @param string $name Navigation area name. - * @return stdClass An object representation of the navigation area. - */ - protected function get_navigation_area_object( $name ) { - $available_areas = get_navigation_areas(); - $mapping = get_option( 'wp_navigation_areas', array() ); - $area = new stdClass(); - $area->name = $name; - $area->navigation = ! empty( $mapping[ $name ] ) ? $mapping[ $name ] : null; - $area->description = $available_areas[ $name ]; - return $area; - } - - /** - * Prepares a navigation area object for serialization. - * - * @since 5.9.0 - * - * @param stdClass $area Post status data. - * @param WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. - */ - public function prepare_item_for_response( $area, $request ) { - $areas = get_navigation_areas(); - $navigation = ( isset( $areas[ $area->name ] ) ) ? $area->navigation : 0; - - $fields = $this->get_fields_for_response( $request ); - $data = array(); - - if ( rest_is_field_included( 'name', $fields ) ) { - $data['name'] = $area->name; - } - - if ( rest_is_field_included( 'description', $fields ) ) { - $data['description'] = $area->description; - } - - if ( rest_is_field_included( 'navigation', $fields ) ) { - $data['navigation'] = (int) $navigation; - } - - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - - $response = rest_ensure_response( $data ); - - /** - * Filters a navigation area returned from the REST API. - * - * @since 5.9.0 - * - * Allows modification of the navigation area data right before it is - * returned. - * - * @param WP_REST_Response|WP_Error $response The response object, or WP_Error object on failure. - * @param object $area The original status object. - * @param WP_REST_Request $request Request used to generate the response. - */ - return apply_filters( 'rest_prepare_navigation_area', $response, $area, $request ); - } - - /** - * Retrieves the navigation area's schema, conforming to JSON Schema. - * - * @since 5.9.0 - * - * @return array Item schema data. - */ - public function get_item_schema() { - if ( $this->schema ) { - return $this->schema; - } - - $this->schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'navigation-area', - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the navigation area.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'description' => array( - 'description' => __( 'The description of the navigation area.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'navigation' => array( - 'description' => __( 'The ID of the assigned navigation.' ), - 'type' => 'integer', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - ), - ); - - return $this->add_additional_fields_schema( $this->schema ); - } - - /** - * Retrieves the query params for collections. - * - * @since 5.9.0 - * - * @return array Collection parameters. - */ - public function get_collection_params() { - return array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ); - } - -} diff --git a/wp-includes/version.php b/wp-includes/version.php index 3dc09060a031..9d365c4f7a3b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52271'; +$wp_version = '5.9-alpha-52272'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 0a55449bfc31..3b0e179baf14 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -246,7 +246,6 @@ require ABSPATH . WPINC . '/class-wp-widget-factory.php'; require ABSPATH . WPINC . '/nav-menu-template.php'; require ABSPATH . WPINC . '/nav-menu.php'; -require ABSPATH . WPINC . '/navigation-areas.php'; require ABSPATH . WPINC . '/admin-bar.php'; require ABSPATH . WPINC . '/class-wp-application-passwords.php'; require ABSPATH . WPINC . '/rest-api.php'; @@ -276,7 +275,6 @@ require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-plugins-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-directory-controller.php'; -require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-application-passwords-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php';