diff --git a/src/wp-includes/blocks/navigation.php b/src/wp-includes/blocks/navigation.php index bbaa8794be985..be67f1ea4279c 100644 --- a/src/wp-includes/blocks/navigation.php +++ b/src/wp-includes/blocks/navigation.php @@ -147,7 +147,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { if ( ! empty( $block->context['navigationArea'] ) ) { $area = $block->context['navigationArea']; - $mapping = get_option( 'fse_navigation_areas', array() ); + $mapping = _wp_get_navigation_areas_menus(); if ( ! empty( $mapping[ $area ] ) ) { $attributes['navigationMenuId'] = $mapping[ $area ]; } diff --git a/src/wp-includes/navigation-areas.php b/src/wp-includes/navigation-areas.php index e2d7460c3815a..7bf10540cd8a3 100644 --- a/src/wp-includes/navigation-areas.php +++ b/src/wp-includes/navigation-areas.php @@ -78,7 +78,7 @@ function _wp_migrate_menu_to_navigation_post( $new_name, WP_Theme $new_theme, WP add_filter( 'option_stylesheet', $get_old_theme_stylesheet ); $locations = get_nav_menu_locations(); - $area_mapping = get_option( 'fse_navigation_areas', array() ); + $area_mapping = _wp_get_navigation_areas_menus(); foreach ( $locations as $location_name => $menu_id ) { // Get the menu from the location, skipping if there is no @@ -124,15 +124,38 @@ function _wp_migrate_menu_to_navigation_post( $new_name, WP_Theme $new_theme, WP 'post_status' => 'publish', ); $navigation_post_id = wp_insert_post( $post_data ); + // If wp_insert_post fails *at any time*, then bale 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( 'fse_navigation_areas', $area_mapping ); + update_option( 'wp_navigation_areas', $area_mapping ); } +/** + * Retrieves navigation areas. + * + * @return array Navigation areas. + */ +function _wp_get_navigation_areas_menus() { + $areas = get_option( 'wp_navigation_areas', array() ); + if ( ! $areas ) { + // Original key used `fse` prefix but Core options should use `wp`. + // We fallback to the legacy option to catch sites with values in the + // original location. + $legacy_option_key = 'fse_navigation_areas'; + $areas = get_option( $legacy_option_key, array() ); + } + return $areas; +} + + /** * Returns the menu items for a WordPress menu location. * diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php index ef515f5970615..cb3005ef83fc8 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php @@ -177,9 +177,9 @@ public function get_item( $request ) { public function update_item( $request ) { $name = $request['area']; - $mapping = get_option( 'fse_navigation_areas', array() ); + $mapping = _wp_get_navigation_areas_menus(); $mapping[ $name ] = $request['navigation']; - update_option( 'fse_navigation_areas', $mapping ); + update_option( 'wp_navigation_areas', $mapping ); $area = $this->get_navigation_area_object( $name ); $data = $this->prepare_item_for_response( $area, $request ); @@ -196,7 +196,7 @@ public function update_item( $request ) { */ protected function get_navigation_area_object( $name ) { $available_areas = get_navigation_areas(); - $mapping = get_option( 'fse_navigation_areas', array() ); + $mapping = _wp_get_navigation_areas_menus(); $area = new stdClass(); $area->name = $name; $area->navigation = ! empty( $mapping[ $name ] ) ? $mapping[ $name ] : null;