From d158e9bd431e3e801980d9d0511c97e2e770c127 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 16 Nov 2018 12:03:18 -0800 Subject: [PATCH 1/5] Do not override user_can_richedit option --- lib/client-assets.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 7f4acff26619e..e69773ec13b12 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -1419,12 +1419,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) { 'after' ); - // Ignore Classic Editor's `rich_editing` user option, aka "Disable visual - // editor". Forcing this to be true guarantees that TinyMCE and its plugins - // are available in Gutenberg. Fixes - // https://github.com/WordPress/gutenberg/issues/5667. - add_filter( 'user_can_richedit', '__return_true' ); - wp_enqueue_script( 'wp-edit-post' ); wp_enqueue_script( 'wp-format-library' ); wp_enqueue_style( 'wp-format-library' ); From 20190d5404fd2ca215dc308df4c4543b7b16fce8 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 16 Nov 2018 12:03:48 -0800 Subject: [PATCH 2/5] Add checks for user_can_richedit() to show plain-text editor Honors the user setting for `Disable the visual editor when writing` If the user checks the option to disable visual editor: - Returns from Gutenberg init - Removes the links to Classic Editor in post list - Removes the Gutenberg menu item When editing a post, it will load the plain text editor. --- gutenberg.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gutenberg.php b/gutenberg.php index 762707d175574..16ef63d780cbf 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -68,6 +68,9 @@ function the_gutenberg_project() { */ function gutenberg_menu() { global $submenu; + if ( ! user_can_richedit() ) { + return false; + } add_menu_page( 'Gutenberg', @@ -142,6 +145,10 @@ function is_gutenberg_page() { return false; } + if ( ! user_can_richedit() ) { + return false; + } + return true; } @@ -274,6 +281,10 @@ function gutenberg_redirect_demo() { * @since 1.5.0 */ function gutenberg_add_edit_link_filters() { + if ( ! user_can_richedit() ) { + return; + } + // For hierarchical post types. add_filter( 'page_row_actions', 'gutenberg_add_edit_link', 10, 2 ); // For non-hierarchical post types. From eefe33022ea0a593fef5d4a1b033d2a419f27608 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 16 Nov 2018 16:13:22 -0800 Subject: [PATCH 3/5] Update user_can_richedit added to filter Moves the user_can_richedit to attach just on the filters and not spread through out different fucntions. add_filter( 'gutenberg_can_edit_post_type', 'user_can_richedit', 5 ); add_filter( 'gutenberg_can_edit_post', 'user_can_richedit', 5 ); add_filter( 'use_block_editor_for_post', 'user_can_richedit', 5 ); --- gutenberg.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/gutenberg.php b/gutenberg.php index 16ef63d780cbf..fe2c5856fcd5a 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -68,9 +68,6 @@ function the_gutenberg_project() { */ function gutenberg_menu() { global $submenu; - if ( ! user_can_richedit() ) { - return false; - } add_menu_page( 'Gutenberg', @@ -145,10 +142,6 @@ function is_gutenberg_page() { return false; } - if ( ! user_can_richedit() ) { - return false; - } - return true; } @@ -207,6 +200,14 @@ function gutenberg_pre_init() { add_filter( 'replace_editor', 'gutenberg_init', 10, 2 ); } +/** + * Enable Gutenberg based on user_can_richedit setting. + * Set use_block_editor_for_post based on user setting for disable visual editor. + */ +add_filter( 'gutenberg_can_edit_post_type', 'user_can_richedit', 5 ); +add_filter( 'gutenberg_can_edit_post', 'user_can_richedit', 5 ); +add_filter( 'use_block_editor_for_post', 'user_can_richedit', 5 ); + /** * Initialize Gutenberg. * @@ -281,10 +282,6 @@ function gutenberg_redirect_demo() { * @since 1.5.0 */ function gutenberg_add_edit_link_filters() { - if ( ! user_can_richedit() ) { - return; - } - // For hierarchical post types. add_filter( 'page_row_actions', 'gutenberg_add_edit_link', 10, 2 ); // For non-hierarchical post types. From 9fc78bb3a29c89a9861ce5adc9ef4f10b6fcbe02 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 16 Nov 2018 16:20:29 -0800 Subject: [PATCH 4/5] Update with just plugin changes * Don't include core function use_block_editor_for_post * Don't show Gutenberg menu in admin sidebar, since Demo link will not load block editor, still plain text editor --- gutenberg.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gutenberg.php b/gutenberg.php index fe2c5856fcd5a..53c23d9989d30 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -67,6 +67,9 @@ function the_gutenberg_project() { * @since 0.1.0 */ function gutenberg_menu() { + if ( ! gutenberg_can_edit_post( $post ) ) { + return; + } global $submenu; add_menu_page( @@ -206,7 +209,6 @@ function gutenberg_pre_init() { */ add_filter( 'gutenberg_can_edit_post_type', 'user_can_richedit', 5 ); add_filter( 'gutenberg_can_edit_post', 'user_can_richedit', 5 ); -add_filter( 'use_block_editor_for_post', 'user_can_richedit', 5 ); /** * Initialize Gutenberg. From 3ed3609f0a2682b230833e15e12c4bc4c4368e23 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 16 Nov 2018 16:36:29 -0800 Subject: [PATCH 5/5] Fix comment --- gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gutenberg.php b/gutenberg.php index 53c23d9989d30..7ce8db46c2078 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -205,7 +205,7 @@ function gutenberg_pre_init() { /** * Enable Gutenberg based on user_can_richedit setting. - * Set use_block_editor_for_post based on user setting for disable visual editor. + * Set gutenberg_can_edit_post based on user setting for disable visual editor. */ add_filter( 'gutenberg_can_edit_post_type', 'user_can_richedit', 5 ); add_filter( 'gutenberg_can_edit_post', 'user_can_richedit', 5 );