PluginProbe
Disable Gutenberg / 2.5
Disable Gutenberg v2.5
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.5, at disable-gutenberg.php

240 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.8
13 Stable tag: 2.5
14 Version: 2.5
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.5');
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 'classic-widgets' => 0,
125
126 );
127
128 $types = disable_gutenberg_get_post_types();
129
130 foreach($types as $type) {
131
132 extract($type); // name label
133
134 $options['post-type_'. $name] = 1;
135
136 }
137
138 $roles = disable_gutenberg_get_user_roles();
139
140 foreach($roles as $type) {
141
142 extract($type); // name label
143
144 $options['user-role_'. $name] = 1;
145
146 }
147
148 return apply_filters('disable_gutenberg_options', $options);
149
150 }
151
152 function action_links($links, $file) {
153
154 if (($file === DISABLE_GUTENBERG_FILE) && (current_user_can('manage_options'))) {
155
156 $settings = '<a href="'. admin_url('options-general.php?page=disable-gutenberg') .'">'. esc_html__('Settings', 'disable-gutenberg') .'</a>';
157
158 array_unshift($links, $settings);
159
160 }
161
162 return $links;
163
164 }
165
166 function plugin_links($links, $file) {
167
168 if ($file === DISABLE_GUTENBERG_FILE) {
169
170 $home_href = 'https://perishablepress.com/disable-gutenberg/';
171 $home_title = esc_attr__('Plugin Homepage', 'disable-gutenberg');
172 $home_text = esc_html__('Homepage', 'disable-gutenberg');
173
174 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
175
176 $rate_href = 'https://wordpress.org/support/plugin/'. DISABLE_GUTENBERG_SLUG .'/reviews/?rate=5#new-post';
177 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'disable-gutenberg');
178 $rate_text = esc_html__('Rate this plugin', 'disable-gutenberg') .'&nbsp;&raquo;';
179
180 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
181
182 }
183
184 return $links;
185
186 }
187
188 function check_version() {
189
190 $wp_version = get_bloginfo('version');
191
192 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
193
194 if (version_compare($wp_version, DISABLE_GUTENBERG_REQUIRE, '<')) {
195
196 if (is_plugin_active(DISABLE_GUTENBERG_FILE)) {
197
198 deactivate_plugins(DISABLE_GUTENBERG_FILE);
199
200 $msg = '<strong>'. DISABLE_GUTENBERG_NAME .'</strong> '. esc_html__('requires WordPress ', 'disable-gutenberg') . DISABLE_GUTENBERG_REQUIRE;
201 $msg .= esc_html__(' or higher, and has been deactivated! ', 'disable-gutenberg');
202 $msg .= esc_html__('Please return to the', 'disable-gutenberg') .' <a href="'. admin_url() .'">';
203 $msg .= esc_html__('WP Admin Area', 'disable-gutenberg') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'disable-gutenberg');
204
205 wp_die($msg);
206
207 }
208
209 }
210
211 }
212
213 }
214
215 function load_i18n() {
216
217 load_plugin_textdomain('disable-gutenberg', false, DISABLE_GUTENBERG_DIR .'languages/');
218
219 }
220
221 function __clone() {
222
223 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'disable-gutenberg'), DISABLE_GUTENBERG_VERSION);
224
225 }
226
227 function __wakeup() {
228
229 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'disable-gutenberg'), DISABLE_GUTENBERG_VERSION);
230
231 }
232
233 }
234
235 global $DisableGutenberg;
236
237 $DisableGutenberg = new DisableGutenberg();
238
239 }
240