Classic Editor - Version 0.5

Version Description

Updated for Gutenberg 4.1 and WordPress 5.0-beta1. Removed some functionality that now exists in Gutenberg. Fixed redirecting back to the Classic editor after looking at post revisions.

Download this release

Release Info

Developer azaozz
Plugin Icon 128x128 Classic Editor
Version 0.5
Comparing to
See all releases

Code changes from version 0.4 to 0.5

Files changed (2) hide show
  1. classic-editor.php +91 -55
  2. readme.txt +10 -5
classic-editor.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin Name: Classic Editor
6
  * Plugin URI: https://wordpress.org
7
  * Description: Enables the WordPress classic editor and the old-style Edit Post screen layout (TinyMCE, meta boxes, etc.). Supports the older plugins that extend this screen.
8
- * Version: 0.4
9
  * Author: WordPress Contributors
10
  * License: GPL-2.0+
11
  * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -26,45 +26,44 @@ if ( ! defined( 'ABSPATH' ) ) {
26
  die( 'Invalid request.' );
27
  }
28
 
29
- /**
30
- * Check if Gutenberg is active.
31
- *
32
- * Cannot use `is_plugin_active()` as it loads late and only in wp-admin.
33
- *
34
- * @return bool Whether the Gutenberg plugin is active.
35
- */
36
- function classic_editor_is_gutenberg_active() {
37
- if ( in_array( 'gutenberg/gutenberg.php', (array) get_option( 'active_plugins' ) ) ||
38
- ( is_multisite() && array_key_exists( 'gutenberg/gutenberg.php', (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
39
-
40
- return true;
41
- }
42
-
43
- return false;
44
- }
45
-
46
  add_action( 'plugins_loaded', 'classic_editor_init_actions' );
47
  function classic_editor_init_actions() {
 
 
 
48
  // Always remove the "Try Gutenberg" dashboard widget. See https://core.trac.wordpress.org/ticket/44635.
 
49
  remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
50
 
51
  // Always show the settings and the link to them in the plugins list table.
52
  add_filter( 'plugin_action_links', 'classic_editor_add_settings_link', 10, 2 );
53
  add_action( 'admin_init', 'classic_editor_admin_init' );
54
 
55
- if ( ! classic_editor_is_gutenberg_active() || ! (
56
- has_filter( 'replace_editor', 'gutenberg_init' ) ||
57
- has_filter( 'load-post.php', 'gutenberg_intercept_edit_post' ) ) ) {
 
58
 
59
- // Gutenberg is not installed or activated. No need to do anything :)
60
- return;
 
 
 
 
 
61
  }
62
 
63
  $replace = ( get_option( 'classic-editor-replace' ) !== 'no-replace' );
64
 
65
- if ( $replace || isset( $_GET['classic-editor'] ) ) {
 
 
 
 
 
66
  // gutenberg.php
67
  remove_action( 'admin_menu', 'gutenberg_menu' );
 
68
  remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
69
  remove_action( 'admin_init', 'gutenberg_redirect_demo' );
70
 
@@ -79,25 +78,13 @@ function classic_editor_init_actions() {
79
  // lib/compat.php
80
  remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
81
 
82
- // lib/register.php
83
- remove_action( 'plugins_loaded', 'gutenberg_trick_plugins_into_registering_meta_boxes' );
84
- remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
85
-
86
- remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
87
- remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
88
- remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
89
-
90
  // lib/rest-api.php
91
  remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
92
  remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
93
 
94
  remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
95
  remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
96
- remove_filter( 'registered_taxonomy', 'gutenberg_register_taxonomy_prepare_functions' );
97
- remove_filter( 'rest_index', 'gutenberg_ensure_wp_json_has_theme_supports' );
98
- remove_filter( 'rest_request_before_callbacks', 'gutenberg_handle_early_callback_checks' );
99
- remove_filter( 'rest_user_collection_params', 'gutenberg_filter_user_collection_parameters' );
100
- remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_request_after_callbacks' );
101
 
102
  // lib/meta-box-partial-page.php
103
  remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save', 1000 );
@@ -112,12 +99,27 @@ function classic_editor_init_actions() {
112
  // add_filter( 'replace_editor', 'classic_editor_replace' );
113
  }
114
 
115
- if ( $replace ) {
116
  // gutenberg.php
117
- remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' );
118
  remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
119
 
 
 
 
 
 
 
 
 
 
 
120
  // lib/register.php
 
 
 
 
 
121
  remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' );
122
 
123
  // lib/plugin-compat.php
@@ -136,20 +138,25 @@ function classic_editor_init_actions() {
136
  // remove_filter( 'the_content', 'gutenberg_wpautop', 8 );
137
 
138
  // remove_action( 'init', 'gutenberg_register_post_types' );
139
- } else {
 
 
140
  // Menus
141
  add_action( 'admin_menu', 'classic_editor_add_submenus' );
142
  add_action( 'admin_bar_menu', 'classic_editor_admin_bar_menu', 120 );
143
 
144
  // Row actions (edit.php)
145
- add_filter( 'page_row_actions', 'classic_editor_add_edit_links', 10, 2 );
146
- add_filter( 'post_row_actions', 'classic_editor_add_edit_links', 10, 2 );
147
 
148
- add_filter( 'redirect_post_location', 'classic_editor_redirect_location' );
149
- }
150
 
151
- // Gutenberg plugin: remove the "Classic editor" row actions.
152
- remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
 
 
 
 
153
  }
154
 
155
  function classic_editor_admin_init() {
@@ -175,13 +182,13 @@ function classic_editor_settings() {
175
  <p id="classic-editor-options" style="margin: 0;">
176
  <input type="radio" name="classic-editor-replace" id="classic-editor-replace" value="replace"<?php if ( $replace ) echo ' checked'; ?> />
177
  <label for="classic-editor-replace">
178
- <?php _e( 'Replace the Gutenberg editor with the Classic editor.', 'classic-editor' ); ?>
179
  </label>
180
  <br>
181
 
182
  <input type="radio" name="classic-editor-replace" id="classic-editor-no-replace" value="no-replace"<?php if ( ! $replace ) echo ' checked'; ?> />
183
  <label for="classic-editor-no-replace">
184
- <?php _e( 'Use the Gutenberg editor by default and include optional links back to the Classic editor.', 'classic-editor' ); ?>
185
  </label>
186
  </p>
187
  <script>
@@ -206,16 +213,40 @@ function classic_editor_validate_options( $value ) {
206
  }
207
 
208
  /**
209
- * Keep the `classic-editor` query arg. through redirects when saving posts.
 
 
 
 
 
 
 
 
 
 
210
  */
211
  function classic_editor_redirect_location( $location ) {
212
- if ( isset( $_POST['_wp_http_referer'] ) && strpos( $_POST['_wp_http_referer'], 'classic-editor=1' ) !== false ) {
213
- $location = add_query_arg( 'classic-editor', '1', $location );
 
 
 
214
  }
215
 
216
  return $location;
217
  }
218
 
 
 
 
 
 
 
 
 
 
 
 
219
  /**
220
  * Add an `Add New (Classic)` submenu for Posts, Pages, etc.
221
  */
@@ -242,7 +273,7 @@ function classic_editor_add_submenus() {
242
 
243
  $item_name = $type_obj->labels->add_new . ' ' . __( '(Classic)', 'classic-editor' );
244
 
245
- 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=1" );
246
  }
247
  }
248
 
@@ -277,14 +308,14 @@ function classic_editor_admin_bar_menu( $wp_admin_bar ) {
277
  if ( isset( $_GET['classic-editor'] ) ) {
278
  $wp_admin_bar->add_menu( array(
279
  'id' => 'classic-editor',
280
- 'title' => __( 'Edit (Gutenberg)', 'classic-editor' ),
281
  'href' => remove_query_arg( 'classic-editor', $edit_url ),
282
  ) );
283
  } else {
284
  $wp_admin_bar->add_menu( array(
285
  'id' => 'classic-editor',
286
  'title' => __( 'Edit (Classic)', 'classic-editor' ),
287
- 'href' => add_query_arg( 'classic-editor', '1', $edit_url ),
288
  ) );
289
  }
290
  }
@@ -312,6 +343,11 @@ function classic_editor_add_settings_link( $links, $file ) {
312
  * @return array Updated post actions.
313
  */
314
  function classic_editor_add_edit_links( $actions, $post ) {
 
 
 
 
 
315
  if ( 'trash' === $post->post_status || ! post_type_supports( $post->post_type, 'editor' ) ) {
316
  return $actions;
317
  }
@@ -322,7 +358,7 @@ function classic_editor_add_edit_links( $actions, $post ) {
322
  return $actions;
323
  }
324
 
325
- $edit_url = add_query_arg( 'classic-editor', '1', $edit_url );
326
 
327
  // Build the classic edit action. See also: WP_Posts_List_Table::handle_row_actions().
328
  $title = _draft_or_post_title( $post->ID );
5
  * Plugin Name: Classic Editor
6
  * Plugin URI: https://wordpress.org
7
  * Description: Enables the WordPress classic editor and the old-style Edit Post screen layout (TinyMCE, meta boxes, etc.). Supports the older plugins that extend this screen.
8
+ * Version: 0.5
9
  * Author: WordPress Contributors
10
  * License: GPL-2.0+
11
  * License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26
  die( 'Invalid request.' );
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  add_action( 'plugins_loaded', 'classic_editor_init_actions' );
30
  function classic_editor_init_actions() {
31
+ $gutenberg = false;
32
+ $block_editor = false;
33
+
34
  // Always remove the "Try Gutenberg" dashboard widget. See https://core.trac.wordpress.org/ticket/44635.
35
+ // TODO: not needed in 5.0-beta
36
  remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
37
 
38
  // Always show the settings and the link to them in the plugins list table.
39
  add_filter( 'plugin_action_links', 'classic_editor_add_settings_link', 10, 2 );
40
  add_action( 'admin_init', 'classic_editor_admin_init' );
41
 
42
+ if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
43
+ // Gutenberg is installed and activated.
44
+ $gutenberg = true;
45
+ }
46
 
47
+ if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
48
+ // Block editor.
49
+ $block_editor = true;
50
+ }
51
+
52
+ if ( ! $gutenberg && ! $block_editor ) {
53
+ return; // Nothing to do :)
54
  }
55
 
56
  $replace = ( get_option( 'classic-editor-replace' ) !== 'no-replace' );
57
 
58
+ if ( $block_editor && ( $replace || isset( $_GET['classic-editor'] ) ) ) {
59
+ // TODO: consider disabling other block editor functionality.
60
+ add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
61
+ }
62
+
63
+ if ( $gutenberg && ( $replace || isset( $_GET['classic-editor'] ) ) ) {
64
  // gutenberg.php
65
  remove_action( 'admin_menu', 'gutenberg_menu' );
66
+ remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
67
  remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
68
  remove_action( 'admin_init', 'gutenberg_redirect_demo' );
69
 
78
  // lib/compat.php
79
  remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
80
 
 
 
 
 
 
 
 
 
81
  // lib/rest-api.php
82
  remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
83
  remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
84
 
85
  remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
86
  remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
87
+ remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );
 
 
 
 
88
 
89
  // lib/meta-box-partial-page.php
90
  remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save', 1000 );
99
  // add_filter( 'replace_editor', 'classic_editor_replace' );
100
  }
101
 
102
+ if ( $gutenberg && $replace ) {
103
  // gutenberg.php
104
+ remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
105
  remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
106
 
107
+ remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
108
+ remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' );
109
+
110
+ // Keep
111
+ // remove_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2 ); // not needed in 5.0
112
+ // remove_filter( 'bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions' );
113
+
114
+ // lib/compat.php
115
+ remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
116
+
117
  // lib/register.php
118
+ remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
119
+
120
+ remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
121
+ remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
122
+ remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
123
  remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' );
124
 
125
  // lib/plugin-compat.php
138
  // remove_filter( 'the_content', 'gutenberg_wpautop', 8 );
139
 
140
  // remove_action( 'init', 'gutenberg_register_post_types' );
141
+ }
142
+
143
+ if ( ! $replace ) {
144
  // Menus
145
  add_action( 'admin_menu', 'classic_editor_add_submenus' );
146
  add_action( 'admin_bar_menu', 'classic_editor_admin_bar_menu', 120 );
147
 
148
  // Row actions (edit.php)
149
+ add_filter( 'page_row_actions', 'classic_editor_add_edit_links', 15, 2 );
150
+ add_filter( 'post_row_actions', 'classic_editor_add_edit_links', 15, 2 );
151
 
152
+ add_filter( 'get_edit_post_link', 'classic_editor_get_edit_post_link' );
 
153
 
154
+ if ( ! $gutenberg ) {
155
+ // Redirect on saving in the classic editor.
156
+ add_filter( 'redirect_post_location', 'classic_editor_redirect_location' );
157
+ add_action( 'edit_form_top', 'classic_editor_remember_when_saving_posts' );
158
+ }
159
+ }
160
  }
161
 
162
  function classic_editor_admin_init() {
182
  <p id="classic-editor-options" style="margin: 0;">
183
  <input type="radio" name="classic-editor-replace" id="classic-editor-replace" value="replace"<?php if ( $replace ) echo ' checked'; ?> />
184
  <label for="classic-editor-replace">
185
+ <?php _e( 'Replace the Block editor with the Classic editor.', 'classic-editor' ); ?>
186
  </label>
187
  <br>
188
 
189
  <input type="radio" name="classic-editor-replace" id="classic-editor-no-replace" value="no-replace"<?php if ( ! $replace ) echo ' checked'; ?> />
190
  <label for="classic-editor-no-replace">
191
+ <?php _e( 'Use the Block editor by default and include optional links back to the Classic editor.', 'classic-editor' ); ?>
192
  </label>
193
  </p>
194
  <script>
213
  }
214
 
215
  /**
216
+ * Add a hidden field in edit-form-advanced.php
217
+ * to help redirect back to the classic editor on saving.
218
+ */
219
+ function classic_editor_remember_when_saving_posts() {
220
+ ?>
221
+ <input type="hidden" name="classic-editor" value="" />
222
+ <?php
223
+ }
224
+
225
+ /**
226
+ * Keep the `classic-editor` query arg through redirects when saving posts.
227
  */
228
  function classic_editor_redirect_location( $location ) {
229
+ if (
230
+ isset( $_REQUEST['classic-editor'] ) ||
231
+ ( isset( $_POST['_wp_http_referer'] ) && strpos( $_POST['_wp_http_referer'], '&classic-editor' ) !== false )
232
+ ) {
233
+ $location = add_query_arg( 'classic-editor', '', $location );
234
  }
235
 
236
  return $location;
237
  }
238
 
239
+ /**
240
+ * Keep the `classic-editor` query arg when looking at revisions.
241
+ */
242
+ function classic_editor_get_edit_post_link( $url ) {
243
+ if ( isset( $_REQUEST['classic-editor'] ) ) {
244
+ $url = add_query_arg( 'classic-editor', '', $url );
245
+ }
246
+
247
+ return $url;
248
+ }
249
+
250
  /**
251
  * Add an `Add New (Classic)` submenu for Posts, Pages, etc.
252
  */
273
 
274
  $item_name = $type_obj->labels->add_new . ' ' . __( '(Classic)', 'classic-editor' );
275
 
276
+ 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" );
277
  }
278
  }
279
 
308
  if ( isset( $_GET['classic-editor'] ) ) {
309
  $wp_admin_bar->add_menu( array(
310
  'id' => 'classic-editor',
311
+ 'title' => __( 'Edit (Block editor)', 'classic-editor' ),
312
  'href' => remove_query_arg( 'classic-editor', $edit_url ),
313
  ) );
314
  } else {
315
  $wp_admin_bar->add_menu( array(
316
  'id' => 'classic-editor',
317
  'title' => __( 'Edit (Classic)', 'classic-editor' ),
318
+ 'href' => add_query_arg( 'classic-editor', '', $edit_url ),
319
  ) );
320
  }
321
  }
343
  * @return array Updated post actions.
344
  */
345
  function classic_editor_add_edit_links( $actions, $post ) {
346
+ // This is in Gutenberg now.
347
+ if ( array_key_exists( 'classic', $actions ) ) {
348
+ return $actions;
349
+ }
350
+
351
  if ( 'trash' === $post->post_status || ! post_type_supports( $post->post_type, 'editor' ) ) {
352
  return $actions;
353
  }
358
  return $actions;
359
  }
360
 
361
+ $edit_url = add_query_arg( 'classic-editor', '', $edit_url );
362
 
363
  // Build the classic edit action. See also: WP_Posts_List_Table::handle_row_actions().
364
  $title = _draft_or_post_title( $post->ID );
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Classic Editor ===
2
  Contributors: azaozz
3
  Requires at least: 4.9
4
- Tested up to: 4.9
5
- Stable tag: 0.3
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
 
@@ -12,16 +12,21 @@ Restores the Classic Editor and the old-style Edit Post screen layout (TinyMCE,
12
 
13
  Classic Editor restores the previous WordPress editor and the Edit Post screen and makes it possible to use the plugins that extend it, add old-style meta boxes, or otherwise depend on the previous editor.
14
 
15
- By default it will hide all traces of the new Gutenberg editor including the Dashboard widget asking the users to try it.
16
 
17
  It has two modes:
18
 
19
- 1. Fully replaces the Gutenberg editor and restores the Edit Post template.
20
- 2. Adds alternate "Edit" links to the Posts and Pages screens, on the toolbar at the top of the screen, and in the admin menu. Using these links will open the corresponding post or page in the Classic Editor.
21
 
22
  The modes can be changed from the Settings -> Writing screen. See the screenshots.
23
 
24
  == Changelog ==
 
 
 
 
 
25
  = 0.4 =
26
  Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated.
27
  Fixed to always show the settings and the settings link in the plugins list table.
1
  === Classic Editor ===
2
  Contributors: azaozz
3
  Requires at least: 4.9
4
+ Tested up to: 5.0-beta1
5
+ Stable tag: 0.4
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
 
12
 
13
  Classic Editor restores the previous WordPress editor and the Edit Post screen and makes it possible to use the plugins that extend it, add old-style meta boxes, or otherwise depend on the previous editor.
14
 
15
+ By default it will hide all traces of the new Block editor and the Gutenberg editor including the Dashboard widget asking the users to try it.
16
 
17
  It has two modes:
18
 
19
+ 1. Fully replaces the Block editor and the Gutenberg editor, and restores the Edit Post template.
20
+ 2. Adds alternate "Edit" links to the Posts and Pages screens, on the toolbar at the top of the screen, and in the admin menu. Using these links will open the corresponding post or page in the Classic editor.
21
 
22
  The modes can be changed from the Settings -> Writing screen. See the screenshots.
23
 
24
  == Changelog ==
25
+ = 0.5 =
26
+ Updated for Gutenberg 4.1 and WordPress 5.0-beta1.
27
+ Removed some functionality that now exists in Gutenberg.
28
+ Fixed redirecting back to the Classic editor after looking at post revisions.
29
+
30
  = 0.4 =
31
  Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated.
32
  Fixed to always show the settings and the settings link in the plugins list table.