Gets (and/or creates) an appropriate fallback Navigation Menu.
Source
public static function get_fallback() {
/**
* Filters whether or not a fallback should be created.
*
* @since 6.3.0
*
* @param bool $create Whether to create a fallback navigation menu. Default true.
*/
$should_create_fallback = apply_filters( 'wp_navigation_should_create_fallback', true );
$fallback = static::get_most_recently_published_navigation();
if ( $fallback || ! $should_create_fallback ) {
return $fallback;
}
$fallback = static::create_classic_menu_fallback();
if ( $fallback && ! is_wp_error( $fallback ) ) {
// Return the newly created fallback post object which will now be the most recently created navigation menu.
return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation();
}
$fallback = static::create_default_fallback();
if ( $fallback && ! is_wp_error( $fallback ) ) {
// Return the newly created fallback post object which will now be the most recently created navigation menu.
return $fallback instanceof WP_Post ? $fallback : static::get_most_recently_published_navigation();
}
return null;
}
Hooks
- apply_filters( ‘wp_navigation_should_create_fallback’,
bool $create ) Filters whether or not a fallback should be created.
Changelog
Version | Description |
---|---|
6.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.