Disable Gutenberg - Version 1.4

Version Description

To upgrade this plugin, remove the old version and replace with the new version. Or just click "Update" from the Plugins screen and let WordPress do it for you automatically.

Note: uninstalling the plugin from the WP Plugins screen results in the removal of all settings and data from the WP database.

Download this release

Release Info

Developer specialk
Plugin Icon 128x128 Disable Gutenberg
Version 1.4
Comparing to
See all releases

Code changes from version 1.3.1 to 1.4

disable-gutenberg.php CHANGED
@@ -2,16 +2,16 @@
2
  /*
3
  Plugin Name: Disable Gutenberg
4
  Plugin URI: https://perishablepress.com/disable-gutenberg/
5
- Description: Disables Gutenberg and restores the Classic Editor and original Edit Post screen. Provides options to enable on specific post types, user roles, and more.
6
- Tags: gutenberg, disable, post types, g7g
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.5
12
  Tested up to: 5.0
13
- Stable tag: 1.3.1
14
- Version: 1.3.1
15
  Requires PHP: 5.2
16
  Text Domain: disable-gutenberg
17
  Domain Path: /languages
@@ -51,13 +51,6 @@ if (!class_exists('DisableGutenberg')) {
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_filter('page_row_actions', 'disable_gutenberg_page_row_actions', 15, 2);
55
- // add_filter('post_row_actions', 'disable_gutenberg_page_row_actions', 15, 2);
56
- // add_filter('get_edit_post_link', 'disable_gutenberg_get_edit_post_link');
57
- // add_filter('redirect_post_location', 'disable_gutenberg_redirect_post_location');
58
- // add_action('edit_form_top', 'disable_gutenberg_edit_form_top');
59
- // add_action('admin_menu', 'disable_gutenberg_add_submenus');
60
-
61
  add_action('admin_enqueue_scripts', 'disable_gutenberg_enqueue_resources_admin');
62
  add_action('admin_print_scripts', 'disable_gutenberg_print_js_vars_admin');
63
  add_action('admin_notices', 'disable_gutenberg_admin_notice');
@@ -66,14 +59,13 @@ if (!class_exists('DisableGutenberg')) {
66
  add_action('admin_menu', 'disable_gutenberg_menu_pages');
67
  add_action('admin_menu', 'disable_gutenberg_menu_items', 999);
68
  add_filter('admin_init', 'disable_gutenberg_disable_nag');
69
-
70
- add_filter('use_block_editor_for_post_type', 'disable_gutenberg_init', 10, 2);
71
 
72
  }
73
 
74
  function constants() {
75
 
76
- if (!defined('DISABLE_GUTENBERG_VERSION')) define('DISABLE_GUTENBERG_VERSION', '1.3.1');
77
  if (!defined('DISABLE_GUTENBERG_REQUIRE')) define('DISABLE_GUTENBERG_REQUIRE', '4.5');
78
  if (!defined('DISABLE_GUTENBERG_AUTHOR')) define('DISABLE_GUTENBERG_AUTHOR', 'Jeff Starr');
79
  if (!defined('DISABLE_GUTENBERG_NAME')) define('DISABLE_GUTENBERG_NAME', __('Disable Gutenberg', 'disable-gutenberg'));
@@ -87,16 +79,22 @@ if (!class_exists('DisableGutenberg')) {
87
 
88
  function includes() {
89
 
90
- require_once DISABLE_GUTENBERG_DIR .'inc/classic-editor.php';
91
-
92
  if (is_admin()) {
93
 
 
 
94
  require_once DISABLE_GUTENBERG_DIR .'inc/plugin-core.php';
95
  require_once DISABLE_GUTENBERG_DIR .'inc/resources-enqueue.php';
96
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-display.php';
97
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-register.php';
98
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-reset.php';
99
 
 
 
 
 
 
 
100
  }
101
 
102
  }
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: gutenberg, block editor, block-editor, disable, blocks, 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.5
12
  Tested up to: 5.0
13
+ Stable tag: 1.4
14
+ Version: 1.4
15
  Requires PHP: 5.2
16
  Text Domain: disable-gutenberg
17
  Domain Path: /languages
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_enqueue_resources_admin');
55
  add_action('admin_print_scripts', 'disable_gutenberg_print_js_vars_admin');
56
  add_action('admin_notices', 'disable_gutenberg_admin_notice');
59
  add_action('admin_menu', 'disable_gutenberg_menu_pages');
60
  add_action('admin_menu', 'disable_gutenberg_menu_items', 999);
61
  add_filter('admin_init', 'disable_gutenberg_disable_nag');
62
+ add_filter('admin_init', 'disable_gutenberg_init');
 
63
 
64
  }
65
 
66
  function constants() {
67
 
68
+ if (!defined('DISABLE_GUTENBERG_VERSION')) define('DISABLE_GUTENBERG_VERSION', '1.4');
69
  if (!defined('DISABLE_GUTENBERG_REQUIRE')) define('DISABLE_GUTENBERG_REQUIRE', '4.5');
70
  if (!defined('DISABLE_GUTENBERG_AUTHOR')) define('DISABLE_GUTENBERG_AUTHOR', 'Jeff Starr');
71
  if (!defined('DISABLE_GUTENBERG_NAME')) define('DISABLE_GUTENBERG_NAME', __('Disable Gutenberg', 'disable-gutenberg'));
79
 
80
  function includes() {
81
 
 
 
82
  if (is_admin()) {
83
 
84
+ require_once DISABLE_GUTENBERG_DIR .'inc/classic-editor.php';
85
+
86
  require_once DISABLE_GUTENBERG_DIR .'inc/plugin-core.php';
87
  require_once DISABLE_GUTENBERG_DIR .'inc/resources-enqueue.php';
88
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-display.php';
89
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-register.php';
90
  require_once DISABLE_GUTENBERG_DIR .'inc/settings-reset.php';
91
 
92
+ if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) {
93
+
94
+ require_once DISABLE_GUTENBERG_DIR .'inc/plugin-features.php';
95
+
96
+ }
97
+
98
  }
99
 
100
  }
inc/classic-editor.php CHANGED
@@ -6,77 +6,103 @@ if (!defined('ABSPATH')) exit;
6
 
7
  function disable_gutenberg_remove() {
8
 
9
- // gutenberg.php
10
- remove_action('admin_menu', 'gutenberg_menu');
11
- remove_action('admin_notices', 'gutenberg_build_files_notice');
12
- remove_action('admin_notices', 'gutenberg_wordpress_version_notice');
13
- remove_action('admin_init', 'gutenberg_redirect_demo');
14
- remove_action('admin_init', 'gutenberg_add_edit_link_filters');
15
- remove_action('admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button');
16
-
17
- remove_filter('replace_editor', 'gutenberg_init');
18
- remove_filter('body_class', 'gutenberg_add_responsive_body_class');
19
- remove_filter('admin_url', 'gutenberg_modify_add_new_button_url');
20
-
21
- // Keep
22
- // remove_filter('wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2); // not needed in 5.0
23
- // remove_filter('bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions');
24
-
25
- // lib/client-assets.php
26
- remove_action('wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5);
27
- remove_action('admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5);
28
- remove_action('wp_enqueue_scripts', 'gutenberg_common_scripts_and_styles');
29
- remove_action('admin_enqueue_scripts', 'gutenberg_common_scripts_and_styles');
30
-
31
- // lib/compat.php
32
- remove_filter('wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers');
33
-
34
- // lib/plugin-compat.php
35
- remove_filter('rest_pre_insert_post', 'gutenberg_remove_wpcom_markdown_support');
36
-
37
- // lib/register.php
38
- remove_action('edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts');
39
-
40
- remove_filter('redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts');
41
- remove_filter('get_edit_post_link', 'gutenberg_revisions_link_to_editor');
42
- remove_filter('wp_prepare_revision_for_js', 'gutenberg_revisions_restore');
43
- remove_filter('display_post_states', 'gutenberg_add_gutenberg_post_state');
44
-
45
- // lib/rest-api.php
46
- remove_action('rest_api_init', 'gutenberg_register_rest_routes');
47
- remove_action('rest_api_init', 'gutenberg_add_taxonomy_visibility_field');
48
-
49
- remove_filter('rest_request_after_callbacks', 'gutenberg_filter_oembed_result');
50
- remove_filter('registered_post_type', 'gutenberg_register_post_prepare_functions');
51
- remove_filter('register_post_type_args', 'gutenberg_filter_post_type_labels');
52
-
53
- // lib/meta-box-partial-page.php
54
- remove_action('do_meta_boxes', 'gutenberg_meta_box_save', 1000);
55
- remove_action('submitpost_box', 'gutenberg_intercept_meta_box_render');
56
- remove_action('submitpage_box', 'gutenberg_intercept_meta_box_render');
57
- remove_action('edit_page_form', 'gutenberg_intercept_meta_box_render');
58
- remove_action('edit_form_advanced', 'gutenberg_intercept_meta_box_render');
59
-
60
- remove_filter('redirect_post_location', 'gutenberg_meta_box_save_redirect');
61
- remove_filter('filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes');
62
-
63
- // add_filter('replace_editor', 'disable_gutenberg_replace');
64
-
65
- // lib/compat.php
66
- remove_action('admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks');
67
-
68
- // Keep
69
- // lib/blocks.php
70
- // remove_filter('the_content', 'do_blocks', 9);
71
-
72
- // Continue to disable wpautop inside TinyMCE for posts that were started in Gutenberg
73
- // remove_filter('wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop');
74
-
75
- // Keep the tweaks to the PHP wpautop
76
- // add_filter('the_content', 'wpautop');
77
- // remove_filter('the_content', 'gutenberg_wpautop', 8);
78
-
79
- // remove_action('init', 'gutenberg_register_post_types');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  }
82
 
@@ -85,8 +111,8 @@ function disable_gutenberg_replace($return) {
85
  if (true === $return) return $return;
86
 
87
  $suffix = SCRIPT_DEBUG ? '' : '.min';
88
- $js_url = plugin_dir_url(__FILE__) . 'js/';
89
- $css_url = plugin_dir_url(__FILE__) . 'css/';
90
 
91
  // Enqueued conditionally from legacy-edit-form-advanced.php
92
  wp_register_script('editor-expand', $js_url . "editor-expand$suffix.js", array('jquery', 'underscore'), false, 1);
@@ -145,7 +171,7 @@ function disable_gutenberg_replace($return) {
145
  // wp_enqueue_script('admin-comments') is a dependency for 'dashboard', also used in edit-comments.php.
146
  // wp_enqueue_script('image-edit') and wp_enqueue_style('imgareaselect') are also used in media.php and media-upload.php.
147
 
148
- include_once(DISABLE_GUTENBERG_DIR . 'lib/classic-editor/classic-edit-form-advanced.php');
149
 
150
  return true;
151
 
6
 
7
  function disable_gutenberg_remove() {
8
 
9
+ $gutenberg = false;
10
+
11
+ $block_editor = false;
12
+
13
+ if (has_filter('replace_editor', 'gutenberg_init')) $gutenberg = true;
14
+
15
+ if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) $block_editor = true;
16
+
17
+ if (!$gutenberg && !$block_editor) return;
18
+
19
+ if ($block_editor) {
20
+
21
+ add_filter('use_block_editor_for_post_type', '__return_false', 100);
22
+
23
+ }
24
+
25
+ if ($gutenberg) {
26
+
27
+ // gutenberg.php
28
+ remove_action('admin_menu', 'gutenberg_menu');
29
+ remove_action('admin_notices', 'gutenberg_build_files_notice');
30
+ remove_action('admin_notices', 'gutenberg_wordpress_version_notice');
31
+ remove_action('admin_init', 'gutenberg_redirect_demo');
32
+
33
+ remove_filter('replace_editor', 'gutenberg_init');
34
+
35
+ // lib/client-assets.php
36
+ remove_action('wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5);
37
+ remove_action('admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles', 5);
38
+ remove_action('wp_enqueue_scripts', 'gutenberg_common_scripts_and_styles');
39
+ remove_action('admin_enqueue_scripts', 'gutenberg_common_scripts_and_styles');
40
+
41
+ // lib/compat.php
42
+ remove_filter('wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers');
43
+
44
+ // lib/rest-api.php
45
+ remove_action('rest_api_init', 'gutenberg_register_rest_routes');
46
+ remove_action('rest_api_init', 'gutenberg_add_taxonomy_visibility_field');
47
+
48
+ remove_filter('rest_request_after_callbacks', 'gutenberg_filter_oembed_result');
49
+ remove_filter('registered_post_type', 'gutenberg_register_post_prepare_functions');
50
+ remove_filter('register_post_type_args', 'gutenberg_filter_post_type_labels');
51
+
52
+ // lib/meta-box-partial-page.php
53
+ remove_action('do_meta_boxes', 'gutenberg_meta_box_save', 1000);
54
+ remove_action('submitpost_box', 'gutenberg_intercept_meta_box_render');
55
+ remove_action('submitpage_box', 'gutenberg_intercept_meta_box_render');
56
+ remove_action('edit_page_form', 'gutenberg_intercept_meta_box_render');
57
+ remove_action('edit_form_advanced', 'gutenberg_intercept_meta_box_render');
58
+
59
+ remove_filter('redirect_post_location', 'gutenberg_meta_box_save_redirect');
60
+ remove_filter('filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes');
61
+
62
+ // add_filter('replace_editor', 'disable_gutenberg_replace');
63
+
64
+ //
65
+
66
+ // gutenberg.php
67
+ remove_action('admin_init', 'gutenberg_add_edit_link_filters');
68
+ remove_action('admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button');
69
+
70
+ remove_filter('body_class', 'gutenberg_add_responsive_body_class');
71
+ remove_filter('admin_url', 'gutenberg_modify_add_new_button_url');
72
+
73
+ // Keep
74
+ // remove_filter('wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2); // not needed in 5.0
75
+ // remove_filter('bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions');
76
+
77
+ // lib/compat.php
78
+ remove_action('admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks');
79
+
80
+ // lib/register.php
81
+ remove_action('edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts');
82
+
83
+ remove_filter('redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts');
84
+ remove_filter('get_edit_post_link', 'gutenberg_revisions_link_to_editor');
85
+ remove_filter('wp_prepare_revision_for_js', 'gutenberg_revisions_restore');
86
+ remove_filter('display_post_states', 'gutenberg_add_gutenberg_post_state');
87
+
88
+ // lib/plugin-compat.php
89
+ remove_filter('rest_pre_insert_post', 'gutenberg_remove_wpcom_markdown_support');
90
+
91
+ // Keep
92
+
93
+ // lib/blocks.php
94
+ // remove_filter('the_content', 'do_blocks', 9);
95
+
96
+ // Continue to disable wpautop inside TinyMCE for posts that were started in Gutenberg.
97
+ // remove_filter('wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop');
98
+
99
+ // Keep the tweaks to the PHP wpautop.
100
+ // add_filter('the_content', 'wpautop');
101
+ // remove_filter('the_content', 'gutenberg_wpautop', 8);
102
+
103
+ // remove_action('init', 'gutenberg_register_post_types');
104
+
105
+ }
106
 
107
  }
108
 
111
  if (true === $return) return $return;
112
 
113
  $suffix = SCRIPT_DEBUG ? '' : '.min';
114
+ $js_url = DISABLE_GUTENBERG_URL .'lib/classic-editor/js/';
115
+ $css_url = DISABLE_GUTENBERG_URL .'lib/classic-editor/css/';
116
 
117
  // Enqueued conditionally from legacy-edit-form-advanced.php
118
  wp_register_script('editor-expand', $js_url . "editor-expand$suffix.js", array('jquery', 'underscore'), false, 1);
171
  // wp_enqueue_script('admin-comments') is a dependency for 'dashboard', also used in edit-comments.php.
172
  // wp_enqueue_script('image-edit') and wp_enqueue_style('imgareaselect') are also used in media.php and media-upload.php.
173
 
174
+ include_once(DISABLE_GUTENBERG_DIR .'lib/classic-editor/classic-edit-form-advanced.php');
175
 
176
  return true;
177
 
inc/plugin-core.php CHANGED
@@ -2,47 +2,27 @@
2
 
3
  if (!defined('ABSPATH')) exit;
4
 
5
- function disable_gutenberg_init($is_enabled, $post_type) {
6
 
7
- if (disable_gutenberg($is_enabled, $post_type)) {
8
-
9
- disable_gutenberg_remove();
10
-
11
- return false;
12
-
13
- }
14
-
15
- return $is_enabled;
16
 
17
  }
18
 
19
- function disable_gutenberg($is_enabled, $post_type) {
20
 
21
- if (!$is_enabled) return false;
22
 
23
  if (isset($_GET['classic-editor'])) return true;
24
 
25
- $options = disable_gutenberg_get_options();
26
 
27
- $disable_all = (isset($options['disable-all']) && !empty($options['disable-all'])) ? true : false;
28
 
29
- if ($disable_all) return true;
30
 
31
- foreach (disable_gutenberg_get_enabled_post_types() as $type) {
32
-
33
- if ($post_type === $type) return true;
34
-
35
- }
36
 
37
- foreach (disable_gutenberg_get_enabled_user_roles() as $role) {
38
-
39
- $roles = disable_gutenberg_get_current_user_roles();
40
-
41
- if (is_array($roles) && in_array($role, $roles)) return true;
42
-
43
- }
44
-
45
- if (disable_gutenberg_disable_templates() || disable_gutenberg_disable_ids()) return true;
46
 
47
  return false;
48
 
@@ -64,6 +44,8 @@ function disable_gutenberg_get_current_user_roles($user = null) {
64
 
65
  function disable_gutenberg_get_user_roles() {
66
 
 
 
67
  $roles = get_editable_roles();
68
 
69
  $types = array();
@@ -140,6 +122,74 @@ function disable_gutenberg_get_enabled_post_types() {
140
 
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  function disable_gutenberg_disable_templates() {
144
 
145
  $excluded = array();
@@ -213,206 +263,3 @@ function disable_gutenberg_menu_items() {
213
  if ($hide_gutenberg) remove_menu_page('gutenberg');
214
 
215
  }
216
-
217
- function disable_gutenberg_is_gutenberg_active() {
218
-
219
- $gutenberg = has_filter('replace_editor', 'gutenberg_init') ? true : false;
220
-
221
- $block_editor = version_compare($GLOBALS['wp_version'], '5.0-beta', '>') ? true : false;
222
-
223
- if ($gutenberg || $block_editor) return true;
224
-
225
- return false;
226
-
227
- }
228
-
229
- function disable_gutenberg_post_or_page() {
230
-
231
- global $pagenow;
232
-
233
- $type = null;
234
-
235
- if ($pagenow === 'edit.php') {
236
-
237
- if (!isset($_GET['post_type'])) {
238
-
239
- $type = 'post'; // posts @ edit.php
240
-
241
- } elseif (isset($_GET['post_type']) && $_GET['post_type'] === 'page') {
242
-
243
- $type = 'page'; // pages @ edit.php?post_type=page
244
-
245
- }
246
-
247
- } elseif ($pagenow === 'post.php' && isset($_GET['post'])) {
248
-
249
- $post_type = get_post_type($_GET['post']);
250
-
251
- if ($post_type === 'post') {
252
-
253
- $type = 'post'; // post.php?post=1&action=edit
254
-
255
- } elseif ($post_type === 'page') {
256
-
257
- $type = 'page'; // post.php?post=1&action=edit
258
-
259
- }
260
-
261
- } elseif ($pagenow === 'post-new.php') {
262
-
263
- if (!isset($_GET['post_type'])) {
264
-
265
- $type = 'post'; // post-new.php
266
-
267
- } elseif (isset($_GET['post_type']) && $_GET['post_type'] === 'page') {
268
-
269
- $type = 'page'; // post-new.php?post_type=page
270
-
271
- }
272
-
273
- }
274
-
275
- return $type;
276
-
277
- }
278
-
279
-
280
-
281
- // THANKS to Classic Editor for next several functions
282
- // NOTE: these functions are disabled until further notice
283
-
284
- function disable_gutenberg_add_submenus() {
285
-
286
- $post_type = disable_gutenberg_post_or_page();
287
-
288
- $is_active = disable_gutenberg_is_gutenberg_active();
289
-
290
- $disable = ($post_type) ? disable_gutenberg($is_active, $post_type) : false;
291
-
292
- if ($disable && version_compare(get_bloginfo('version'), '5.0-beta', '>')) return;
293
-
294
- foreach (get_post_types(array('show_ui' => true)) as $type) {
295
-
296
- $type_obj = get_post_type_object($type);
297
-
298
- if (!$type_obj->show_in_menu || !post_type_supports($type, 'editor')) continue;
299
-
300
- if ($type_obj->show_in_menu === true) {
301
-
302
- if ('post' === $type) {
303
-
304
- $parent_slug = 'edit.php';
305
-
306
- } elseif ('page' === $type) {
307
-
308
- $parent_slug = 'edit.php?post_type=page';
309
-
310
- } else {
311
-
312
- continue;
313
-
314
- }
315
-
316
- } else {
317
-
318
- $parent_slug = $type_obj->show_in_menu;
319
-
320
- }
321
-
322
- $item_name = $type_obj->labels->add_new .' '. __('(Classic)', 'disable-gutenberg');
323
-
324
- add_submenu_page($parent_slug, $type_obj->labels->add_new, $item_name, $type_obj->cap->edit_posts, 'post-new.php?post_type='. $type .'&classic-editor');
325
-
326
- }
327
-
328
- }
329
-
330
- function disable_gutenberg_page_row_actions($actions, $post) {
331
-
332
- $is_active = disable_gutenberg_is_gutenberg_active();
333
-
334
- if (disable_gutenberg($is_active, $post->post_type)) return $actions;
335
-
336
- if (!$is_active || array_key_exists('classic', $actions)) return $actions;
337
-
338
- if ('trash' === $post->post_status || !post_type_supports($post->post_type, 'editor')) return $actions;
339
-
340
- $edit_url = get_edit_post_link($post->ID, 'raw');
341
-
342
- if (!$edit_url) return $actions;
343
-
344
- $edit_url = add_query_arg('classic-editor', '', $edit_url);
345
-
346
- $title = _draft_or_post_title($post->ID);
347
-
348
- $edit_action = array(
349
-
350
- 'classic' => sprintf(
351
-
352
- '<a href="%s" aria-label="%s">%s</a>',
353
-
354
- esc_url($edit_url),
355
-
356
- esc_attr(sprintf(
357
-
358
- __('Edit &#8220;%s&#8221; with Classic Editor', 'disable-gutenberg'),
359
-
360
- $title
361
-
362
- )),
363
-
364
- __('Edit (Classic)', 'disable-gutenberg')
365
-
366
- ),
367
-
368
- );
369
-
370
- $edit_offset = array_search('edit', array_keys($actions), true);
371
-
372
- array_splice($actions, $edit_offset + 1, 0, $edit_action);
373
-
374
- return $actions;
375
-
376
- }
377
-
378
- function disable_gutenberg_get_edit_post_link($url) {
379
-
380
- global $current_screen;
381
-
382
- if (!isset($_REQUEST['classic-editor']) && !disable_gutenberg(disable_gutenberg_is_gutenberg_active(), $current_screen->post_type)) return $url;
383
-
384
- $url = add_query_arg('classic-editor', '', $url);
385
-
386
- return $url;
387
-
388
- }
389
-
390
- function disable_gutenberg_redirect_post_location($location) {
391
-
392
- global $current_screen;
393
-
394
- if (!isset($_REQUEST['classic-editor']) && !disable_gutenberg(disable_gutenberg_is_gutenberg_active(), $current_screen->post_type)) return $location;
395
-
396
- if (isset($_REQUEST['classic-editor']) || (isset($_POST['_wp_http_referer']) && strpos($_POST['_wp_http_referer'], '&classic-editor') !== false)) {
397
-
398
- $location = add_query_arg('classic-editor', '', $location);
399
-
400
- }
401
-
402
- return $location;
403
-
404
- }
405
-
406
- function disable_gutenberg_edit_form_top() {
407
-
408
- global $current_screen;
409
-
410
- if (!isset($_GET['classic-editor']) && !disable_gutenberg(disable_gutenberg_is_gutenberg_active(), $current_screen->post_type)) return;
411
-
412
- ?>
413
-
414
- <input type="hidden" name="classic-editor" value="" />
415
-
416
- <?php
417
-
418
- }
2
 
3
  if (!defined('ABSPATH')) exit;
4
 
5
+ function disable_gutenberg_init() {
6
 
7
+ if (disable_gutenberg()) disable_gutenberg_remove();
 
 
 
 
 
 
 
 
8
 
9
  }
10
 
11
+ function disable_gutenberg() {
12
 
13
+ if (is_plugin_active('classic-editor/classic-editor.php')) return false;
14
 
15
  if (isset($_GET['classic-editor'])) return true;
16
 
17
+ if (disable_gutenberg_disable_all()) return true;
18
 
19
+ if (disable_gutenberg_disable_user_role()) return true;
20
 
21
+ if (disable_gutenberg_disable_post_type()) return true;
22
 
23
+ if (disable_gutenberg_disable_templates()) return true;
 
 
 
 
24
 
25
+ if (disable_gutenberg_disable_ids()) return true;
 
 
 
 
 
 
 
 
26
 
27
  return false;
28
 
44
 
45
  function disable_gutenberg_get_user_roles() {
46
 
47
+ if (!function_exists('get_editable_roles')) require_once ABSPATH .'wp-admin/includes/user.php';
48
+
49
  $roles = get_editable_roles();
50
 
51
  $types = array();
122
 
123
  }
124
 
125
+ function disable_gutenberg_disable_all() {
126
+
127
+ $options = disable_gutenberg_get_options();
128
+
129
+ $disable_all = (isset($options['disable-all']) && !empty($options['disable-all'])) ? true : false;
130
+
131
+ if ($disable_all) return true;
132
+
133
+ return false;
134
+
135
+ }
136
+
137
+ function disable_gutenberg_disable_user_role() {
138
+
139
+ foreach (disable_gutenberg_get_enabled_user_roles() as $role) {
140
+
141
+ $roles = disable_gutenberg_get_current_user_roles();
142
+
143
+ if (is_array($roles) && in_array($role, $roles)) return true;
144
+
145
+ }
146
+
147
+ return false;
148
+
149
+ }
150
+
151
+ function disable_gutenberg_disable_post_type() {
152
+
153
+ global $pagenow, $typenow;
154
+
155
+ $post_type = null;
156
+
157
+ if ($pagenow === 'edit.php') {
158
+
159
+ if (empty($typenow)) $typenow = 'post';
160
+
161
+ $post_type = $typenow;
162
+
163
+ } elseif ($pagenow === 'post.php') {
164
+
165
+ $post_id = isset($_GET['post']) ? $_GET['post'] : null;
166
+
167
+ $post_type = $post_id ? get_post_type($post_id) : null;
168
+
169
+ } elseif ($pagenow === 'post-new.php') {
170
+
171
+ if (empty($typenow)) $typenow = 'post';
172
+
173
+ $post_type = isset($_GET['post_type']) ? $_GET['post_type'] : null;
174
+
175
+ if (empty($post_type)) $post_type = $typenow;
176
+
177
+ }
178
+
179
+ if ($post_type) {
180
+
181
+ foreach (disable_gutenberg_get_enabled_post_types() as $type) {
182
+
183
+ if ($post_type === $type) return true;
184
+
185
+ }
186
+
187
+ }
188
+
189
+ return false;
190
+
191
+ }
192
+
193
  function disable_gutenberg_disable_templates() {
194
 
195
  $excluded = array();
263
  if ($hide_gutenberg) remove_menu_page('gutenberg');
264
 
265
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/plugin-features.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php // Plugin Features
2
+
3
+ if (!defined('ABSPATH')) exit;
4
+
5
+ // THANKS to Classic Editor for these "feature" functions
6
+
7
+ function disable_gutenberg_add_submenus() {
8
+
9
+ if (disable_gutenberg()) return;
10
+
11
+ foreach (get_post_types(array('show_ui' => true)) as $type) {
12
+
13
+ $type_obj = get_post_type_object($type);
14
+
15
+ if (!$type_obj->show_in_menu || !post_type_supports($type, 'editor')) continue;
16
+
17
+ if ($type_obj->show_in_menu === true) {
18
+
19
+ if ('post' === $type) {
20
+
21
+ $parent_slug = 'edit.php';
22
+
23
+ } elseif ('page' === $type) {
24
+
25
+ $parent_slug = 'edit.php?post_type=page';
26
+
27
+ } else {
28
+
29
+ continue;
30
+
31
+ }
32
+
33
+ } else {
34
+
35
+ $parent_slug = $type_obj->show_in_menu;
36
+
37
+ }
38
+
39
+ $item_name = $type_obj->labels->add_new .' '. __('(Classic)', 'disable-gutenberg');
40
+
41
+ add_submenu_page($parent_slug, $type_obj->labels->add_new, $item_name, $type_obj->cap->edit_posts, 'post-new.php?post_type='. $type .'&classic-editor');
42
+
43
+ }
44
+
45
+ }
46
+ add_action('admin_menu', 'disable_gutenberg_add_submenus');
47
+
48
+
49
+
50
+ function disable_gutenberg_page_row_actions($actions, $post) {
51
+
52
+ if (disable_gutenberg()) return $actions;
53
+
54
+ if (array_key_exists('classic', $actions)) return $actions;
55
+
56
+ if ('trash' === $post->post_status || !post_type_supports($post->post_type, 'editor')) return $actions;
57
+
58
+ $edit_url = get_edit_post_link($post->ID, 'raw');
59
+
60
+ if (!$edit_url) return $actions;
61
+
62
+ $edit_url = add_query_arg('classic-editor', '', $edit_url);
63
+
64
+ $title = _draft_or_post_title($post->ID);
65
+
66
+ $edit_action = array(
67
+
68
+ 'classic' => sprintf(
69
+
70
+ '<a href="%s" aria-label="%s">%s</a>',
71
+
72
+ esc_url($edit_url),
73
+
74
+ esc_attr(sprintf(
75
+
76
+ __('Edit &#8220;%s&#8221; with Classic Editor', 'disable-gutenberg'),
77
+
78
+ $title
79
+
80
+ )),
81
+
82
+ __('Edit (Classic)', 'disable-gutenberg')
83
+
84
+ ),
85
+
86
+ );
87
+
88
+ $edit_offset = array_search('edit', array_keys($actions), true);
89
+
90
+ array_splice($actions, $edit_offset + 1, 0, $edit_action);
91
+
92
+ return $actions;
93
+
94
+ }
95
+ add_filter('page_row_actions', 'disable_gutenberg_page_row_actions', 15, 2);
96
+ add_filter('post_row_actions', 'disable_gutenberg_page_row_actions', 15, 2);
97
+
98
+
99
+
100
+ function disable_gutenberg_get_edit_post_link($url) {
101
+
102
+ global $current_screen;
103
+
104
+ if (!isset($_REQUEST['classic-editor']) && !disable_gutenberg()) return $url;
105
+
106
+ $url = add_query_arg('classic-editor', '', $url);
107
+
108
+ return $url;
109
+
110
+ }
111
+ add_filter('get_edit_post_link', 'disable_gutenberg_get_edit_post_link');
112
+
113
+
114
+
115
+ function disable_gutenberg_redirect_post_location($location) {
116
+
117
+ global $current_screen;
118
+
119
+ if (!isset($_REQUEST['classic-editor']) && !disable_gutenberg()) return $location;
120
+
121
+ if (isset($_REQUEST['classic-editor']) || (isset($_POST['_wp_http_referer']) && strpos($_POST['_wp_http_referer'], '&classic-editor') !== false)) {
122
+
123
+ $location = add_query_arg('classic-editor', '', $location);
124
+
125
+ }
126
+
127
+ return $location;
128
+
129
+ }
130
+ add_filter('redirect_post_location', 'disable_gutenberg_redirect_post_location');
131
+
132
+
133
+
134
+ function disable_gutenberg_edit_form_top() {
135
+
136
+ global $current_screen;
137
+
138
+ if (!isset($_GET['classic-editor']) && !disable_gutenberg()) return;
139
+
140
+ ?>
141
+
142
+ <input type="hidden" name="classic-editor" value="" />
143
+
144
+ <?php
145
+
146
+ }
147
+ add_action('edit_form_top', 'disable_gutenberg_edit_form_top');
readme.txt CHANGED
@@ -2,30 +2,30 @@
2
 
3
  Plugin Name: Disable Gutenberg
4
  Plugin URI: https://perishablepress.com/disable-gutenberg/
5
- Description: Disables Gutenberg and restores the Classic Editor and original Edit Post screen. Provides options to enable on specific post types, user roles, and more.
6
- Tags: gutenberg, disable, post types, g7g
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.5
12
  Tested up to: 5.0
13
- Stable tag: 1.3.1
14
- Version: 1.3.1
15
  Requires PHP: 5.2
16
  Text Domain: disable-gutenberg
17
  Domain Path: /languages
18
  License: GPL v2 or later
19
 
20
- Disable Gutenberg and restore the Classic Editor and original Edit Post screen (TinyMCE, meta boxes, et al). Selectively disable for posts, pages, roles, post types, and theme templates. Hide the Gutenberg nag, menu item, and more.
21
 
22
 
23
 
24
  == Description ==
25
 
26
- This plugin disables the new Gutenberg Editor and replaces it with the Classic Editor. You can disable Gutenberg completely, or selectively disable for posts, pages, roles, post types, and theme templates. Plus you can hide the Gutenberg nag, menu item, and more!
27
 
28
- > The all-in-one, COMPLETE solution handling Gutenberg.
29
  > Hide ALL traces of Gutenberg and replace with the Classic Editor.
30
  > Restores the original Edit Post screen (TinyMCE, meta boxes, et al).
31
 
@@ -41,6 +41,8 @@ The Disable Gutenberg plugin restores the classic (original) WordPress editor an
41
  * Disable Gutenberg admin notice (nag)
42
  * Option to hide the plugin menu item
43
  * Option to hide the Gutenberg plugin menu item (settings link)
 
 
44
 
45
  > Works same way as Classic Editor plugin, but can do a LOT more!
46
  > Lightweight and super fast, built with the WP API :)
@@ -163,6 +165,13 @@ Bottom line: both Disable Gutenberg and Classic Editor plugins are lightweight a
163
  Because it is being promoted by the Gutenberg developers and the "official" plugin for replacing Gutenberg. That's fine, but understand that Disable Gutenberg functions the same way AND provides way more features and settings. FWIW, I use Disable Gutenberg on my sites Perishable Press, DigWP.com, Plugin Planet, and many others. 100% solid.
164
 
165
 
 
 
 
 
 
 
 
166
  **Got a question?**
167
 
168
  Send any questions or feedback via my [contact form](https://perishablepress.com/contact/)
@@ -191,12 +200,18 @@ Links, tweets and likes also appreciated. Thanks! :)
191
 
192
  == Changelog ==
193
 
 
 
 
 
 
 
 
194
  **1.3.1 (2018/10/29)**
195
 
196
  * Rolls back new "Edit Classic" feature introduced in 1.3
197
  * Further tests on WP 5.0 beta
198
 
199
-
200
  **1.3 (2018/10/27)**
201
 
202
  * Refactored for WordPress 5.0 (Gutenberg merged into core)
@@ -225,7 +240,6 @@ Links, tweets and likes also appreciated. Thanks! :)
225
  * Adds option to hide the plugin's menu item
226
  * Further testing on WP 5.0 (alpha)
227
 
228
-
229
  **1.0 (2018/04/16)**
230
 
231
  * Initial release
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: gutenberg, block editor, block-editor, disable, blocks, 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.5
12
  Tested up to: 5.0
13
+ Stable tag: 1.4
14
+ Version: 1.4
15
  Requires PHP: 5.2
16
  Text Domain: disable-gutenberg
17
  Domain Path: /languages
18
  License: GPL v2 or later
19
 
20
+ Disable Gutenberg Block Editor and restore the Classic Editor and original Edit Post screen (TinyMCE, meta boxes, et al). Selectively disable for posts, pages, roles, post types, and theme templates. Hide the Gutenberg nag, menu item, and more.
21
 
22
 
23
 
24
  == Description ==
25
 
26
+ This plugin disables the new Gutenberg Editor (aka Block Editor) and replaces it with the Classic Editor. You can disable Gutenberg completely, or selectively disable for posts, pages, roles, post types, and theme templates. Plus you can hide the Gutenberg nag, menu item, and more!
27
 
28
+ > The all-in-one, COMPLETE solution for handling Gutenberg.
29
  > Hide ALL traces of Gutenberg and replace with the Classic Editor.
30
  > Restores the original Edit Post screen (TinyMCE, meta boxes, et al).
31
 
41
  * Disable Gutenberg admin notice (nag)
42
  * Option to hide the plugin menu item
43
  * Option to hide the Gutenberg plugin menu item (settings link)
44
+ * NEW! Adds WP menu item: "Add New (Classic)"
45
+ * NEW! Adds post link to "Edit (Classic)"
46
 
47
  > Works same way as Classic Editor plugin, but can do a LOT more!
48
  > Lightweight and super fast, built with the WP API :)
165
  Because it is being promoted by the Gutenberg developers and the "official" plugin for replacing Gutenberg. That's fine, but understand that Disable Gutenberg functions the same way AND provides way more features and settings. FWIW, I use Disable Gutenberg on my sites Perishable Press, DigWP.com, Plugin Planet, and many others. 100% solid.
166
 
167
 
168
+ **Template exclusions not working?**
169
+
170
+ In order for template exclusions to work, the template must be registered with the page itself. The only way to do this is via the "Edit Page" screen, in the "Page Attributes" meta box. There you will find an option to set the page template. Remember to save your changes.
171
+
172
+ After assigning some templates, they will be recognized by Disable Gutenberg. So to disable Gutenberg on any registered template, you can add them via the plugin setting, "Disable for Templates". Important: the template name must be written as `page-custom.php`, only using the actual file name of whichever template you want to use.
173
+
174
+
175
  **Got a question?**
176
 
177
  Send any questions or feedback via my [contact form](https://perishablepress.com/contact/)
200
 
201
  == Changelog ==
202
 
203
+ **1.4 (2018/11/09)**
204
+
205
+ * Refactored for changes in Gutenberg plugin
206
+ * Checks for Classic Editor plugin is active
207
+ * Restores "Edit Classic" feature for WP 5.0+
208
+ * Further tests on WP 4.9.8 and 5.0 beta
209
+
210
  **1.3.1 (2018/10/29)**
211
 
212
  * Rolls back new "Edit Classic" feature introduced in 1.3
213
  * Further tests on WP 5.0 beta
214
 
 
215
  **1.3 (2018/10/27)**
216
 
217
  * Refactored for WordPress 5.0 (Gutenberg merged into core)
240
  * Adds option to hide the plugin's menu item
241
  * Further testing on WP 5.0 (alpha)
242
 
 
243
  **1.0 (2018/04/16)**
244
 
245
  * Initial release