block_editor_rest_api_preload example

$current_screen = get_current_screen();
$current_screen->is_block_editor( true );

$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-widgets' ) );

$preload_paths = array(
    array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
    '/wp/v2/widget-types?context=edit&per_page=-1',
    '/wp/v2/sidebars?context=edit&per_page=-1',
    '/wp/v2/widgets?context=edit&per_page=-1&_embed=about',
);
block_editor_rest_api_preload( $preload_paths$block_editor_context );

$editor_settings = get_block_editor_settings(
    array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ),
    $block_editor_context
);

// The widgets editor does not support the Block Directory, so don't load any of // its assets. This also prevents 'wp-editor' from being enqueued which we // cannot load in the widgets screen because many widget scripts rely on `wp.editor`. remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );

'orderby'   => 'date',
                // array indices are required to avoid query being encoded and not matching in cache.                 'status[0]' => 'publish',
                'status[1]' => 'draft',
            ),
            $navigation_rest_route
        ),
        'GET',
    ),
);

block_editor_rest_api_preload( $preload_paths$block_editor_context );

wp_add_inline_script(
    'wp-edit-site',
    sprintf(
        'wp.domReady( function() { wp.editSite.initializeEditor( "site-editor", %s ); } );',
        wp_json_encode( $editor_settings )
    )
);

sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
    '/wp/v2/users/me',
    array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
    array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
    array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
    array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ),
    sprintf( '%s/autosaves?context=edit', $rest_path ),
    '/wp/v2/settings',
    array( '/wp/v2/settings', 'OPTIONS' ),
);

block_editor_rest_api_preload( $preload_paths$block_editor_context );

wp_add_inline_script(
    'wp-blocks',
    sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
    'after'
);

/* * Assign initial edits, if applicable. These are not initially assigned to the persisted post, * but should be included in its save payload. */
Home | Imprint | This part of the site doesn't use cookies.