Commit db23ab19 authored by lucha's avatar lucha

[auto] plugin: classic-editor 1.4

parent fd9795a8
### WordPress - Web publishing software
Copyright 2011-2018 by the contributors
Copyright 2011-2019 by the contributors
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
......@@ -5,14 +5,13 @@
* Plugin Name: Classic Editor
* Plugin URI: https://wordpress.org/plugins/classic-editor/
* 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.
* Version: 1.3
* Version: 1.4
* Author: WordPress Contributors
* Author URI: https://github.com/WordPress/classic-editor/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: classic-editor
* Domain Path: /languages
* Network: true
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
......@@ -28,7 +27,6 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'Classic_Editor' ) ) :
class Classic_Editor {
const plugin_version = 1.2;
private static $settings;
private static $supported_post_types = array();
......@@ -49,8 +47,10 @@ class Classic_Editor {
}
if ( ! $settings['hide-settings-ui'] ) {
// Show the plugin's admin settings, and a link to them in the plugins list table.
// Add a link to the plugin's settings and/or network admin settings in the plugins list table.
add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
add_filter( 'network_admin_plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
if ( $settings['allow-users'] ) {
......@@ -95,8 +95,7 @@ class Classic_Editor {
// Switch editors while editing a post
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_box' ), 10, 2 );
// TODO: needs https://github.com/WordPress/gutenberg/pull/12309
// add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'enqueue_block_editor_scripts' ) );
} else {
if ( $settings['editor'] === 'classic' ) {
if ( $block_editor ) {
......@@ -200,7 +199,7 @@ class Classic_Editor {
if ( is_multisite() ) {
$defaults = array(
'editor' => 'classic',
'editor' => get_network_option( null, 'classic-editor-replace' ) === 'block' ? 'block' : 'classic',
'allow-users' => false,
);
......@@ -422,7 +421,7 @@ class Classic_Editor {
?>
<table class="form-table">
<tr class="classic-editor-user-options">
<th scope="row"><?php _e( 'Editor', 'classic-editor' ); ?></th>
<th scope="row"><?php _e( 'Default Editor', 'classic-editor' ); ?></th>
<td>
<?php wp_nonce_field( 'allow-user-settings', 'classic-editor-user-settings' ); ?>
<?php self::settings_1(); ?>
......@@ -434,17 +433,32 @@ class Classic_Editor {
}
public static function network_settings() {
$is_checked = ( get_network_option( null, 'classic-editor-allow-sites' ) === 'allow' );
$editor = get_network_option( null, 'classic-editor-replace' );
$is_checked = ( get_network_option( null, 'classic-editor-allow-sites' ) === 'allow' );
?>
<h2 id="classic-editor-options"><?php _e( 'Editor Settings', 'classic-editor' ); ?></h2>
<table class="form-table">
<?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?>
<tr>
<th scope="row"><?php _e( 'Default editor for all sites', 'classic-editor' ); ?></th>
<td>
<p>
<input type="radio" name="classic-editor-replace" id="classic-editor-classic" value="classic"<?php if ( $editor !== 'block' ) echo ' checked'; ?> />
<label for="classic-editor-classic"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></label>
</p>
<p>
<input type="radio" name="classic-editor-replace" id="classic-editor-block" value="block"<?php if ( $editor === 'block' ) echo ' checked'; ?> />
<label for="classic-editor-block"><?php _ex( 'Block Editor', 'Editor Name', 'classic-editor' ); ?></label>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></th>
<th scope="row"><?php _e( 'Change settings', 'classic-editor' ); ?></th>
<td>
<?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?>
<input type="checkbox" name="classic-editor-allow-sites" id="classic-editor-allow-sites" value="allow"<?php if ( $is_checked ) echo ' checked'; ?>>
<label for="classic-editor-allow-sites"><?php _e( 'Allow site admins to change settings', 'classic-editor' ); ?></label>
<p class="description"><?php _e( 'By default the Block Editor is replaced with the Classic Editor and users cannot switch editors.', 'classic-editor' ); ?></p>
<input type="checkbox" name="classic-editor-allow-sites" id="classic-editor-allow-sites" value="allow"<?php if ( $is_checked ) echo ' checked'; ?>>
<label for="classic-editor-allow-sites"><?php _e( 'Allow site admins to change settings', 'classic-editor' ); ?></label>
<p class="description"><?php _e( 'By default the Block Editor is replaced with the Classic Editor and users cannot switch editors.', 'classic-editor' ); ?></p>
</td>
</tr>
</table>
......@@ -457,6 +471,11 @@ class Classic_Editor {
current_user_can( 'manage_network_options' ) &&
wp_verify_nonce( $_POST['classic-editor-network-settings'], 'allow-site-admin-settings' )
) {
if ( isset( $_POST['classic-editor-replace'] ) && $_POST['classic-editor-replace'] === 'block' ) {
update_network_option( null, 'classic-editor-replace', 'block' );
} else {
update_network_option( null, 'classic-editor-replace', 'classic' );
}
if ( isset( $_POST['classic-editor-allow-sites'] ) && $_POST['classic-editor-allow-sites'] === 'allow' ) {
update_network_option( null, 'classic-editor-allow-sites', 'allow' );
} else {
......@@ -472,7 +491,7 @@ class Classic_Editor {
if (
$pagenow !== 'about.php' ||
$settings['hide-settings-ui'] ||
$settings['editor'] === 'block' ||
$settings['editor'] === 'block' ||
$settings['allow-users'] ||
! current_user_can( 'edit_posts' )
) {
......@@ -485,7 +504,13 @@ class Classic_Editor {
$message = __( 'The Classic Editor plugin prevents use of the new Block Editor.', 'classic-editor' );
if ( current_user_can( 'manage_options' ) ) {
$message .= ' ' . sprintf( __( 'Change the %1$sClassic Editor settings%2$s.', 'classic-editor' ), '<a href="options-writing.php#classic-editor-options">', '</a>' );
if ( is_network_admin() ) {
$url = 'settings.php#classic-editor-options';
} else {
$url = 'options-writing.php#classic-editor-options';
}
$message .= ' ' . sprintf( __( 'Change the %1$sClassic Editor settings%2$s.', 'classic-editor' ), sprintf( '<a href="%s">', $url ), '</a>' );
}
$margin = is_rtl() ? 'margin: 1em 0 0 160px;' : 'margin: 1em 160px 0 0;';
......@@ -618,33 +643,25 @@ class Classic_Editor {
$id = 'classic-editor-switch-editor';
$title = __( 'Editor', 'classic-editor' );
$callback = array( __CLASS__, 'do_meta_box' );
/* Add when the Block Editor plugin is enabled.
$args = array(
'__back_compat_meta_box' => true,
);
*/
add_meta_box( $id, $title, $callback, null, 'side', 'default' );
add_meta_box( $id, $title, $callback, null, 'side', 'default', $args );
}
public static function do_meta_box( $post ) {
$edit_url = get_edit_post_link( $post->ID, 'raw' );
if ( did_action( 'enqueue_block_editor_assets' ) ) {
// Block Editor is loading, switch to Classic Editor.
$edit_url = add_query_arg( 'classic-editor', '', $edit_url );
$link_text = __( 'Switch to Classic Editor', 'classic-editor' );
} else {
// Switch to Block Editor.
$edit_url = remove_query_arg( 'classic-editor', $edit_url );
$link_text = __( 'Switch to Block Editor', 'classic-editor' );
}
// Switching to Block Editor.
$edit_url = remove_query_arg( 'classic-editor', $edit_url );
// Forget the previous value when going to a specific editor.
$edit_url = add_query_arg( 'classic-editor__forget', '', $edit_url );
?>
<p style="margin: 1em 0;"><a href="<?php echo esc_url( $edit_url ); ?>"><?php echo $link_text; ?></a></p>
<p style="margin: 1em 0;">
<a href="<?php echo esc_url( $edit_url ); ?>"><?php _e( 'Switch to Block Editor', 'classic-editor' ); ?></a>
</p>
<?php
}
......@@ -657,15 +674,15 @@ class Classic_Editor {
}
wp_enqueue_script(
'classic-editor-add-submenu',
'classic-editor-plugin',
plugins_url( 'js/block-editor-plugin.js', __FILE__ ),
array( 'wp-element', 'wp-components', 'lodash' ),
self::plugin_version,
'1.4',
true
);
wp_localize_script(
'classic-editor-add-submenu',
'classic-editor-plugin',
'classicEditorPluginL10n',
array( 'linkText' => __( 'Switch to Classic Editor', 'classic-editor' ) )
);
......@@ -678,7 +695,15 @@ class Classic_Editor {
$settings = self::get_settings();
if ( $file === 'classic-editor/classic-editor.php' && ! $settings['hide-settings-ui'] && current_user_can( 'manage_options' ) ) {
(array) $links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-writing.php#classic-editor-options' ), __( 'Settings', 'classic-editor' ) );
if ( current_filter() === 'plugin_action_links' ) {
$url = admin_url( 'options-writing.php#classic-editor-options' );
} else {
$url = admin_url( '/network/settings.php#classic-editor-options' );
}
// Prevent warnings in PHP 7.0+ when a plugin uses this filter incorrectly.
$links = (array) $links;
$links[] = sprintf( '<a href="%s">%s</a>', $url, __( 'Settings', 'classic-editor' ) );
}
return $links;
......@@ -793,14 +818,14 @@ class Classic_Editor {
// Link to the Block Editor.
$url = remove_query_arg( 'classic-editor', $edit_url );
$text = _x( 'Block Editor', 'Editor Name', 'classic-editor' );
$text = _x( 'Edit (Block Editor)', 'Editor Name', 'classic-editor' );
/* translators: %s: post title */
$label = sprintf( __( 'Edit &#8220;%s&#8221; in the Block Editor', 'classic-editor' ), $title );
$edit_block = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
// Link to the Classic Editor.
$url = add_query_arg( 'classic-editor', '', $edit_url );
$text = _x( 'Classic Editor', 'Editor Name', 'classic-editor' );
$text = _x( 'Edit (Classic Editor)', 'Editor Name', 'classic-editor' );
/* translators: %s: post title */
$label = sprintf( __( 'Edit &#8220;%s&#8221; in the Classic Editor', 'classic-editor' ), $title );
$edit_classic = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $url ), esc_attr( $label ), $text );
......@@ -884,6 +909,7 @@ class Classic_Editor {
*/
public static function activate() {
if ( is_multisite() ) {
add_network_option( null, 'classic-editor-replace', 'classic' );
add_network_option( null, 'classic-editor-allow-sites', 'disallow' );
}
......@@ -896,6 +922,7 @@ class Classic_Editor {
*/
public static function uninstall() {
if ( is_multisite() ) {
delete_network_option( null, 'classic-editor-replace' );
delete_network_option( null, 'classic-editor-allow-sites' );
}
......
( function() {
const { get } = lodash;
const { createElement } = wp.element;
const { PluginMoreMenuItem } = wp.editPost;
const { addQueryArgs } = wp.url;
const { registerPlugin } = wp.plugins;
( function( wp ) {
if ( ! wp ) {
return;
}
registerPlugin( 'classic-editor-add-submenu', {
wp.plugins.registerPlugin( 'classic-editor-plugin', {
render() {
const url = addQueryArgs( document.location.href, { 'classic-editor': null } );
const linkText = get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to Classic Editor';
var createElement = wp.element.createElement;
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem;
var url = wp.url.addQueryArgs( document.location.href, { 'classic-editor': '', 'classic-editor__forget': '' } );
var linkText = lodash.get( window, [ 'classicEditorPluginL10n', 'linkText' ] ) || 'Switch to Classic Editor';
return createElement(
PluginMoreMenuItem,
{
icon: 'editor-kitchensink',
url: url,
href: url,
},
linkText
);
},
} );
} )();
} )( window.wp );
......@@ -29,6 +29,12 @@ By default, this plugin hides all functionality available in the new Block Edito
== Changelog ==
= 1.4 =
* On network installations removed the restriction for only network activation.
* Added support for network administrators to choose the default network-wide editor.
* Fixed the settings link in the warning on network About screen.
* Properly added the "Switch to Classic Editor" menu item to the Block Editor menu.
= 1.3 =
* Fixed removal of the "Try Gutenberg" dashboard widget.
* Fixed condition for displaying of the after upgrade notice on the "What's New" screen. Shown when the Classic Editor is selected and users cannot switch editors.
......@@ -79,10 +85,30 @@ Fixed a bug where it may attempt to load the Block Editor for post types that do
= 0.1 =
Initial release.
== Frequently Asked Questions ==
= Default settings =
When activated this plugin will restore the previous ("classic") WordPress editor and hide the new Block Editor ("Gutenberg").
These settings can be changed at the Settings => Writing screen.
= Default settings for network installation =
There are two options:
* When network-activated this plugin will set the Classic Editor as default and prevent site administrators and users from changing editors.
The settings can be changed and default network-wide editor can be selected on the Network Settings screen.
* When not network-activated each site administrator will be able to activate the plugin and choose options for their users.
= Cannot find the "Switch to Classic Editor" link =
It is in the main Block Editor menu, see this [screenshot](https://ps.w.org/classic-editor/assets/screenshot-7.png?rev=2023480).
== Screenshots ==
1. Admin settings on the Settings -> Writing screen.
2. User settings on the Profile screen. Visible when the users are allowed to switch editors.
3. "Action links" to choose alternative editor. Visible when the users are allowed to switch editors.
4. Link to switch to the Block Editor while editing a post in the Classic Editor. Visible when the users are allowed to switch editors.
5. Link to switch to the Classic Editor while editing a post in the Block Editor. Visible when the users are allowed to switch editors.
6. Network setting to allow site admins to change the default options.
6. Network settings to select the default editor for the network and allow site admins to change it.
7. The "Switch to Classic Editor" link.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment