get_fallback example

array(
            'blockName' => 'core/page-list',
        ),
    );

    $registry = WP_Block_Type_Registry::get_instance();

    // If `core/page-list` is not registered then return empty blocks.     $fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

    if ( class_exists( 'WP_Navigation_Fallback' ) ) {
        $navigation_post = WP_Navigation_Fallback::get_fallback();
    } else {
        $navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
    }

    // Use the first non-empty Navigation as fallback if available.     if ( $navigation_post ) {
        $parsed_blocks  = parse_blocks( $navigation_post->post_content );
        $maybe_fallback = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );

        // Normalizing blocks may result in an empty array of blocks if they were all `null` blocks.         // In this case default to the (Page List) fallback.


    /** * Gets the most appropriate fallback Navigation Menu. * * @since 6.3.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_item( $request ) {
        $post = WP_Navigation_Fallback::get_fallback();

        if ( empty( $post ) ) {
            return rest_ensure_response( new WP_Error( 'no_fallback_menu', __( 'No fallback menu found.' ), array( 'status' => 404 ) ) );
        }

        $response = $this->prepare_item_for_response( $post$request );

        return $response;
    }

    /** * Retrieves the fallbacks' schema, conforming to JSON Schema. * * @since 6.3.0 * * @return array Item schema data. */
Home | Imprint | This part of the site doesn't use cookies.