Block Editor: Display notice to the user when JavaScript is disabled.

Currently, when viewing the block editor with JavaScript disabled, the user sees a blank admin page with the admin menu sidebar. This adds an admin notice informing the user that JavaScript is required for the new block editor.

Props mkaz, pento, azaozz, ocean90, desrosj.
Fixes #45453.

git-svn-id: https://develop.svn.wordpress.org/trunk@44437 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2019-01-07 20:39:56 +00:00
parent 60af2079ed
commit c7fb3b36ea
3 changed files with 36 additions and 8 deletions

View File

@ -560,6 +560,10 @@ code {
margin: 10px 20px 0 2px;
}
.wrap.block-editor-no-js {
padding-left: 20px;
}
.wrap > h2:first-child, /* Back-compat for pre-4.4 */
.wrap [class$="icon32"] + h2, /* Back-compat for pre-4.4 */
.postbox .inside h2, /* Back-compat for pre-4.4 */

View File

@ -23,10 +23,6 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes;
if ( ! empty( $post_type_object ) ) {
$title = $post_type_object->labels->edit_item;
}
// Flag that we're loading the block editor.
$current_screen = get_current_screen();
$current_screen->is_block_editor( true );
@ -399,9 +395,36 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="block-editor">
<h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1>
<div id="editor" class="block-editor__container"></div>
<h1 class="screen-reader-text hide-if-no-js"><?php echo esc_html( $title ); ?></h1>
<div id="editor" class="block-editor__container hide-if-no-js"></div>
<div id="metaboxes" class="hidden">
<?php the_block_editor_meta_boxes(); ?>
</div>
<?php // JavaScript is disabled. ?>
<div class="wrap hide-if-js block-editor-no-js">
<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
<div class="notice notice-error notice-alt">
<p>
<?php
$message = sprintf(
/* translators: %s: https://wordpress.org/plugins/classic-editor/ */
__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or try the <a href="%s">Classic Editor plugin</a>.' ),
__( 'https://wordpress.org/plugins/classic-editor/' )
);
/**
* Filters the message displayed in the block editor interface when JavaScript is
* not enabled in the browser.
*
* @since 5.0.3
*
* @param string $message The message being displayed.
* @param WP_Post $post The post being edited.
*/
echo apply_filters( 'block_editor_no_javascript_message', $message, $post );
?>
</p>
</div>
</div>
</div>

View File

@ -154,6 +154,8 @@ switch ( $action ) {
$post_new_file = "post-new.php?post_type=$post_type";
}
$title = $post_type_object->labels->edit_item;
/**
* Allows replacement of the editor.
*
@ -179,8 +181,7 @@ switch ( $action ) {
}
}
$title = $post_type_object->labels->edit_item;
$post = get_post( $post_id, OBJECT, 'edit' );
$post = get_post( $post_id, OBJECT, 'edit' );
if ( post_type_supports( $post_type, 'comments' ) ) {
wp_enqueue_script( 'admin-comments' );