Shoora
3/7/2019 - 10:45 AM

Disables Gutenberg

Disables Gutenberg

// Disable Gutenberg

if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) {
	
	// WP > 5 beta
	add_filter('use_block_editor_for_post_type', '__return_false', 100);
	
} else {
	
	// WP < 5 beta
	add_filter('gutenberg_can_edit_post_type', '__return_false');
	
}
/**
 * The meat and potatoes of the Classic Editor plugin that disables Gutenberg and 
 * displays the classic editor for all post types.  If you simply want to disable
 * Gutenberg and not give the user the option of enabling it, the following is all
 * you need.  Tested with WordPress 5.0.2
 *
 * Released under the GPL
 *
 * If you want to allow the user the choice of enabling or disabling Gutenberg, use
 * the official plugin:
 *
 * Classic Editor: https://wordpress.org/plugins/classic-editor/
 */
function disable_gutenberg() {
	$block_editor = has_action( 'enqueue_block_assets' );
	$gutenberg    = function_exists( 'gutenberg_can_edit_post_type' );

	remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );

	if ( ! $block_editor && ! $gutenberg ) {
		return;
	}

	if ( $block_editor ) {
		add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
	}

	add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
	remove_action( 'admin_menu', 'gutenberg_menu' );
	remove_action( 'admin_init', 'gutenberg_redirect_demo' );

	remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
	remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
	remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );

	remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
	remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
	remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
	remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );

	remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save', 1000 );
	remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
	remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
	remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
	remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
	remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
	remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );

	remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
	remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
	remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
	remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
	remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );

	remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
	remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
	remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
	remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' );
	remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
}

/* From a plugin, use the plugins_loaded action */
add_action('plugins_loaded', 'disable_gutenberg');

/* Alternatively from a theme, use the admin_init action */
add_action('admin_init', 'disable_gutenberg');
<?php
/**
 * Plugin Name: Disable Gutenberg
 * Description: Uses filters to disable Gutenberg.
 * Author:      Mark Truitt
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

// Basic security, prevents file from being loaded directly.
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );

 // Disable Gutenberg
add_filter('use_block_editor_for_post', '__return_false');
add_filter('use_block_editor_for_page', '__return_false');