Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/wp-includes/class-wp-navigation-fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ class WP_Navigation_Fallback {
*/
public static function get_fallback() {

/**
* Filters whether or not a fallback should be created.
*
* @since 6.3.0
*
* @param bool Whether or not to create a fallback.
*/
$should_create_fallback = apply_filters( 'wp_navigation_should_create_fallback', true );

$fallback = static::get_most_recently_published_navigation();

if ( $fallback ) {
if ( $fallback || ! $should_create_fallback ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we're not opting out of fetching a fallback, it's opting out of creating one either from:

  • converting a classic menu
  • creating a new block based menu

return $fallback;
}

Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/tests/editor/navigation-fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public function test_should_return_a_default_fallback_navigation_menu_in_absence
$this->assertCount( 1, $navs_in_db, 'The fallback Navigation post should be the only one in the database.' );
}

/**
* @ticket 58557
* @covers WP_REST_Navigation_Fallback_Controller::get_fallback
*/
public function test_should_not_automatically_create_fallback_if_filter_is_falsey() {

add_filter( 'gutenberg_navigation_should_create_fallback', '__return_false' );

$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertEmpty( $data );

$navs_in_db = $this->get_navigations_in_database();

$this->assertCount( 0, $navs_in_db, 'The fallback Navigation post should not have been created.' );

remove_filter( 'gutenberg_navigation_should_create_fallback', '__return_false' );
}

/**
* @ticket 58557
* @covers WP_REST_Navigation_Fallback_Controller::get_fallback
Expand Down