Version Description
- Updated for WordPress 5.2 and Gutenberg 5.3+.
- Enhanced and fixed the "open posts in the last editor used to edit them" logic.
- Fixed adding post state so it can easily be accessed from other plugins.
Download this release
Release Info
Developer | azaozz |
Plugin | Classic Editor |
Version | 1.5 |
Comparing to | |
See all releases |
Code changes from version 1.4 to 1.5
- classic-editor.php +64 -59
- js/block-editor-plugin.js +23 -23
- readme.txt +6 -1
classic-editor.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Plugin Name: Classic Editor
|
6 |
* Plugin URI: https://wordpress.org/plugins/classic-editor/
|
7 |
* Description: Enables the WordPress classic editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports the older plugins that extend this screen.
|
8 |
-
* Version: 1.
|
9 |
* Author: WordPress Contributors
|
10 |
* Author URI: https://github.com/WordPress/classic-editor/
|
11 |
* License: GPLv2 or later
|
@@ -34,7 +34,7 @@ class Classic_Editor {
|
|
34 |
|
35 |
public static function init_actions() {
|
36 |
$block_editor = has_action( 'enqueue_block_assets' );
|
37 |
-
$gutenberg = function_exists( '
|
38 |
|
39 |
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
|
40 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
|
@@ -68,10 +68,11 @@ class Classic_Editor {
|
|
68 |
}
|
69 |
|
70 |
if ( $settings['allow-users'] ) {
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
if ( $gutenberg ) {
|
|
|
75 |
add_filter( 'gutenberg_can_edit_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
76 |
|
77 |
if ( $settings['editor'] === 'classic' ) {
|
@@ -98,11 +99,12 @@ class Classic_Editor {
|
|
98 |
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
|
99 |
} else {
|
100 |
if ( $settings['editor'] === 'classic' ) {
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
if ( $gutenberg ) {
|
|
|
106 |
add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
|
107 |
self::remove_gutenberg_hooks();
|
108 |
}
|
@@ -113,13 +115,11 @@ class Classic_Editor {
|
|
113 |
}
|
114 |
|
115 |
if ( $block_editor ) {
|
116 |
-
// Show warning on the "What's New" screen (about.php).
|
117 |
-
add_action( 'all_admin_notices', array( __CLASS__, 'notice_after_upgrade' ) );
|
118 |
// Move the Privacy Page notice back under the title.
|
119 |
add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) );
|
120 |
}
|
121 |
if ( $gutenberg ) {
|
122 |
-
// These are handled by this plugin.
|
123 |
remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
|
124 |
remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
|
125 |
remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
|
@@ -136,16 +136,35 @@ class Classic_Editor {
|
|
136 |
return;
|
137 |
}
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
|
140 |
remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
|
141 |
remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
|
142 |
|
143 |
remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
|
144 |
remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
|
145 |
-
remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
|
146 |
remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
|
147 |
|
148 |
-
remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save'
|
149 |
remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
|
150 |
remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
|
151 |
remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
|
@@ -153,7 +172,6 @@ class Classic_Editor {
|
|
153 |
remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
|
154 |
remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
|
155 |
|
156 |
-
remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
|
157 |
remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
|
158 |
remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
|
159 |
remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
|
@@ -271,12 +289,16 @@ class Classic_Editor {
|
|
271 |
if ( $settings['allow-users'] && ! isset( $_GET['classic-editor__forget'] ) ) {
|
272 |
$which = get_post_meta( $post_id, 'classic-editor-remember', true );
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
279 |
}
|
|
|
|
|
280 |
}
|
281 |
}
|
282 |
|
@@ -484,44 +506,6 @@ class Classic_Editor {
|
|
484 |
}
|
485 |
}
|
486 |
|
487 |
-
public static function notice_after_upgrade() {
|
488 |
-
global $pagenow;
|
489 |
-
$settings = self::get_settings();
|
490 |
-
|
491 |
-
if (
|
492 |
-
$pagenow !== 'about.php' ||
|
493 |
-
$settings['hide-settings-ui'] ||
|
494 |
-
$settings['editor'] === 'block' ||
|
495 |
-
$settings['allow-users'] ||
|
496 |
-
! current_user_can( 'edit_posts' )
|
497 |
-
) {
|
498 |
-
// No need to show when the user cannot edit posts,
|
499 |
-
// the settings are preset from another plugin,
|
500 |
-
// or when not replacing the Block Editor.
|
501 |
-
return;
|
502 |
-
}
|
503 |
-
|
504 |
-
$message = __( 'The Classic Editor plugin prevents use of the new Block Editor.', 'classic-editor' );
|
505 |
-
|
506 |
-
if ( current_user_can( 'manage_options' ) ) {
|
507 |
-
if ( is_network_admin() ) {
|
508 |
-
$url = 'settings.php#classic-editor-options';
|
509 |
-
} else {
|
510 |
-
$url = 'options-writing.php#classic-editor-options';
|
511 |
-
}
|
512 |
-
|
513 |
-
$message .= ' ' . sprintf( __( 'Change the %1$sClassic Editor settings%2$s.', 'classic-editor' ), sprintf( '<a href="%s">', $url ), '</a>' );
|
514 |
-
}
|
515 |
-
|
516 |
-
$margin = is_rtl() ? 'margin: 1em 0 0 160px;' : 'margin: 1em 160px 0 0;';
|
517 |
-
|
518 |
-
?>
|
519 |
-
<div id="message" class="notice-warning notice" style="display: inline-block !important; <?php echo $margin; ?>">
|
520 |
-
<p><?php echo $message; ?></p>
|
521 |
-
</div>
|
522 |
-
<?php
|
523 |
-
}
|
524 |
-
|
525 |
/**
|
526 |
* Add a hidden field in edit-form-advanced.php
|
527 |
* to help redirect back to the Classic Editor on saving.
|
@@ -846,6 +830,10 @@ class Classic_Editor {
|
|
846 |
* Show the editor that will be used in a "post state" in the Posts list table.
|
847 |
*/
|
848 |
public static function add_post_state( $post_states, $post ) {
|
|
|
|
|
|
|
|
|
849 |
$editors = self::get_enabled_editors_for_post( $post );
|
850 |
|
851 |
if ( ! $editors['classic_editor'] && ! $editors['block_editor'] ) {
|
@@ -861,6 +849,8 @@ class Classic_Editor {
|
|
861 |
|
862 |
if ( $last_editor ) {
|
863 |
$is_classic = ( $last_editor === 'classic-editor' );
|
|
|
|
|
864 |
} else {
|
865 |
$settings = self::get_settings();
|
866 |
$is_classic = ( $settings['editor'] === 'classic' );
|
@@ -869,7 +859,9 @@ class Classic_Editor {
|
|
869 |
$state = $is_classic ? _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) : _x( 'Block Editor', 'Editor Name', 'classic-editor' );
|
870 |
}
|
871 |
|
872 |
-
|
|
|
|
|
873 |
|
874 |
return $post_states;
|
875 |
}
|
@@ -904,6 +896,19 @@ class Classic_Editor {
|
|
904 |
}
|
905 |
}
|
906 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
907 |
/**
|
908 |
* Set defaults on activation.
|
909 |
*/
|
5 |
* Plugin Name: Classic Editor
|
6 |
* Plugin URI: https://wordpress.org/plugins/classic-editor/
|
7 |
* Description: Enables the WordPress classic editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports the older plugins that extend this screen.
|
8 |
+
* Version: 1.5
|
9 |
* Author: WordPress Contributors
|
10 |
* Author URI: https://github.com/WordPress/classic-editor/
|
11 |
* License: GPLv2 or later
|
34 |
|
35 |
public static function init_actions() {
|
36 |
$block_editor = has_action( 'enqueue_block_assets' );
|
37 |
+
$gutenberg = function_exists( 'gutenberg_register_scripts_and_styles' );
|
38 |
|
39 |
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
|
40 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
|
68 |
}
|
69 |
|
70 |
if ( $settings['allow-users'] ) {
|
71 |
+
// Also used in Gutenberg.
|
72 |
+
add_filter( 'use_block_editor_for_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
73 |
+
|
74 |
if ( $gutenberg ) {
|
75 |
+
// Support older Gutenberg versions.
|
76 |
add_filter( 'gutenberg_can_edit_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
77 |
|
78 |
if ( $settings['editor'] === 'classic' ) {
|
99 |
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
|
100 |
} else {
|
101 |
if ( $settings['editor'] === 'classic' ) {
|
102 |
+
// Also used in Gutenberg.
|
103 |
+
// Consider disabling other Block Editor functionality.
|
104 |
+
add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
|
105 |
+
|
106 |
if ( $gutenberg ) {
|
107 |
+
// Support older Gutenberg versions.
|
108 |
add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
|
109 |
self::remove_gutenberg_hooks();
|
110 |
}
|
115 |
}
|
116 |
|
117 |
if ( $block_editor ) {
|
|
|
|
|
118 |
// Move the Privacy Page notice back under the title.
|
119 |
add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) );
|
120 |
}
|
121 |
if ( $gutenberg ) {
|
122 |
+
// These are handled by this plugin. All are older, not used in 5.3+.
|
123 |
remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
|
124 |
remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
|
125 |
remove_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts' );
|
136 |
return;
|
137 |
}
|
138 |
|
139 |
+
// Gutenberg 5.3+
|
140 |
+
remove_action( 'wp_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
|
141 |
+
remove_action( 'admin_enqueue_scripts', 'gutenberg_register_scripts_and_styles' );
|
142 |
+
remove_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
|
143 |
+
remove_action( 'rest_api_init', 'gutenberg_register_rest_widget_updater_routes' );
|
144 |
+
remove_action( 'admin_print_styles', 'gutenberg_block_editor_admin_print_styles' );
|
145 |
+
remove_action( 'admin_print_scripts', 'gutenberg_block_editor_admin_print_scripts' );
|
146 |
+
remove_action( 'admin_print_footer_scripts', 'gutenberg_block_editor_admin_print_footer_scripts' );
|
147 |
+
remove_action( 'admin_footer', 'gutenberg_block_editor_admin_footer' );
|
148 |
+
remove_action( 'admin_enqueue_scripts', 'gutenberg_widgets_init' );
|
149 |
+
remove_action( 'admin_notices', 'gutenberg_build_files_notice' );
|
150 |
+
|
151 |
+
remove_filter( 'load_script_translation_file', 'gutenberg_override_translation_file' );
|
152 |
+
remove_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );
|
153 |
+
remove_filter( 'default_content', 'gutenberg_default_demo_content' );
|
154 |
+
remove_filter( 'default_title', 'gutenberg_default_demo_title' );
|
155 |
+
remove_filter( 'block_editor_settings', 'gutenberg_legacy_widget_settings' );
|
156 |
+
remove_filter( 'rest_request_after_callbacks', 'gutenberg_filter_oembed_result' );
|
157 |
+
|
158 |
+
// Previously used, compat for older Gutenberg versions.
|
159 |
remove_filter( 'wp_refresh_nonces', 'gutenberg_add_rest_nonce_to_heartbeat_response_headers' );
|
160 |
remove_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
|
161 |
remove_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
|
162 |
|
163 |
remove_action( 'rest_api_init', 'gutenberg_register_rest_routes' );
|
164 |
remove_action( 'rest_api_init', 'gutenberg_add_taxonomy_visibility_field' );
|
|
|
165 |
remove_filter( 'registered_post_type', 'gutenberg_register_post_prepare_functions' );
|
166 |
|
167 |
+
remove_action( 'do_meta_boxes', 'gutenberg_meta_box_save' );
|
168 |
remove_action( 'submitpost_box', 'gutenberg_intercept_meta_box_render' );
|
169 |
remove_action( 'submitpage_box', 'gutenberg_intercept_meta_box_render' );
|
170 |
remove_action( 'edit_page_form', 'gutenberg_intercept_meta_box_render' );
|
172 |
remove_filter( 'redirect_post_location', 'gutenberg_meta_box_save_redirect' );
|
173 |
remove_filter( 'filter_gutenberg_meta_boxes', 'gutenberg_filter_meta_boxes' );
|
174 |
|
|
|
175 |
remove_filter( 'body_class', 'gutenberg_add_responsive_body_class' );
|
176 |
remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' ); // old
|
177 |
remove_action( 'admin_enqueue_scripts', 'gutenberg_check_if_classic_needs_warning_about_blocks' );
|
289 |
if ( $settings['allow-users'] && ! isset( $_GET['classic-editor__forget'] ) ) {
|
290 |
$which = get_post_meta( $post_id, 'classic-editor-remember', true );
|
291 |
|
292 |
+
if ( $which ) {
|
293 |
+
// The editor choice will be "remembered" when the post is opened in either Classic or Block editor.
|
294 |
+
if ( 'classic-editor' === $which ) {
|
295 |
+
return true;
|
296 |
+
} elseif ( 'block-editor' === $which ) {
|
297 |
+
return false;
|
298 |
+
}
|
299 |
}
|
300 |
+
|
301 |
+
return ( ! self::has_blocks( $post_id ) );
|
302 |
}
|
303 |
}
|
304 |
|
506 |
}
|
507 |
}
|
508 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
509 |
/**
|
510 |
* Add a hidden field in edit-form-advanced.php
|
511 |
* to help redirect back to the Classic Editor on saving.
|
830 |
* Show the editor that will be used in a "post state" in the Posts list table.
|
831 |
*/
|
832 |
public static function add_post_state( $post_states, $post ) {
|
833 |
+
if ( get_post_status( $post ) === 'trash' ) {
|
834 |
+
return $post_states;
|
835 |
+
}
|
836 |
+
|
837 |
$editors = self::get_enabled_editors_for_post( $post );
|
838 |
|
839 |
if ( ! $editors['classic_editor'] && ! $editors['block_editor'] ) {
|
849 |
|
850 |
if ( $last_editor ) {
|
851 |
$is_classic = ( $last_editor === 'classic-editor' );
|
852 |
+
} elseif ( ! empty( $post->post_content ) ) {
|
853 |
+
$is_classic = ! self::has_blocks( $post->post_content );
|
854 |
} else {
|
855 |
$settings = self::get_settings();
|
856 |
$is_classic = ( $settings['editor'] === 'classic' );
|
859 |
$state = $is_classic ? _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) : _x( 'Block Editor', 'Editor Name', 'classic-editor' );
|
860 |
}
|
861 |
|
862 |
+
// Fix PHP 7+ warnings if another plugin returns unexpected type.
|
863 |
+
$post_states = (array) $post_states;
|
864 |
+
$post_states['classic-editor-plugin'] = $state;
|
865 |
|
866 |
return $post_states;
|
867 |
}
|
896 |
}
|
897 |
}
|
898 |
|
899 |
+
// Need to support WP < 5.0
|
900 |
+
private static function has_blocks( $post = null ) {
|
901 |
+
if ( ! is_string( $post ) ) {
|
902 |
+
$wp_post = get_post( $post );
|
903 |
+
|
904 |
+
if ( $wp_post instanceof WP_Post ) {
|
905 |
+
$post = $wp_post->post_content;
|
906 |
+
}
|
907 |
+
}
|
908 |
+
|
909 |
+
return false !== strpos( (string) $post, '<!-- wp:' );
|
910 |
+
}
|
911 |
+
|
912 |
/**
|
913 |
* Set defaults on activation.
|
914 |
*/
|
js/block-editor-plugin.js
CHANGED
@@ -1,23 +1,23 @@
|
|
1 |
-
( function( wp ) {
|
2 |
-
if ( ! wp ) {
|
3 |
-
return;
|
4 |
-
}
|
5 |
-
|
6 |
-
wp.plugins.registerPlugin( 'classic-editor-plugin', {
|
7 |
-
render() {
|
8 |
-
var createElement = wp.element.createElement;
|
9 |
-
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
|
10 |
-
var url = wp.url.addQueryArgs( document.location.href, { 'classic-editor': '', 'classic-editor__forget': '' } );
|
11 |
-
var linkText = lodash.get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to Classic Editor';
|
12 |
-
|
13 |
-
return createElement(
|
14 |
-
PluginMoreMenuItem,
|
15 |
-
{
|
16 |
-
icon: 'editor-kitchensink',
|
17 |
-
href: url,
|
18 |
-
},
|
19 |
-
linkText
|
20 |
-
);
|
21 |
-
},
|
22 |
-
} );
|
23 |
-
} )( window.wp );
|
1 |
+
( function( wp ) {
|
2 |
+
if ( ! wp ) {
|
3 |
+
return;
|
4 |
+
}
|
5 |
+
|
6 |
+
wp.plugins.registerPlugin( 'classic-editor-plugin', {
|
7 |
+
render: function() {
|
8 |
+
var createElement = wp.element.createElement;
|
9 |
+
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
|
10 |
+
var url = wp.url.addQueryArgs( document.location.href, { 'classic-editor': '', 'classic-editor__forget': '' } );
|
11 |
+
var linkText = lodash.get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to Classic Editor';
|
12 |
+
|
13 |
+
return createElement(
|
14 |
+
PluginMoreMenuItem,
|
15 |
+
{
|
16 |
+
icon: 'editor-kitchensink',
|
17 |
+
href: url,
|
18 |
+
},
|
19 |
+
linkText
|
20 |
+
);
|
21 |
+
},
|
22 |
+
} );
|
23 |
+
} )( window.wp );
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: wordpressdotorg, azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce
|
3 |
Tags: gutenberg, disable, disable gutenberg, editor, classic editor, block editor
|
4 |
Requires at least: 4.9
|
5 |
-
Tested up to: 5.
|
6 |
Stable tag: 1.4
|
7 |
Requires PHP: 5.2.4
|
8 |
License: GPLv2 or later
|
@@ -29,6 +29,11 @@ By default, this plugin hides all functionality available in the new Block Edito
|
|
29 |
|
30 |
== Changelog ==
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
= 1.4 =
|
33 |
* On network installations removed the restriction for only network activation.
|
34 |
* Added support for network administrators to choose the default network-wide editor.
|
2 |
Contributors: wordpressdotorg, azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce
|
3 |
Tags: gutenberg, disable, disable gutenberg, editor, classic editor, block editor
|
4 |
Requires at least: 4.9
|
5 |
+
Tested up to: 5.2
|
6 |
Stable tag: 1.4
|
7 |
Requires PHP: 5.2.4
|
8 |
License: GPLv2 or later
|
29 |
|
30 |
== Changelog ==
|
31 |
|
32 |
+
= 1.5 =
|
33 |
+
* Updated for WordPress 5.2 and Gutenberg 5.3+.
|
34 |
+
* Enhanced and fixed the "open posts in the last editor used to edit them" logic.
|
35 |
+
* Fixed adding post state so it can easily be accessed from other plugins.
|
36 |
+
|
37 |
= 1.4 =
|
38 |
* On network installations removed the restriction for only network activation.
|
39 |
* Added support for network administrators to choose the default network-wide editor.
|