Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Last active April 19, 2022 13:47
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshuafredrickson/043c8af09f2ff398521188da13d3891d to your computer and use it in GitHub Desktop.
Save joshuafredrickson/043c8af09f2ff398521188da13d3891d to your computer and use it in GitHub Desktop.
Block Editor Cleanup for WordPress 5.9 and Classic Editor (mu-plugin)
<?php
/**
* Plugin Name: Block Editor Cleanup
* Plugin URI: https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1025520487
* Version: 1.0.1
* Description: Remove WP 5.9 default block editor styles when using Classic Editor
* Author: joshuafredrickson
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
add_action('after_setup_theme', function () {
if (! function_exists('is_plugin_active')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Return early if Classic Editor isn't enabled
if (! is_plugin_active('classic-editor/classic-editor.php')) {
return;
}
// Remove SVG and global styles
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
// @link https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1049011521
remove_action('wp_body_open', 'wp_global_styles_render_svg_filters');
// Remove wp_footer actions which add global inline styles
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
// Remove render_block filters which add unnecessary stuff
remove_filter('render_block', 'wp_render_duotone_support');
remove_filter('render_block', 'wp_restore_group_inner_container');
remove_filter('render_block', 'wp_render_layout_support_flag');
});
add_action('wp_enqueue_scripts', function () {
if (! function_exists('is_plugin_active')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if (is_plugin_active('classic-editor/classic-editor.php')) {
// Dequeue block library styles
wp_dequeue_style('wp-block-library');
}
}, 10);
@dalepgrant
Copy link

Getting Call to undefined function is_plugin_active() on a blank Bedrock install, no plugins active, Twenty Twenty-Two or Twenty Twenty-One theme active.

Two potential solutions:

  1. The way WP Core does it.
if (!function_exists('is_plugin_active')) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if (is_plugin_active('classic-editor/classic-editor.php')) {
    // Dequeue block library styles
  1. Riskier as Classic_Editor might be an entirely different class
if (class_exists( 'Classic_Editor')) {
    // Dequeue block library styles

@joshuafredrickson
Copy link
Author

Thank you and updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment