Version Description
- Fixed switching editors from the Add New (post) screen before a draft post is saved.
- Fixed typo that was appending the edit URL to the
classic-editor
query var. - Changed detecting of WordPress 5.0 to not use version check. Fixes a bug when testing 5.1-alpha.
- Changed the default value of the option to allow users to switch editors to false.
- Added disabling of the Gutenberg plugin and lowered the required WordPress version to 4.9.
- Added
classic_editor_network_default_settings
filter.
Download this release
Release Info
Developer | azaozz |
Plugin | Classic Editor |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- classic-editor.php +170 -57
- readme.txt +31 -25
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
|
@@ -28,14 +28,15 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
28 |
|
29 |
if ( ! class_exists( 'Classic_Editor' ) ) :
|
30 |
class Classic_Editor {
|
31 |
-
const plugin_version = 1.
|
32 |
private static $settings;
|
33 |
private static $supported_post_types = array();
|
34 |
|
35 |
private function __construct() {}
|
36 |
|
37 |
public static function init_actions() {
|
38 |
-
$
|
|
|
39 |
|
40 |
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
|
41 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
|
@@ -52,22 +53,30 @@ class Classic_Editor {
|
|
52 |
add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
|
53 |
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
|
54 |
|
55 |
-
if ( $
|
56 |
// User settings.
|
57 |
add_action( 'personal_options_update', array( __CLASS__, 'save_user_settings' ) );
|
58 |
add_action( 'profile_personal_options', array( __CLASS__, 'user_settings' ) );
|
59 |
}
|
60 |
}
|
61 |
|
62 |
-
if ( ! $
|
63 |
-
// For unsupported versions (less than 5.0), only show the admin settings.
|
64 |
-
// That will let admins to install the plugin and to configure it before upgrading WordPress.
|
65 |
return;
|
66 |
}
|
67 |
|
68 |
if ( $settings['allow-users'] ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
add_filter( 'get_edit_post_link', array( __CLASS__, 'get_edit_post_link' ) );
|
70 |
-
add_filter( 'use_block_editor_for_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
71 |
add_filter( 'redirect_post_location', array( __CLASS__, 'redirect_location' ) );
|
72 |
add_action( 'edit_form_top', array( __CLASS__, 'add_redirect_helper' ) );
|
73 |
add_action( 'admin_head-edit.php', array( __CLASS__, 'add_edit_php_inline_style' ) );
|
@@ -87,38 +96,99 @@ class Classic_Editor {
|
|
87 |
// add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
|
88 |
} else {
|
89 |
if ( $settings['editor'] === 'classic' ) {
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
} else {
|
93 |
// `$settings['editor'] === 'block'`, nothing to do :)
|
94 |
return;
|
95 |
}
|
96 |
}
|
97 |
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
// Move the Privacy Page notice back under the title.
|
102 |
-
add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) );
|
103 |
}
|
104 |
|
105 |
private static function get_settings( $refresh = 'no' ) {
|
106 |
/**
|
107 |
-
* Can be used to override the plugin's settings
|
108 |
*
|
109 |
* Has to return an associative array with two keys.
|
110 |
* The defaults are:
|
111 |
* 'editor' => 'classic', // Accepted values: 'classic', 'block'.
|
112 |
-
* 'allow-users' =>
|
113 |
*
|
114 |
-
*
|
115 |
*/
|
116 |
$settings = apply_filters( 'classic_editor_plugin_settings', false );
|
117 |
|
118 |
if ( is_array( $settings ) ) {
|
119 |
return array(
|
120 |
'editor' => ( isset( $settings['editor'] ) && $settings['editor'] === 'block' ) ? 'block' : 'classic',
|
121 |
-
'allow-users' =>
|
122 |
'hide-settings-ui' => true,
|
123 |
);
|
124 |
}
|
@@ -127,24 +197,49 @@ class Classic_Editor {
|
|
127 |
return self::$settings;
|
128 |
}
|
129 |
|
130 |
-
if ( is_multisite()
|
131 |
-
|
132 |
-
return array(
|
133 |
'editor' => 'classic',
|
134 |
'allow-users' => false,
|
135 |
-
'hide-settings-ui' => true,
|
136 |
);
|
137 |
-
}
|
138 |
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
$editor = 'block';
|
145 |
} else {
|
146 |
-
|
147 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
}
|
149 |
|
150 |
// Override the defaults with the user options.
|
@@ -273,11 +368,11 @@ class Classic_Editor {
|
|
273 |
<div class="classic-editor-options">
|
274 |
<p>
|
275 |
<input type="radio" name="classic-editor-replace" id="classic-editor-classic" value="classic"<?php if ( $settings['editor'] === 'classic' ) echo ' checked'; ?> />
|
276 |
-
<label for="classic-editor-classic"><?php
|
277 |
</p>
|
278 |
<p>
|
279 |
<input type="radio" name="classic-editor-replace" id="classic-editor-block" value="block"<?php if ( $settings['editor'] !== 'classic' ) echo ' checked'; ?> />
|
280 |
-
<label for="classic-editor-block"><?php
|
281 |
</p>
|
282 |
</div>
|
283 |
<script>
|
@@ -343,7 +438,7 @@ class Classic_Editor {
|
|
343 |
?>
|
344 |
<table class="form-table">
|
345 |
<tr>
|
346 |
-
<th scope="row"><?php
|
347 |
<td>
|
348 |
<?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?>
|
349 |
<input type="checkbox" name="classic-editor-allow-sites" id="classic-editor-allow-sites" value="allow"<?php if ( $is_checked ) echo ' checked'; ?>>
|
@@ -409,7 +504,9 @@ class Classic_Editor {
|
|
409 |
* Remember when the Classic Editor was used to edit a post.
|
410 |
*/
|
411 |
public static function remember_classic_editor( $post ) {
|
412 |
-
|
|
|
|
|
413 |
self::remember( $post->ID, 'classic-editor' );
|
414 |
}
|
415 |
}
|
@@ -418,7 +515,9 @@ class Classic_Editor {
|
|
418 |
* Remember when the Block Editor was used to edit a post.
|
419 |
*/
|
420 |
public static function remember_block_editor( $editor_settings, $post ) {
|
421 |
-
|
|
|
|
|
422 |
self::remember( $post->ID, 'block-editor' );
|
423 |
}
|
424 |
|
@@ -426,10 +525,7 @@ class Classic_Editor {
|
|
426 |
}
|
427 |
|
428 |
private static function remember( $post_id, $editor ) {
|
429 |
-
if (
|
430 |
-
use_block_editor_for_post_type( get_post_type( $post_id ) ) &&
|
431 |
-
get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor
|
432 |
-
) {
|
433 |
update_post_meta( $post_id, 'classic-editor-remember', $editor );
|
434 |
}
|
435 |
}
|
@@ -454,9 +550,13 @@ class Classic_Editor {
|
|
454 |
return $use_block_editor;
|
455 |
}
|
456 |
|
457 |
-
// Open the default editor when no $post and for "Add New" links
|
|
|
458 |
if ( empty( $post->ID ) || $post->post_status === 'auto-draft' ) {
|
459 |
-
if (
|
|
|
|
|
|
|
460 |
$use_block_editor = false;
|
461 |
}
|
462 |
} elseif ( self::is_classic( $post->ID ) ) {
|
@@ -466,7 +566,7 @@ class Classic_Editor {
|
|
466 |
// Enforce the editor if set by plugins.
|
467 |
if ( $use_block_editor && ! $editors['block_editor'] ) {
|
468 |
$use_block_editor = false;
|
469 |
-
} elseif ( ! $use_block_editor && ! $editors['classic_editor'] ) {
|
470 |
$use_block_editor = true;
|
471 |
}
|
472 |
|
@@ -525,7 +625,7 @@ class Classic_Editor {
|
|
525 |
|
526 |
if ( did_action( 'enqueue_block_editor_assets' ) ) {
|
527 |
// Block Editor is loading, switch to Classic Editor.
|
528 |
-
$edit_url = add_query_arg( 'classic-editor', $edit_url );
|
529 |
$link_text = __( 'Switch to Classic Editor', 'classic-editor' );
|
530 |
} else {
|
531 |
// Switch to Block Editor.
|
@@ -537,7 +637,7 @@ class Classic_Editor {
|
|
537 |
$edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url );
|
538 |
|
539 |
?>
|
540 |
-
<p style="margin: 1em;"><a href="<?php echo esc_url( $edit_url ); ?>"><?php echo $link_text; ?></a></p>
|
541 |
<?php
|
542 |
}
|
543 |
|
@@ -577,6 +677,18 @@ class Classic_Editor {
|
|
577 |
return $links;
|
578 |
}
|
579 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
/**
|
581 |
* Checks which editors are enabled for the post type.
|
582 |
*
|
@@ -589,7 +701,7 @@ class Classic_Editor {
|
|
589 |
}
|
590 |
|
591 |
$classic_editor = post_type_supports( $post_type, 'editor' );
|
592 |
-
$block_editor =
|
593 |
|
594 |
$editors = array(
|
595 |
'classic_editor' => $classic_editor,
|
@@ -674,14 +786,14 @@ class Classic_Editor {
|
|
674 |
|
675 |
// Link to the Block Editor.
|
676 |
$url = remove_query_arg( 'classic-editor', $edit_url );
|
677 |
-
$text =
|
678 |
/* translators: %s: post title */
|
679 |
$label = sprintf( __( 'Edit “%s” in the Block Editor', 'classic-editor' ), $title );
|
680 |
$edit_block = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
|
681 |
|
682 |
// Link to the Classic Editor.
|
683 |
$url = add_query_arg( 'classic-editor', '', $edit_url );
|
684 |
-
$text =
|
685 |
/* translators: %s: post title */
|
686 |
$label = sprintf( __( 'Edit “%s” in the Classic Editor', 'classic-editor' ), $title );
|
687 |
$edit_classic = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
|
@@ -708,10 +820,10 @@ class Classic_Editor {
|
|
708 |
return $post_states;
|
709 |
} elseif ( $editors['classic_editor'] && ! $editors['block_editor'] ) {
|
710 |
// Forced to Classic Editor.
|
711 |
-
$state = '<span class="classic-editor-forced-state">' .
|
712 |
} elseif ( ! $editors['classic_editor'] && $editors['block_editor'] ) {
|
713 |
// Forced to Block Editor.
|
714 |
-
$state = '<span class="classic-editor-forced-state">' .
|
715 |
} else {
|
716 |
$last_editor = get_post_meta( $post->ID, 'classic-editor-remember', true );
|
717 |
|
@@ -722,7 +834,7 @@ class Classic_Editor {
|
|
722 |
$is_classic = ( $settings['editor'] === 'classic' );
|
723 |
}
|
724 |
|
725 |
-
$state = $is_classic ?
|
726 |
}
|
727 |
|
728 |
(array) $post_states[] = $state;
|
@@ -764,21 +876,22 @@ class Classic_Editor {
|
|
764 |
* Set defaults on activation.
|
765 |
*/
|
766 |
public static function activate() {
|
767 |
-
if ( ! get_option( 'classic-editor-replace' ) ) {
|
768 |
-
update_option( 'classic-editor-replace', 'classic' );
|
769 |
-
}
|
770 |
-
if ( ! get_option( 'classic-editor-allow-users' ) ) {
|
771 |
-
update_option( 'classic-editor-allow-users', 'allow' );
|
772 |
-
}
|
773 |
if ( is_multisite() ) {
|
774 |
-
|
775 |
}
|
|
|
|
|
|
|
776 |
}
|
777 |
|
778 |
/**
|
779 |
* Delete the options on uninstall.
|
780 |
*/
|
781 |
public static function uninstall() {
|
|
|
|
|
|
|
|
|
782 |
delete_option( 'classic-editor-replace' );
|
783 |
delete_option( 'classic-editor-allow-users' );
|
784 |
}
|
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.2
|
9 |
* Author: WordPress Contributors
|
10 |
* Author URI: https://github.com/WordPress/classic-editor/
|
11 |
* License: GPLv2 or later
|
28 |
|
29 |
if ( ! class_exists( 'Classic_Editor' ) ) :
|
30 |
class Classic_Editor {
|
31 |
+
const plugin_version = 1.2;
|
32 |
private static $settings;
|
33 |
private static $supported_post_types = array();
|
34 |
|
35 |
private function __construct() {}
|
36 |
|
37 |
public static function init_actions() {
|
38 |
+
$block_editor = has_action( 'enqueue_block_assets' );
|
39 |
+
$gutenberg = function_exists( 'gutenberg_can_edit_post_type' );
|
40 |
|
41 |
register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) );
|
42 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) );
|
53 |
add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
|
54 |
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
|
55 |
|
56 |
+
if ( $settings['allow-users'] ) {
|
57 |
// User settings.
|
58 |
add_action( 'personal_options_update', array( __CLASS__, 'save_user_settings' ) );
|
59 |
add_action( 'profile_personal_options', array( __CLASS__, 'user_settings' ) );
|
60 |
}
|
61 |
}
|
62 |
|
63 |
+
if ( ! $block_editor && ! $gutenberg ) {
|
|
|
|
|
64 |
return;
|
65 |
}
|
66 |
|
67 |
if ( $settings['allow-users'] ) {
|
68 |
+
if ( $block_editor ) {
|
69 |
+
add_filter( 'use_block_editor_for_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
70 |
+
}
|
71 |
+
if ( $gutenberg ) {
|
72 |
+
add_filter( 'gutenberg_can_edit_post', array( __CLASS__, 'choose_editor' ), 100, 2 );
|
73 |
+
|
74 |
+
if ( $settings['editor'] === 'classic' ) {
|
75 |
+
self::remove_gutenberg_hooks( 'some' );
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
add_filter( 'get_edit_post_link', array( __CLASS__, 'get_edit_post_link' ) );
|
|
|
80 |
add_filter( 'redirect_post_location', array( __CLASS__, 'redirect_location' ) );
|
81 |
add_action( 'edit_form_top', array( __CLASS__, 'add_redirect_helper' ) );
|
82 |
add_action( 'admin_head-edit.php', array( __CLASS__, 'add_edit_php_inline_style' ) );
|
96 |
// add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
|
97 |
} else {
|
98 |
if ( $settings['editor'] === 'classic' ) {
|
99 |
+
if ( $block_editor ) {
|
100 |
+
// Consider disabling other Block Editor functionality.
|
101 |
+
add_filter( 'use_block_editor_for_post_type', '__return_false', 100 );
|
102 |
+
}
|
103 |
+
if ( $gutenberg ) {
|
104 |
+
add_filter( 'gutenberg_can_edit_post_type', '__return_false', 100 );
|
105 |
+
self::remove_gutenberg_hooks();
|
106 |
+
}
|
107 |
} else {
|
108 |
// `$settings['editor'] === 'block'`, nothing to do :)
|
109 |
return;
|
110 |
}
|
111 |
}
|
112 |
|
113 |
+
if ( $block_editor ) {
|
114 |
+
// Show warning on the "What's New" screen (about.php).
|
115 |
+
add_action( 'all_admin_notices', array( __CLASS__, 'notice_after_upgrade' ) );
|
116 |
+
// Move the Privacy Page notice back under the title.
|
117 |
+
add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) );
|
118 |
+
}
|
119 |
+
if ( $gutenberg ) {
|
120 |
+
// Always remove the "Try Gutenberg" dashboard widget. See https://core.trac.wordpress.org/ticket/44635.
|
121 |
+
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
|
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' );
|
126 |
+
remove_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state' );
|
127 |
+
remove_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
public static function remove_gutenberg_hooks( $remove = 'all' ) {
|
132 |
+
remove_action( 'admin_menu', 'gutenberg_menu' );
|
133 |
+
remove_action( 'admin_init', 'gutenberg_redirect_demo' );
|
134 |
+
|
135 |
+
if ( $remove !== 'all' ) {
|
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', 1000 );
|
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' );
|
152 |
+
remove_action( 'edit_form_advanced', 'gutenberg_intercept_meta_box_render' );
|
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' );
|
160 |
+
remove_filter( 'register_post_type_args', 'gutenberg_filter_post_type_labels' );
|
161 |
+
|
162 |
+
// Keep
|
163 |
+
// remove_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allowedtags', 10, 2 ); // not needed in 5.0
|
164 |
+
// remove_filter( 'bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions' );
|
165 |
+
// remove_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support' );
|
166 |
+
// remove_filter( 'the_content', 'do_blocks', 9 );
|
167 |
+
// remove_action( 'init', 'gutenberg_register_post_types' );
|
168 |
+
|
169 |
+
// Continue to manage wpautop for posts that were edited in Gutenberg.
|
170 |
+
// remove_filter( 'wp_editor_settings', 'gutenberg_disable_editor_settings_wpautop' );
|
171 |
+
// remove_filter( 'the_content', 'gutenberg_wpautop', 8 );
|
172 |
|
|
|
|
|
173 |
}
|
174 |
|
175 |
private static function get_settings( $refresh = 'no' ) {
|
176 |
/**
|
177 |
+
* Can be used to override the plugin's settings. Always hides the settings UI when used (as users cannot change the settings).
|
178 |
*
|
179 |
* Has to return an associative array with two keys.
|
180 |
* The defaults are:
|
181 |
* 'editor' => 'classic', // Accepted values: 'classic', 'block'.
|
182 |
+
* 'allow-users' => false,
|
183 |
*
|
184 |
+
* @param boolean To override the settings return an array with the above keys.
|
185 |
*/
|
186 |
$settings = apply_filters( 'classic_editor_plugin_settings', false );
|
187 |
|
188 |
if ( is_array( $settings ) ) {
|
189 |
return array(
|
190 |
'editor' => ( isset( $settings['editor'] ) && $settings['editor'] === 'block' ) ? 'block' : 'classic',
|
191 |
+
'allow-users' => ! empty( $settings['allow-users'] ),
|
192 |
'hide-settings-ui' => true,
|
193 |
);
|
194 |
}
|
197 |
return self::$settings;
|
198 |
}
|
199 |
|
200 |
+
if ( is_multisite() ) {
|
201 |
+
$defaults = array(
|
|
|
202 |
'editor' => 'classic',
|
203 |
'allow-users' => false,
|
|
|
204 |
);
|
|
|
205 |
|
206 |
+
/**
|
207 |
+
* Filters the default network options.
|
208 |
+
*
|
209 |
+
* @param array $defaults The default options array. See `classic_editor_plugin_settings` for supported keys and values.
|
210 |
+
*/
|
211 |
+
$defaults = apply_filters( 'classic_editor_network_default_settings', $defaults );
|
212 |
+
|
213 |
+
if ( get_network_option( null, 'classic-editor-allow-sites' ) !== 'allow' ) {
|
214 |
+
// Per-site settings are disabled. Return default network options nad hide the settings UI.
|
215 |
+
$defaults['hide-settings-ui'] = true;
|
216 |
+
return $defaults;
|
217 |
+
}
|
218 |
+
|
219 |
+
// Override with the site options.
|
220 |
+
$editor_option = get_option( 'classic-editor-replace' );
|
221 |
+
$allow_users_option = get_option( 'classic-editor-allow-users' );
|
222 |
+
|
223 |
+
if ( $editor_option ) {
|
224 |
+
$defaults['editor'] = $editor_option;
|
225 |
+
}
|
226 |
+
if ( $allow_users_option ) {
|
227 |
+
$defaults['allow-users'] = ( $allow_users_option === 'allow' );
|
228 |
+
}
|
229 |
|
230 |
+
$editor = ( isset( $defaults['editor'] ) && $defaults['editor'] === 'block' ) ? 'block' : 'classic';
|
231 |
+
$allow_users = ! empty( $defaults['allow-users'] );
|
|
|
232 |
} else {
|
233 |
+
$allow_users = ( get_option( 'classic-editor-allow-users' ) === 'allow' );
|
234 |
+
$option = get_option( 'classic-editor-replace' );
|
235 |
+
|
236 |
+
// Normalize old options.
|
237 |
+
if ( $option === 'block' || $option === 'no-replace' ) {
|
238 |
+
$editor = 'block';
|
239 |
+
} else {
|
240 |
+
// empty( $option ) || $option === 'classic' || $option === 'replace'.
|
241 |
+
$editor = 'classic';
|
242 |
+
}
|
243 |
}
|
244 |
|
245 |
// Override the defaults with the user options.
|
368 |
<div class="classic-editor-options">
|
369 |
<p>
|
370 |
<input type="radio" name="classic-editor-replace" id="classic-editor-classic" value="classic"<?php if ( $settings['editor'] === 'classic' ) echo ' checked'; ?> />
|
371 |
+
<label for="classic-editor-classic"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></label>
|
372 |
</p>
|
373 |
<p>
|
374 |
<input type="radio" name="classic-editor-replace" id="classic-editor-block" value="block"<?php if ( $settings['editor'] !== 'classic' ) echo ' checked'; ?> />
|
375 |
+
<label for="classic-editor-block"><?php _ex( 'Block Editor', 'Editor Name', 'classic-editor' ); ?></label>
|
376 |
</p>
|
377 |
</div>
|
378 |
<script>
|
438 |
?>
|
439 |
<table class="form-table">
|
440 |
<tr>
|
441 |
+
<th scope="row"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></th>
|
442 |
<td>
|
443 |
<?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?>
|
444 |
<input type="checkbox" name="classic-editor-allow-sites" id="classic-editor-allow-sites" value="allow"<?php if ( $is_checked ) echo ' checked'; ?>>
|
504 |
* Remember when the Classic Editor was used to edit a post.
|
505 |
*/
|
506 |
public static function remember_classic_editor( $post ) {
|
507 |
+
$post_type = get_post_type( $post );
|
508 |
+
|
509 |
+
if ( $post_type && post_type_supports( $post_type, 'editor' ) ) {
|
510 |
self::remember( $post->ID, 'classic-editor' );
|
511 |
}
|
512 |
}
|
515 |
* Remember when the Block Editor was used to edit a post.
|
516 |
*/
|
517 |
public static function remember_block_editor( $editor_settings, $post ) {
|
518 |
+
$post_type = get_post_type( $post );
|
519 |
+
|
520 |
+
if ( $post_type && self::can_edit_post_type( $post_type ) ) {
|
521 |
self::remember( $post->ID, 'block-editor' );
|
522 |
}
|
523 |
|
525 |
}
|
526 |
|
527 |
private static function remember( $post_id, $editor ) {
|
528 |
+
if ( get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor ) {
|
|
|
|
|
|
|
529 |
update_post_meta( $post_id, 'classic-editor-remember', $editor );
|
530 |
}
|
531 |
}
|
550 |
return $use_block_editor;
|
551 |
}
|
552 |
|
553 |
+
// Open the default editor when no $post and for "Add New" links,
|
554 |
+
// or the alternate editor when the user is switching editors.
|
555 |
if ( empty( $post->ID ) || $post->post_status === 'auto-draft' ) {
|
556 |
+
if (
|
557 |
+
( $settings['editor'] === 'classic' && ! isset( $_GET['classic-editor__forget'] ) ) || // Add New
|
558 |
+
( isset( $_GET['classic-editor'] ) && isset( $_GET['classic-editor__forget'] ) ) // Switch to Classic Editor when no draft post.
|
559 |
+
) {
|
560 |
$use_block_editor = false;
|
561 |
}
|
562 |
} elseif ( self::is_classic( $post->ID ) ) {
|
566 |
// Enforce the editor if set by plugins.
|
567 |
if ( $use_block_editor && ! $editors['block_editor'] ) {
|
568 |
$use_block_editor = false;
|
569 |
+
} elseif ( ! $use_block_editor && ! $editors['classic_editor'] && $editors['block_editor'] ) {
|
570 |
$use_block_editor = true;
|
571 |
}
|
572 |
|
625 |
|
626 |
if ( did_action( 'enqueue_block_editor_assets' ) ) {
|
627 |
// Block Editor is loading, switch to Classic Editor.
|
628 |
+
$edit_url = add_query_arg( 'classic-editor', '', $edit_url );
|
629 |
$link_text = __( 'Switch to Classic Editor', 'classic-editor' );
|
630 |
} else {
|
631 |
// Switch to Block Editor.
|
637 |
$edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url );
|
638 |
|
639 |
?>
|
640 |
+
<p style="margin: 1em 0;"><a href="<?php echo esc_url( $edit_url ); ?>"><?php echo $link_text; ?></a></p>
|
641 |
<?php
|
642 |
}
|
643 |
|
677 |
return $links;
|
678 |
}
|
679 |
|
680 |
+
private static function can_edit_post_type( $post_type ) {
|
681 |
+
$can_edit = false;
|
682 |
+
|
683 |
+
if ( function_exists( 'gutenberg_can_edit_post_type' ) ) {
|
684 |
+
$can_edit = gutenberg_can_edit_post_type( $post_type );
|
685 |
+
} elseif ( function_exists( 'use_block_editor_for_post_type' ) ) {
|
686 |
+
$can_edit = use_block_editor_for_post_type( $post_type );
|
687 |
+
}
|
688 |
+
|
689 |
+
return $can_edit;
|
690 |
+
}
|
691 |
+
|
692 |
/**
|
693 |
* Checks which editors are enabled for the post type.
|
694 |
*
|
701 |
}
|
702 |
|
703 |
$classic_editor = post_type_supports( $post_type, 'editor' );
|
704 |
+
$block_editor = self::can_edit_post_type( $post_type );
|
705 |
|
706 |
$editors = array(
|
707 |
'classic_editor' => $classic_editor,
|
786 |
|
787 |
// Link to the Block Editor.
|
788 |
$url = remove_query_arg( 'classic-editor', $edit_url );
|
789 |
+
$text = _x( 'Block Editor', 'Editor Name', 'classic-editor' );
|
790 |
/* translators: %s: post title */
|
791 |
$label = sprintf( __( 'Edit “%s” in the Block Editor', 'classic-editor' ), $title );
|
792 |
$edit_block = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
|
793 |
|
794 |
// Link to the Classic Editor.
|
795 |
$url = add_query_arg( 'classic-editor', '', $edit_url );
|
796 |
+
$text = _x( 'Classic Editor', 'Editor Name', 'classic-editor' );
|
797 |
/* translators: %s: post title */
|
798 |
$label = sprintf( __( 'Edit “%s” in the Classic Editor', 'classic-editor' ), $title );
|
799 |
$edit_classic = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
|
820 |
return $post_states;
|
821 |
} elseif ( $editors['classic_editor'] && ! $editors['block_editor'] ) {
|
822 |
// Forced to Classic Editor.
|
823 |
+
$state = '<span class="classic-editor-forced-state">' . _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) . '</span>';
|
824 |
} elseif ( ! $editors['classic_editor'] && $editors['block_editor'] ) {
|
825 |
// Forced to Block Editor.
|
826 |
+
$state = '<span class="classic-editor-forced-state">' . _x( 'Block Editor', 'Editor Name', 'classic-editor' ) . '</span>';
|
827 |
} else {
|
828 |
$last_editor = get_post_meta( $post->ID, 'classic-editor-remember', true );
|
829 |
|
834 |
$is_classic = ( $settings['editor'] === 'classic' );
|
835 |
}
|
836 |
|
837 |
+
$state = $is_classic ? _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) : _x( 'Block Editor', 'Editor Name', 'classic-editor' );
|
838 |
}
|
839 |
|
840 |
(array) $post_states[] = $state;
|
876 |
* Set defaults on activation.
|
877 |
*/
|
878 |
public static function activate() {
|
|
|
|
|
|
|
|
|
|
|
|
|
879 |
if ( is_multisite() ) {
|
880 |
+
add_network_option( null, 'classic-editor-allow-sites', 'disallow' );
|
881 |
}
|
882 |
+
|
883 |
+
add_option( 'classic-editor-replace', 'classic' );
|
884 |
+
add_option( 'classic-editor-allow-users', 'disallow' );
|
885 |
}
|
886 |
|
887 |
/**
|
888 |
* Delete the options on uninstall.
|
889 |
*/
|
890 |
public static function uninstall() {
|
891 |
+
if ( is_multisite() ) {
|
892 |
+
delete_network_option( null, 'classic-editor-allow-sites' );
|
893 |
+
}
|
894 |
+
|
895 |
delete_option( 'classic-editor-replace' );
|
896 |
delete_option( 'classic-editor-allow-users' );
|
897 |
}
|
readme.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
=== Classic Editor ===
|
2 |
Contributors: azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce
|
3 |
Tags: editor, classic editor, block editor, gutenberg
|
4 |
-
Requires at least:
|
5 |
Tested up to: 5.0
|
6 |
Stable tag: 1.1
|
7 |
Requires PHP: 5.2.4
|
@@ -22,48 +22,54 @@ At a glance, this plugin adds the following:
|
|
22 |
* When allowed, the users can choose which editor to use for each post.
|
23 |
* Each post opens in the last editor used regardless of who edited it last. This is important for maintaining a consistent experience when editing content.
|
24 |
|
25 |
-
The Classic Editor plugin supports WordPress version 4.9, so it can be installed and configured before WordPress is upgraded to version 5.0. In this case, only the admin settings are visible.
|
26 |
-
|
27 |
In addition, the Classic Editor plugin includes several filters that let other plugins control the settings, and the editor choice per post and per post type.
|
28 |
|
29 |
Classic Editor is an official WordPress plugin, and will be maintained until at least 2022.
|
30 |
|
31 |
== Changelog ==
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
= 1.1 =
|
34 |
Fixed a bug where it may attempt to load the Block Editor for post types that do not support editor when users are allowed to switch editors.
|
35 |
|
36 |
= 1.0 =
|
37 |
-
Updated for WordPress 5.0.
|
38 |
-
Changed all "Gutenberg" names/references to "Block Editor".
|
39 |
-
Refreshed the settings UI.
|
40 |
-
Removed disabling of the Gutenberg plugin. This was added for testing in WordPress 4.9. Users who want to continue following the development of Gutenberg in WordPress 5.0 and beyond will not need another plugin to disable it.
|
41 |
-
Added support for per-user settings of default editor.
|
42 |
-
Added support for admins to set the default editor for the site.
|
43 |
-
Added support for admins to allow users to change their default editor.
|
44 |
-
Added support for network admins to prevent site admins from changing the default settings.
|
45 |
-
Added support to store the last editor used for each post and open it next time. Enabled when users can choose default editor.
|
46 |
-
Added "post editor state" in the listing of posts on the Posts screen. Shows the editor that will be opened for the post. Enabled when users can choose default editor.
|
47 |
-
Added `classic_editor_enabled_editors_for_post` and `classic_editor_enabled_editors_for_post_type` filters. Can be used by other plugins to control or override the editor used for a particular post of post type.
|
48 |
-
Added `classic_editor_plugin_settings` filter. Can be used by other plugins to override the settings and disable the settings UI.
|
49 |
|
50 |
= 0.5 =
|
51 |
-
Updated for Gutenberg 4.1 and WordPress 5.0-beta1.
|
52 |
-
Removed some functionality that now exists in Gutenberg.
|
53 |
-
Fixed redirecting back to the
|
54 |
|
55 |
= 0.4 =
|
56 |
-
Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated.
|
57 |
-
Fixed to always show the settings and the settings link in the plugins list table.
|
58 |
-
Updated the readme text.
|
59 |
|
60 |
= 0.3 =
|
61 |
-
Updated the option from a checkbox to couple of radio buttons, seems clearer. Thanks to @designsimply for the label text suggestions.
|
62 |
-
Some general updates and cleanup.
|
63 |
|
64 |
= 0.2 =
|
65 |
-
Update for Gutenberg 1.9.
|
66 |
-
Remove warning and automatic deactivation when Gutenberg is not active.
|
67 |
|
68 |
= 0.1 =
|
69 |
Initial release.
|
1 |
=== Classic Editor ===
|
2 |
Contributors: azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce
|
3 |
Tags: editor, classic editor, block editor, gutenberg
|
4 |
+
Requires at least: 4.9
|
5 |
Tested up to: 5.0
|
6 |
Stable tag: 1.1
|
7 |
Requires PHP: 5.2.4
|
22 |
* When allowed, the users can choose which editor to use for each post.
|
23 |
* Each post opens in the last editor used regardless of who edited it last. This is important for maintaining a consistent experience when editing content.
|
24 |
|
|
|
|
|
25 |
In addition, the Classic Editor plugin includes several filters that let other plugins control the settings, and the editor choice per post and per post type.
|
26 |
|
27 |
Classic Editor is an official WordPress plugin, and will be maintained until at least 2022.
|
28 |
|
29 |
== Changelog ==
|
30 |
|
31 |
+
= 1.2 =
|
32 |
+
* Fixed switching editors from the Add New (post) screen before a draft post is saved.
|
33 |
+
* Fixed typo that was appending the edit URL to the `classic-editor` query var.
|
34 |
+
* Changed detecting of WordPress 5.0 to not use version check. Fixes a bug when testing 5.1-alpha.
|
35 |
+
* Changed the default value of the option to allow users to switch editors to false.
|
36 |
+
* Added disabling of the Gutenberg plugin and lowered the required WordPress version to 4.9.
|
37 |
+
* Added `classic_editor_network_default_settings` filter.
|
38 |
+
|
39 |
= 1.1 =
|
40 |
Fixed a bug where it may attempt to load the Block Editor for post types that do not support editor when users are allowed to switch editors.
|
41 |
|
42 |
= 1.0 =
|
43 |
+
* Updated for WordPress 5.0.
|
44 |
+
* Changed all "Gutenberg" names/references to "Block Editor".
|
45 |
+
* Refreshed the settings UI.
|
46 |
+
* Removed disabling of the Gutenberg plugin. This was added for testing in WordPress 4.9. Users who want to continue following the development of Gutenberg in WordPress 5.0 and beyond will not need another plugin to disable it.
|
47 |
+
* Added support for per-user settings of default editor.
|
48 |
+
* Added support for admins to set the default editor for the site.
|
49 |
+
* Added support for admins to allow users to change their default editor.
|
50 |
+
* Added support for network admins to prevent site admins from changing the default settings.
|
51 |
+
* Added support to store the last editor used for each post and open it next time. Enabled when users can choose default editor.
|
52 |
+
* Added "post editor state" in the listing of posts on the Posts screen. Shows the editor that will be opened for the post. Enabled when users can choose default editor.
|
53 |
+
* Added `classic_editor_enabled_editors_for_post` and `classic_editor_enabled_editors_for_post_type` filters. Can be used by other plugins to control or override the editor used for a particular post of post type.
|
54 |
+
* Added `classic_editor_plugin_settings` filter. Can be used by other plugins to override the settings and disable the settings UI.
|
55 |
|
56 |
= 0.5 =
|
57 |
+
* Updated for Gutenberg 4.1 and WordPress 5.0-beta1.
|
58 |
+
* Removed some functionality that now exists in Gutenberg.
|
59 |
+
* Fixed redirecting back to the Classic editor after looking at post revisions.
|
60 |
|
61 |
= 0.4 =
|
62 |
+
* Fixed removing of the "Try Gutenberg" call-out when the Gutenberg plugin is not activated.
|
63 |
+
* Fixed to always show the settings and the settings link in the plugins list table.
|
64 |
+
* Updated the readme text.
|
65 |
|
66 |
= 0.3 =
|
67 |
+
* Updated the option from a checkbox to couple of radio buttons, seems clearer. Thanks to @designsimply for the label text suggestions.
|
68 |
+
* Some general updates and cleanup.
|
69 |
|
70 |
= 0.2 =
|
71 |
+
* Update for Gutenberg 1.9.
|
72 |
+
* Remove warning and automatic deactivation when Gutenberg is not active.
|
73 |
|
74 |
= 0.1 =
|
75 |
Initial release.
|