WP_Navigation_Fallback::create_classic_menu_fallback(): int|WP_Error

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Creates a Navigation Menu post from a Classic Menu.


int|WP_Error The post ID of the default fallback menu or a WP_Error object.


private static function create_classic_menu_fallback() {
	// See if we have a classic menu.
	$classic_nav_menu = static::get_fallback_classic_menu();

	if ( ! $classic_nav_menu ) {
		return new WP_Error( 'no_classic_menus', __( 'No Classic Menus found.' ) );

	// If there is a classic menu then convert it to blocks.
	$classic_nav_menu_blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );

	if ( is_wp_error( $classic_nav_menu_blocks ) ) {
		return $classic_nav_menu_blocks;

	if ( empty( $classic_nav_menu_blocks ) ) {
		return new WP_Error( 'cannot_convert_classic_menu', __( 'Unable to convert Classic Menu to blocks.' ) );

	// Create a new navigation menu from the classic menu.
	$classic_menu_fallback = wp_insert_post(
			'post_content' => $classic_nav_menu_blocks,
			'post_title'   => $classic_nav_menu->name,
			'post_name'    => $classic_nav_menu->slug,
			'post_status'  => 'publish',
			'post_type'    => 'wp_navigation',
		true // So that we can check whether the result is an error.

	return $classic_menu_fallback;



User Contributed Notes

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