2021-05-25 10:52:58 +02: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 );
2022-03-17 04:37:05 +01:00
$block_editor_context = new WP_Block_Editor_Context ( array ( 'name' => 'core/edit-widgets' ) );
2021-05-25 10:52:58 +02:00
$preload_paths = array (
2021-11-01 00:16:58 +01:00
array ( rest_get_route_for_post_type_items ( 'attachment' ), 'OPTIONS' ),
2022-04-07 15:40:04 +02:00
'/wp/v2/widget-types?context=edit&per_page=-1' ,
2021-05-25 10:52:58 +02:00
'/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 10:52:30 +02:00
$editor_settings = get_block_editor_settings (
2021-06-22 15:33:58 +02:00
array_merge ( get_legacy_widget_block_editor_settings (), array ( 'styles' => get_block_editor_theme_styles () ) ),
2021-06-15 10:52:30 +02:00
$block_editor_context
);
2021-05-25 10:52:58 +02:00
2021-06-22 18:56:56 +02: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 10:52:58 +02: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 () ) . ');'
);
2024-10-15 10:52:17 +02:00
// Preload server-registered block bindings sources.
$registered_sources = get_all_registered_block_bindings_sources ();
if ( ! empty ( $registered_sources ) ) {
$filtered_sources = array ();
foreach ( $registered_sources as $source ) {
$filtered_sources [] = array (
'name' => $source -> name ,
'label' => $source -> label ,
'usesContext' => $source -> uses_context ,
);
}
$script = sprintf ( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }' , wp_json_encode ( $filtered_sources ) );
wp_add_inline_script (
'wp-blocks' ,
$script
);
}
2021-05-25 10:52:58 +02:00
wp_add_inline_script (
'wp-blocks' ,
2021-08-31 15:38:58 +02:00
sprintf ( 'wp.blocks.setCategories( %s );' , wp_json_encode ( get_block_categories ( $block_editor_context ) ) ),
2021-05-25 10:52:58 +02:00
'after'
);
wp_enqueue_script ( 'wp-edit-widgets' );
wp_enqueue_script ( 'admin-widgets' );
wp_enqueue_style ( 'wp-edit-widgets' );
2021-05-27 11:07:01 +02:00
/** This action is documented in wp-admin/edit-form-blocks.php */
2021-05-25 10:52:58 +02:00
do_action ( 'enqueue_block_editor_assets' );
2021-06-02 03:57:57 +02:00
/** This action is documented in wp-admin/widgets-form.php */
do_action ( 'sidebar_admin_setup' );
2021-05-25 10:52:58 +02:00
require_once ABSPATH . 'wp-admin/admin-header.php' ;
2021-05-27 03:52:57 +02:00
2021-05-27 11:07:01 +02:00
/** This action is documented in wp-admin/widgets-form.php */
2021-05-27 03:52:57 +02:00
do_action ( 'widgets_admin_page' );
2021-05-25 10:52:58 +02:00
?>
Widgets: Add missing no JS notice in Widgets screen.
Add an H1 heading and an admin notice to display on the Widgets screen when JS is not available. Invite the user to either install or activate the Classic Widgets plugin, as that plugin provides basic functionality without JS.
Props afercia, nihar007, huzaifaalmesbah, joedolson, matthewfarlymn, bvreeman22, bosskhj, devmuhib, shailu25, joedolson.
Fixes #58738.
Built from https://develop.svn.wordpress.org/trunk@56671
git-svn-id: http://core.svn.wordpress.org/trunk@56183 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-09-25 02:00:17 +02:00
< div id = " widgets-editor " class = " blocks-widgets-container " >
< ? php // JavaScript is disabled. ?>
< div class = " wrap hide-if-js widgets-editor-no-js " >
< h1 class = " wp-heading-inline " >< ? php echo esc_html ( $title ); ?> </h1>
< ? php
if ( file_exists ( WP_PLUGIN_DIR . '/classic-widgets/classic-widgets.php' ) ) {
// If Classic Widgets is already installed, provide a link to activate the plugin.
$installed = true ;
$plugin_activate_url = wp_nonce_url ( 'plugins.php?action=activate&plugin=classic-widgets/classic-widgets.php' , 'activate-plugin_classic-widgets/classic-widgets.php' );
$message = sprintf (
/* translators: %s: Link to activate the Classic Widgets plugin. */
__ ( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Widgets plugin</a>.' ),
esc_url ( $plugin_activate_url )
);
} else {
// If Classic Widgets is not installed, provide a link to install it.
$installed = false ;
$plugin_install_url = wp_nonce_url ( self_admin_url ( 'update.php?action=install-plugin&plugin=classic-widgets' ), 'install-plugin_classic-widgets' );
$message = sprintf (
/* translators: %s: A link to install the Classic Widgets plugin. */
__ ( 'The block widgets require JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Widgets plugin</a>.' ),
esc_url ( $plugin_install_url )
);
}
/**
* Filters the message displayed in the block widget interface when JavaScript is
* not enabled in the browser .
*
* @ since 6.4 . 0
*
* @ param string $message The message being displayed .
* @ param bool $installed Whether the Classic Widget plugin is installed .
*/
$message = apply_filters ( 'block_widgets_no_javascript_message' , $message , $installed );
wp_admin_notice (
$message ,
array (
'type' => 'error' ,
'additional_classes' => array ( 'hide-if-js' ),
)
);
?>
</ div >
</ div >
2021-05-25 10:52:58 +02:00
< ? php
2021-06-02 03:57:57 +02:00
/** This action is documented in wp-admin/widgets-form.php */
do_action ( 'sidebar_admin_page' );
2021-05-25 10:52:58 +02:00
require_once ABSPATH . 'wp-admin/admin-footer.php' ;