2021-05-25 04:52:58 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The block-based widgets editor, for use in widgets.php.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
$preload_paths = array(
|
|
|
|
array( '/wp/v2/media', 'OPTIONS' ),
|
|
|
|
'/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 );
|
|
|
|
|
2021-06-15 04:52:30 -04:00
|
|
|
$editor_settings = get_block_editor_settings(
|
2021-06-22 09:33:58 -04:00
|
|
|
array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ),
|
2021-06-15 04:52:30 -04:00
|
|
|
$block_editor_context
|
|
|
|
);
|
2021-05-25 04:52:58 -04:00
|
|
|
|
2021-06-22 12:56:56 -04:00
|
|
|
// 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' );
|
|
|
|
|
2021-05-25 04:52:58 -04:00
|
|
|
wp_add_inline_script(
|
|
|
|
'wp-edit-widgets',
|
|
|
|
sprintf(
|
|
|
|
'wp.domReady( function() {
|
|
|
|
wp.editWidgets.initialize( "widgets-editor", %s );
|
|
|
|
} );',
|
|
|
|
wp_json_encode( $editor_settings )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Preload server-registered block schemas.
|
|
|
|
wp_add_inline_script(
|
|
|
|
'wp-blocks',
|
|
|
|
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_add_inline_script(
|
|
|
|
'wp-blocks',
|
|
|
|
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( 'widgets-editor' ) ) ),
|
|
|
|
'after'
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script( 'wp-edit-widgets' );
|
|
|
|
wp_enqueue_script( 'admin-widgets' );
|
|
|
|
wp_enqueue_style( 'wp-edit-widgets' );
|
|
|
|
|
2021-05-27 05:07:01 -04:00
|
|
|
/** This action is documented in wp-admin/edit-form-blocks.php */
|
2021-05-25 04:52:58 -04:00
|
|
|
do_action( 'enqueue_block_editor_assets' );
|
|
|
|
|
2021-06-01 21:57:57 -04:00
|
|
|
/** This action is documented in wp-admin/widgets-form.php */
|
|
|
|
do_action( 'sidebar_admin_setup' );
|
|
|
|
|
2021-05-25 04:52:58 -04:00
|
|
|
require_once ABSPATH . 'wp-admin/admin-header.php';
|
2021-05-26 21:52:57 -04:00
|
|
|
|
2021-05-27 05:07:01 -04:00
|
|
|
/** This action is documented in wp-admin/widgets-form.php */
|
2021-05-26 21:52:57 -04:00
|
|
|
do_action( 'widgets_admin_page' );
|
2021-05-25 04:52:58 -04:00
|
|
|
?>
|
|
|
|
|
2021-06-22 12:56:56 -04:00
|
|
|
<div id="widgets-editor" class="blocks-widgets-container"></div>
|
2021-05-25 04:52:58 -04:00
|
|
|
|
|
|
|
<?php
|
2021-06-01 21:57:57 -04:00
|
|
|
/** This action is documented in wp-admin/widgets-form.php */
|
|
|
|
do_action( 'sidebar_admin_page' );
|
|
|
|
|
2021-05-25 04:52:58 -04:00
|
|
|
require_once ABSPATH . 'wp-admin/admin-footer.php';
|