Skip to content

Commit

Permalink
Honor the Disable Visual Editor setting (#12000)
Browse files Browse the repository at this point in the history
* Do not override user_can_richedit option

* 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.

* 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 );

* 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

* Fix comment
  • Loading branch information
mkaz authored and gziolo committed Nov 19, 2018
1 parent 8585f15 commit 095d18f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 10 additions & 0 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -200,6 +203,13 @@ function gutenberg_pre_init() {
add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
}

/**
* Enable Gutenberg based on user_can_richedit setting.
* 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 );

/**
* Initialize Gutenberg.
*
Expand Down
6 changes: 0 additions & 6 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,12 +1020,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' );
Expand Down

0 comments on commit 095d18f

Please sign in to comment.