array( array( '/wp/v2/media', 'OPTIONS' ), '/wp/v2/sidebars?context=edit&per_page=-1', '/wp/v2/widgets?context=edit&per_page=-1', ), 'editor_settings' => $settings, ) ); wp_enqueue_script( 'wp-edit-widgets' ); wp_enqueue_script( 'admin-widgets' ); wp_enqueue_script( 'wp-format-library' ); wp_enqueue_style( 'wp-edit-widgets' ); wp_enqueue_style( 'wp-format-library' ); do_action( 'enqueue_block_editor_assets' ); } add_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' ); /** * Tells the script loader to load the scripts and styles of custom block on widgets editor screen. * * @param bool $is_block_editor_screen Current decision about loading block assets. * @return bool Filtered decision about loading block assets. */ function gutenberg_widgets_editor_load_block_editor_scripts_and_styles( $is_block_editor_screen ) { if ( is_callable( 'get_current_screen' ) && 'appearance_page_gutenberg-widgets' === get_current_screen()->base ) { return true; } return $is_block_editor_screen; } add_filter( 'should_load_block_editor_scripts_and_styles', 'gutenberg_widgets_editor_load_block_editor_scripts_and_styles' ); /** * Show responsive embeds correctly on the widgets screen by adding the wp-embed-responsive class. * * @param string $classes existing admin body classes. * * @return string admin body classes including the wp-embed-responsive class. */ function gutenberg_widgets_editor_add_responsive_embed_body_class( $classes ) { return "$classes wp-embed-responsive"; } add_filter( 'admin_body_class', 'gutenberg_widgets_editor_add_responsive_embed_body_class' );