WP_Navigation_Fallback::get_fallback(): WP_Post|null

In this article

Gets (and/or creates) an appropriate fallback Navigation Menu.

Return

WP_Post|null the fallback Navigation Post or null.

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

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.