Skip to content

Commit

Permalink
Rename fse_navigation_area to wp_navigation_area (#36460)
Browse files Browse the repository at this point in the history
* Rename fse_navigation_area to wp_navigation_area

* Update lib/navigation.php

Co-authored-by: Dave Smith <[email protected]>

* Lint

* Rename the remaining function calls to gutenberg_get_navigation_areas_menus

Co-authored-by: Dave Smith <[email protected]>
  • Loading branch information
2 people authored and noisysocks committed Nov 15, 2021
1 parent af2a7cf commit da0f553
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/class-wp-rest-block-navigation-areas-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public function get_item( $request ) {
public function update_item( $request ) {
$name = $request['area'];

$mapping = get_option( 'fse_navigation_areas', array() );
$mapping = gutenberg_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 @@ -182,7 +182,7 @@ public function update_item( $request ) {
*/
private function get_navigation_area_object( $name ) {
$available_areas = gutenberg_get_navigation_areas();
$mapping = get_option( 'fse_navigation_areas', array() );
$mapping = gutenberg_get_navigation_areas_menus();
$area = new stdClass();
$area->name = $name;
$area->navigation = ! empty( $mapping[ $name ] ) ? $mapping[ $name ] : null;
Expand Down
23 changes: 20 additions & 3 deletions lib/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function gutenberg_get_navigation_areas() {
* @return array A list of paths.
*/
function gutenberg_get_navigation_areas_paths_to_preload() {
$areas = get_option( 'fse_navigation_areas', array() );
$areas = gutenberg_get_navigation_areas_menus();
$active_areas = array_intersect_key( $areas, gutenberg_get_navigation_areas() );
$paths = array(
'/wp/v2/block-navigation-areas?context=edit',
Expand Down Expand Up @@ -225,7 +225,7 @@ function gutenberg_migrate_menu_to_navigation_post( $new_name, $new_theme, $old_
add_filter( 'option_stylesheet', $get_old_theme_stylesheet );

$locations = get_nav_menu_locations();
$area_mapping = get_option( 'fse_navigation_areas', array() );
$area_mapping = gutenberg_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 @@ -277,11 +277,28 @@ function gutenberg_migrate_menu_to_navigation_post( $new_name, $new_theme, $old_
}
remove_filter( 'option_stylesheet', $get_old_theme_stylesheet );

update_option( 'fse_navigation_areas', $area_mapping );
update_option( 'wp_navigation_areas', $area_mapping );
}

add_action( 'switch_theme', 'gutenberg_migrate_menu_to_navigation_post', 200, 3 );

/**
* Retrieves navigation areas.
*
* @return array Navigation areas.
*/
function gutenberg_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;
}

// The functions below are copied over from packages/block-library/src/navigation/index.php
// Let's figure out a better way of managing these global PHP dependencies.

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/index.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 = get_option( 'wp_navigation_areas', array() );
if ( ! empty( $mapping[ $area ] ) ) {
$attributes['navigationMenuId'] = $mapping[ $area ];
}
Expand Down

0 comments on commit da0f553

Please sign in to comment.