PluginProbe
Disable Gutenberg / 2.4
Disable Gutenberg v2.4
trunk 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.5.2 1.6 1.7 1.8 1.8.1 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.5.1 2.6 2.7 2.8 2.8.1 All 39 releases
disable-gutenberg / disable-gutenberg.php

disable-gutenberg.php in Disable Gutenberg 2.4, at disable-gutenberg.php

239 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Disable Gutenberg
4 Plugin URI: https://perishablepress.com/disable-gutenberg/
5 Description: Disables Gutenberg Block Editor and restores the Classic Editor and original Edit Post screen. Provides options to enable on specific post types, user roles, and more.
6 Tags: editor, classic editor, block editor, block-editor, gutenberg, disable, blocks, posts, post types
7 Author: Jeff Starr
8 Author URI: https://plugin-planet.com/
9 Donate link: https://monzillamedia.com/donate.html
10 Contributors: specialk
11 Requires at least: 4.9
12 Tested up to: 5.7
13 Stable tag: 2.4
14 Version: 2.4
15 Requires PHP: 5.6.20
16 Text Domain: disable-gutenberg
17 Domain Path: /languages
18 License: GPL v2 or later
19 */
20
21 /*
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License
24 as published by the Free Software Foundation; either version
25 2 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 with this program. If not, visit: https://www.gnu.org/licenses/
34
35 Copyright 2021 Monzilla Media. All rights reserved.
36 */
37
38 if (!defined('ABSPATH')) die();
39
40 if (!class_exists('DisableGutenberg')) {
41
42 class DisableGutenberg {
43
44 function __construct() {
45
46 $this->constants();
47 $this->includes();
48
49 add_action('admin_init', array($this, 'check_version'));
50 add_action('plugins_loaded', array($this, 'load_i18n'));
51 add_filter('plugin_action_links', array($this, 'action_links'), 10, 2);
52 add_filter('plugin_row_meta', array($this, 'plugin_links'), 10, 2);
53
54 add_action('admin_enqueue_scripts', 'disable_gutenberg_admin_enqueue_scripts');
55 add_action('admin_print_scripts', 'disable_gutenberg_admin_print_scripts');
56 add_action('admin_notices', 'disable_gutenberg_admin_notice');
57 add_action('admin_init', 'disable_gutenberg_register_settings');
58 add_action('admin_init', 'disable_gutenberg_reset_options');
59 add_action('admin_menu', 'disable_gutenberg_menu_pages');
60 add_action('admin_menu', 'disable_gutenberg_menu_items', 999);
61 add_action('admin_init', 'disable_gutenberg_acf_enable_meta');
62 add_action('admin_init', 'disable_gutenberg_privacy_notice');
63 add_filter('admin_init', 'disable_gutenberg_disable_nag');
64 add_filter('admin_init', 'disable_gutenberg_init');
65
66 add_filter('wp_enqueue_scripts', 'disable_gutenberg_wp_enqueue_scripts', 100);
67
68 }
69
70 function constants() {
71
72 if (!defined('DISABLE_GUTENBERG_VERSION')) define('DISABLE_GUTENBERG_VERSION', '2.4');
73 if (!defined('DISABLE_GUTENBERG_REQUIRE')) define('DISABLE_GUTENBERG_REQUIRE', '4.9');
74 if (!defined('DISABLE_GUTENBERG_AUTHOR')) define('DISABLE_GUTENBERG_AUTHOR', 'Jeff Starr');
75 if (!defined('DISABLE_GUTENBERG_NAME')) define('DISABLE_GUTENBERG_NAME', __('Disable Gutenberg', 'disable-gutenberg'));
76 if (!defined('DISABLE_GUTENBERG_HOME')) define('DISABLE_GUTENBERG_HOME', esc_url('https://perishablepress.com/disable-gutenberg/'));
77 if (!defined('DISABLE_GUTENBERG_URL')) define('DISABLE_GUTENBERG_URL', plugin_dir_url(__FILE__));
78 if (!defined('DISABLE_GUTENBERG_DIR')) define('DISABLE_GUTENBERG_DIR', plugin_dir_path(__FILE__));
79 if (!defined('DISABLE_GUTENBERG_FILE')) define('DISABLE_GUTENBERG_FILE', plugin_basename(__FILE__));
80 if (!defined('DISABLE_GUTENBERG_SLUG')) define('DISABLE_GUTENBERG_SLUG', basename(dirname(__FILE__)));
81
82 }
83
84 function includes() {
85
86 require_once DISABLE_GUTENBERG_DIR .'inc/classic-editor.php';
87 require_once DISABLE_GUTENBERG_DIR .'inc/plugin-core.php';
88 require_once DISABLE_GUTENBERG_DIR .'inc/plugin-frontend.php';
89
90 if (is_admin()) {
91
92 require_once DISABLE_GUTENBERG_DIR .'inc/resources-enqueue.php';
93 require_once DISABLE_GUTENBERG_DIR .'inc/settings-display.php';
94 require_once DISABLE_GUTENBERG_DIR .'inc/settings-register.php';
95 require_once DISABLE_GUTENBERG_DIR .'inc/settings-reset.php';
96
97 if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) {
98
99 require_once DISABLE_GUTENBERG_DIR .'inc/plugin-features.php';
100
101 }
102
103 }
104
105 }
106
107 function options() {
108
109 $options = array(
110
111 'disable-all' => 1,
112 'disable-nag' => 1,
113 'hide-menu' => 0,
114 'hide-gut' => 0,
115 'templates' => '',
116 'post-ids' => '',
117 'acf-enable' => 0,
118 'links-enable' => 0,
119 'whitelist-id' => '',
120 'whitelist-slug' => '',
121 'whitelist-title' => '',
122 'whitelist' => 0,
123 'styles-enable' => 0,
124
125 );
126
127 $types = disable_gutenberg_get_post_types();
128
129 foreach($types as $type) {
130
131 extract($type); // name label
132
133 $options['post-type_'. $name] = 1;
134
135 }
136
137 $roles = disable_gutenberg_get_user_roles();
138
139 foreach($roles as $type) {
140
141 extract($type); // name label
142
143 $options['user-role_'. $name] = 1;
144
145 }
146
147 return apply_filters('disable_gutenberg_options', $options);
148
149 }
150
151 function action_links($links, $file) {
152
153 if (($file === DISABLE_GUTENBERG_FILE) && (current_user_can('manage_options'))) {
154
155 $settings = '<a href="'. admin_url('options-general.php?page=disable-gutenberg') .'">'. esc_html__('Settings', 'disable-gutenberg') .'</a>';
156
157 array_unshift($links, $settings);
158
159 }
160
161 return $links;
162
163 }
164
165 function plugin_links($links, $file) {
166
167 if ($file === DISABLE_GUTENBERG_FILE) {
168
169 $home_href = 'https://perishablepress.com/disable-gutenberg/';
170 $home_title = esc_attr__('Plugin Homepage', 'disable-gutenberg');
171 $home_text = esc_html__('Homepage', 'disable-gutenberg');
172
173 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
174
175 $rate_href = 'https://wordpress.org/support/plugin/'. DISABLE_GUTENBERG_SLUG .'/reviews/?rate=5#new-post';
176 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'disable-gutenberg');
177 $rate_text = esc_html__('Rate this plugin', 'disable-gutenberg') .'&nbsp;&raquo;';
178
179 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
180
181 }
182
183 return $links;
184
185 }
186
187 function check_version() {
188
189 $wp_version = get_bloginfo('version');
190
191 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
192
193 if (version_compare($wp_version, DISABLE_GUTENBERG_REQUIRE, '<')) {
194
195 if (is_plugin_active(DISABLE_GUTENBERG_FILE)) {
196
197 deactivate_plugins(DISABLE_GUTENBERG_FILE);
198
199 $msg = '<strong>'. DISABLE_GUTENBERG_NAME .'</strong> '. esc_html__('requires WordPress ', 'disable-gutenberg') . DISABLE_GUTENBERG_REQUIRE;
200 $msg .= esc_html__(' or higher, and has been deactivated! ', 'disable-gutenberg');
201 $msg .= esc_html__('Please return to the', 'disable-gutenberg') .' <a href="'. admin_url() .'">';
202 $msg .= esc_html__('WP Admin Area', 'disable-gutenberg') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'disable-gutenberg');
203
204 wp_die($msg);
205
206 }
207
208 }
209
210 }
211
212 }
213
214 function load_i18n() {
215
216 load_plugin_textdomain('disable-gutenberg', false, DISABLE_GUTENBERG_DIR .'languages/');
217
218 }
219
220 function __clone() {
221
222 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'disable-gutenberg'), DISABLE_GUTENBERG_VERSION);
223
224 }
225
226 function __wakeup() {
227
228 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'disable-gutenberg'), DISABLE_GUTENBERG_VERSION);
229
230 }
231
232 }
233
234 global $DisableGutenberg;
235
236 $DisableGutenberg = new DisableGutenberg();
237
238 }
239