widgets-form-blocks.php (2410B)
1 <?php 2 /** 3 * The block-based widgets editor, for use in widgets.php. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 // Don't load directly. 10 if ( ! defined( 'ABSPATH' ) ) { 11 die( '-1' ); 12 } 13 14 // Flag that we're loading the block editor. 15 $current_screen = get_current_screen(); 16 $current_screen->is_block_editor( true ); 17 18 $block_editor_context = new WP_Block_Editor_Context(); 19 20 $preload_paths = array( 21 array( '/wp/v2/media', 'OPTIONS' ), 22 '/wp/v2/sidebars?context=edit&per_page=-1', 23 '/wp/v2/widgets?context=edit&per_page=-1&_embed=about', 24 ); 25 block_editor_rest_api_preload( $preload_paths, $block_editor_context ); 26 27 $editor_settings = get_block_editor_settings( 28 array_merge( get_legacy_widget_block_editor_settings(), array( 'styles' => get_block_editor_theme_styles() ) ), 29 $block_editor_context 30 ); 31 32 // The widgets editor does not support the Block Directory, so don't load any of 33 // its assets. This also prevents 'wp-editor' from being enqueued which we 34 // cannot load in the widgets screen because many widget scripts rely on `wp.editor`. 35 remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); 36 37 wp_add_inline_script( 38 'wp-edit-widgets', 39 sprintf( 40 'wp.domReady( function() { 41 wp.editWidgets.initialize( "widgets-editor", %s ); 42 } );', 43 wp_json_encode( $editor_settings ) 44 ) 45 ); 46 47 // Preload server-registered block schemas. 48 wp_add_inline_script( 49 'wp-blocks', 50 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' 51 ); 52 53 wp_add_inline_script( 54 'wp-blocks', 55 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ), 56 'after' 57 ); 58 59 wp_enqueue_script( 'wp-edit-widgets' ); 60 wp_enqueue_script( 'admin-widgets' ); 61 wp_enqueue_style( 'wp-edit-widgets' ); 62 63 /** This action is documented in wp-admin/edit-form-blocks.php */ 64 do_action( 'enqueue_block_editor_assets' ); 65 66 /** This action is documented in wp-admin/widgets-form.php */ 67 do_action( 'sidebar_admin_setup' ); 68 69 require_once ABSPATH . 'wp-admin/admin-header.php'; 70 71 /** This action is documented in wp-admin/widgets-form.php */ 72 do_action( 'widgets_admin_page' ); 73 ?> 74 75 <div id="widgets-editor" class="blocks-widgets-container"></div> 76 77 <?php 78 /** This action is documented in wp-admin/widgets-form.php */ 79 do_action( 'sidebar_admin_page' ); 80 81 require_once ABSPATH . 'wp-admin/admin-footer.php';