WP_Block_Editor_Context example



// Don't load directly. if ( ! defined( 'ABSPATH' ) ) {
    die( '-1' );
}

// Flag that we're loading the block editor. $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() ) ),
    
'data',
            sprintf( 'var _wpCustomizeWidgetsSettings = %s;', wp_json_encode( $settings ) )
        );

        /* * TODO: Update 'wp-customize-widgets' to not rely so much on things in * 'customize-widgets'. This will let us skip most of the above and not * enqueue 'customize-widgets' which saves bytes. */

        if ( wp_use_widgets_block_editor() ) {
            $block_editor_context = new WP_Block_Editor_Context(
                array(
                    'name' => 'core/customize-widgets',
                )
            );

            $editor_settings = get_block_editor_settings(
                get_legacy_widget_block_editor_settings(),
                $block_editor_context
            );

            wp_add_inline_script(
                


/** * @global string $post_type * @global WP_Post_Type $post_type_object * @global WP_Post $post Global post object. * @global string $title * @global array $wp_meta_boxes */
global $post_type$post_type_object$post$title$wp_meta_boxes;

$block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );

// Flag that we're loading the block editor. $current_screen = get_current_screen();
$current_screen->is_block_editor( true );

// Default to is-fullscreen-mode to avoid jumps in the UI. add_filter(
    'admin_body_class',
    static function( $classes ) {
        return "$classes is-fullscreen-mode";
    }
);

function get_block_categories( $post_or_block_editor_context ) {
    $block_categories     = get_default_block_categories();
    $block_editor_context = $post_or_block_editor_context instanceof WP_Post ?
        new WP_Block_Editor_Context(
            array(
                'post' => $post_or_block_editor_context,
            )
        ) : $post_or_block_editor_context;

    /** * Filters the default array of categories for block types. * * @since 5.8.0 * * @param array[] $block_categories Array of categories for block types. * @param WP_Block_Editor_Context $block_editor_context The current block editor context. */
static function( $classes ) {
        return "$classes is-fullscreen-mode";
    }
);

$indexed_template_types = array();
foreach ( get_default_block_template_types() as $slug => $template_type ) {
    $template_type['slug']    = (string) $slug;
    $indexed_template_types[] = $template_type;
}

$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings      = array(
    'siteUrl'                   => site_url(),
    'postsPerPage'              => get_option( 'posts_per_page' ),
    'styles'                    => get_block_editor_theme_styles(),
    'defaultTemplateTypes'      => $indexed_template_types,
    'defaultTemplatePartAreas'  => get_allowed_block_template_part_areas(),
    'supportsLayout'            => wp_theme_has_theme_json(),
    'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
);

// Add additional back-compat patterns registered by `current_screen` et al.
Home | Imprint | This part of the site doesn't use cookies.