Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/blocks/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}
Expand Down
27 changes: 25 additions & 2 deletions src/wp-includes/navigation-areas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down