PluginProbe
Classic Editor + / trunk
Classic Editor + vtrunk
4.4.2 trunk 1.4.0 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 3.0.0 3.0.1 3.1.0 4.0.1 4.0.2 4.1.0 4.1.1 4.2.0 4.3.0 All 27 releases
classic-editor-addon / classic-editor-addon.php

classic-editor-addon.php in Classic Editor + trunk, at classic-editor-addon.php

165 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Classic Editor +
4 * Description: The "Classic Editor +" plugin disables the block editor, removes enqueued scripts/styles and brings back classic Widgets.
5
6 * Author: <a href="https://so-wp.com">Pieter Bos</a>, <a href="https://gschoppe.com">Greg Schoppe</a>
7 * Version: 4.4.2
8
9 * Requires at least: 5.5
10 * Tested up to: 7.1
11
12 * License: GPL-3.0+
13 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
14
15 * Text Domain: classic-editor-addon
16
17 * GitHub Plugin URI: https://github.com/senlin/classic-editor-addon
18 * GitHub Branch: master
19
20 * @package WordPress
21 * @author Pieter Bos &amp; GSchoppe
22 * @since 1.0.0
23 */
24
25 // don't load the plugin file directly
26 if ( ! defined( 'ABSPATH' ) ) exit;
27
28 // deactivate Classic Editor plugin
29 add_action( 'admin_init', 'cea_deactivate_ce' );
30 function cea_deactivate_ce() {
31 if ( is_admin() && current_user_can( 'activate_plugins' ) && is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
32
33 deactivate_plugins( 'classic-editor/classic-editor.php' );
34
35 }
36 }
37
38 add_action( 'enqueue_block_assets', 'cea_remove_block_styles', 100 );
39
40 function cea_remove_block_styles() {
41
42 wp_dequeue_style( 'wp-block-library' );
43 wp_deregister_style( 'wp-block-library' );
44
45 wp_dequeue_style( 'wp-block-library-theme' );
46 wp_deregister_style( 'wp-block-library-theme' );
47
48 // Remove inline global CSS on the front end.
49 wp_dequeue_style( 'global-styles' );
50 wp_deregister_style( 'global-styles' );
51
52 // @2.5.0 add condition that checks for WooCommerce and removes call to block styles
53 if ( class_exists( 'woocommerce' ) ) {
54 wp_dequeue_style( 'wc-blocks-style' );
55 wp_dequeue_style( 'wc-all-blocks-style' );
56 wp_dequeue_style( 'wc-blocks-vendors-style' );
57 wp_deregister_style( 'wc-blocks-style' );
58 wp_deregister_style( 'wc-all-blocks-style' );
59 wp_deregister_style( 'wc-blocks-vendors-style' );
60 }
61
62 }
63
64 // Remove global styles and enqueueing of classic-themes.min.css
65 remove_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' );
66 remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
67 remove_action('wp_body_open', 'wp_global_styles_render_svg_filters');
68
69 // Disable Gutenberg on the back end.
70 add_filter( 'use_block_editor_for_post', '__return_false' );
71
72 /**
73 * Bring back Classic Widgets
74 *
75 * @since 3.1.0
76 * @src: https://plugins.svn.wordpress.org/classic-widgets/tags/0.3/classic-widgets.php
77 */
78 // Disable the block editor from managing widgets in the Gutenberg plugin.
79 add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
80 // Disable the block editor from managing widgets.
81 add_filter( 'use_widgets_block_editor', '__return_false' );
82
83 /**
84 * Disable block styling that WPML adds to every page load regardless of whether Blocks are being used.
85 * file that loads these styles: classes/block-editor/Loader.php (L25 & L77-84)
86 */
87 add_action( 'wp_enqueue_scripts', 'cea_disable_wpml_block_styles', 11 );
88
89 function cea_disable_wpml_block_styles() {
90 // Check if WPML is active and the WPML\BlockEditor\Loader class exists
91 if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && class_exists( 'WPML\BlockEditor\Loader' ) ) {
92 wp_deregister_style( WPML\BlockEditor\Loader::SCRIPT_NAME );
93 }
94 }
95
96 /**
97 * Remove Patterns
98 *
99 * @since 4.4.0
100 */
101 if ( ! function_exists( 'cea_restrict_block_editor_patterns' ) ) {
102 /**
103 * Restricts block editor patterns in the editor by removing support for all patterns from:
104 * - Dotcom and plugins like Jetpack
105 * - Dotorg pattern directory except for theme patterns
106 */
107 function cea_restrict_block_editor_patterns( $dispatch_result, $request, $route ) {
108 if ( strpos( $route, '/wp/v2/block-patterns/patterns' ) === 0 ) {
109 $patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
110 if ( ! empty( $patterns ) ) {
111 // Remove theme support for all patterns from Dotcom, and plugins. See https://developer.wordpress.org/themes/features/block-patterns/#unregistering-block-patterns
112 foreach ( $patterns as $pattern ) {
113 unregister_block_pattern( $pattern['name'] );
114 }
115 // Remove theme support for core patterns from the Dotorg pattern directory. See https://developer.wordpress.org/themes/features/block-patterns/#removing-core-patterns
116 remove_theme_support( 'core-block-patterns' );
117 }
118 }
119 return $dispatch_result;
120 }
121 }
122
123
124 // Remove and unregister patterns from core, Dotcom, and plugins. See https://github.com/Automattic/jetpack/blob/d032fbb807e9cd69891e4fcbc0904a05508a1c67/projects/packages/jetpack-mu-wpcom/src/features/block-patterns/block-patterns.php#L107
125 add_filter( 'rest_dispatch_request', 'cea_restrict_block_editor_patterns', 12, 3 );
126
127
128 // Disable the remote patterns coming from the Dotorg pattern directory. See https://developer.wordpress.org/themes/features/block-patterns/#disabling-remote-patterns
129 add_filter( 'should_load_remote_block_patterns', '__return_false' );
130
131 // Hide Patterns menu item from Appearance sidebar menu. See https://wordpress.stackexchange.com/a/426325/180899
132 add_action( 'admin_init', 'cea_hide_wp_patterns_submenu', 100 );
133 function cea_hide_wp_patterns_submenu() {
134 remove_submenu_page( 'themes.php', 'site-editor.php?path=/patterns' );
135 }
136
137 // Block access to Patterns page
138 add_action( 'admin_init', 'cea_restrict_patterns_editor_access' );
139
140 function cea_restrict_patterns_editor_access() {
141 // Get the current URL.
142 $current_url = isset( $_SERVER['REQUEST_URI'] )
143 ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) )
144 : '';
145
146 if ( '' === $current_url ) {
147 return;
148 }
149
150 // List of patterns editor URLs to block.
151 $blocked_urls = array(
152 '/wp-admin/site-editor.php?postType=wp_block',
153 '/wp-admin/site-editor.php?path=/patterns',
154 '/wp-admin/site-editor.php',
155 );
156
157 // Redirect if the current URL matches any of the blocked URLs.
158 foreach ( $blocked_urls as $url ) {
159 if ( false !== strpos( $current_url, $url ) ) {
160 wp_safe_redirect( admin_url() );
161 exit;
162 }
163 }
164 }
165