Changeset 1989286
- Timestamp:
- 12/08/2018 02:44:57 PM (7 years ago)
- Location:
- classic-editor/trunk
- Files:
-
- 2 edited
-
classic-editor.php (modified) (25 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
classic-editor/trunk/classic-editor.php
r1987367 r1989286 6 6 * Plugin URI: https://wordpress.org/plugins/classic-editor/ 7 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. 08 * Version: 1.2 9 9 * Author: WordPress Contributors 10 10 * Author URI: https://github.com/WordPress/classic-editor/ … … 36 36 37 37 public static function init_actions() { 38 $supported_wp_version = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ); 38 $block_editor = has_action( 'enqueue_block_assets' ); 39 $gutenberg = function_exists( 'gutenberg_can_edit_post_type' ); 39 40 40 41 register_activation_hook( __FILE__, array( __CLASS__, 'activate' ) ); … … 53 54 add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); 54 55 55 if ( $s upported_wp_version && $settings['allow-users'] ) {56 if ( $settings['allow-users'] ) { 56 57 // User settings. 57 58 add_action( 'personal_options_update', array( __CLASS__, 'save_user_settings' ) ); … … 60 61 } 61 62 62 if ( ! $supported_wp_version ) { 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. 63 if ( ! $block_editor && ! $gutenberg ) { 65 64 return; 66 65 } 67 66 68 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 69 79 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 80 add_filter( 'redirect_post_location', array( __CLASS__, 'redirect_location' ) ); 72 81 add_action( 'edit_form_top', array( __CLASS__, 'add_redirect_helper' ) ); … … 88 97 } else { 89 98 if ( $settings['editor'] === 'classic' ) { 90 // Consider disabling other Block Editor functionality. 91 add_filter( 'use_block_editor_for_post_type', '__return_false', 100 ); 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 } 92 107 } else { 93 108 // `$settings['editor'] === 'block'`, nothing to do :) … … 96 111 } 97 112 98 // Show warning on the "What's New" screen (about.php). 99 add_action( 'all_admin_notices', array( __CLASS__, 'notice_after_upgrade' ) ); 100 101 // Move the Privacy Page notice back under the title. 102 add_action( 'admin_init', array( __CLASS__, 'on_admin_init' ) ); 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 103 173 } 104 174 105 175 private static function get_settings( $refresh = 'no' ) { 106 176 /** 107 * Can be used to override the plugin's settings and hide the settings UI.177 * Can be used to override the plugin's settings. Always hides the settings UI when used (as users cannot change the settings). 108 178 * 109 179 * Has to return an associative array with two keys. 110 180 * The defaults are: 111 181 * 'editor' => 'classic', // Accepted values: 'classic', 'block'. 112 * 'allow-users' => true,182 * 'allow-users' => false, 113 183 * 114 * Note: using this filter always hides the settings UI (as it overrides the user's choices).184 * @param boolean To override the settings return an array with the above keys. 115 185 */ 116 186 $settings = apply_filters( 'classic_editor_plugin_settings', false ); … … 119 189 return array( 120 190 'editor' => ( isset( $settings['editor'] ) && $settings['editor'] === 'block' ) ? 'block' : 'classic', 121 'allow-users' => ( ! isset( $settings['allow-users'] ) || $settings['allow-users'] ), // Allow by default.191 'allow-users' => ! empty( $settings['allow-users'] ), 122 192 'hide-settings-ui' => true, 123 193 ); … … 128 198 } 129 199 130 if ( is_multisite() && get_site_option( 'classic-editor-allow-sites' ) !== 'allow' ) { 131 // Return default network options. 132 return array( 200 if ( is_multisite() ) { 201 $defaults = array( 133 202 'editor' => 'classic', 134 203 'allow-users' => false, 135 'hide-settings-ui' => true,136 204 ); 137 } 138 139 $allow_users = ( get_option( 'classic-editor-allow-users' ) !== 'disallow' ); 140 $option = get_option( 'classic-editor-replace' ); 141 142 // Normalize old options. 143 if ( $option === 'block' || $option === 'no-replace' ) { 144 $editor = 'block'; 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'] ); 145 232 } else { 146 // empty( $option ) || $option === 'classic' || $option === 'replace'. 147 $editor = 'classic'; 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 } 148 243 } 149 244 … … 274 369 <p> 275 370 <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 _e ( 'Classic Editor', 'classic-editor' ); ?></label>371 <label for="classic-editor-classic"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></label> 277 372 </p> 278 373 <p> 279 374 <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 _e ( 'Block Editor', 'classic-editor' ); ?></label>375 <label for="classic-editor-block"><?php _ex( 'Block Editor', 'Editor Name', 'classic-editor' ); ?></label> 281 376 </p> 282 377 </div> … … 344 439 <table class="form-table"> 345 440 <tr> 346 <th scope="row"><?php _e ( 'Classic Editor', 'classic-editor' ); ?></th>441 <th scope="row"><?php _ex( 'Classic Editor', 'Editor Name', 'classic-editor' ); ?></th> 347 442 <td> 348 443 <?php wp_nonce_field( 'allow-site-admin-settings', 'classic-editor-network-settings' ); ?> … … 410 505 */ 411 506 public static function remember_classic_editor( $post ) { 412 if ( ! empty( $post->ID ) ) { 507 $post_type = get_post_type( $post ); 508 509 if ( $post_type && post_type_supports( $post_type, 'editor' ) ) { 413 510 self::remember( $post->ID, 'classic-editor' ); 414 511 } … … 419 516 */ 420 517 public static function remember_block_editor( $editor_settings, $post ) { 421 if ( ! empty( $post->ID ) ) { 518 $post_type = get_post_type( $post ); 519 520 if ( $post_type && self::can_edit_post_type( $post_type ) ) { 422 521 self::remember( $post->ID, 'block-editor' ); 423 522 } … … 427 526 428 527 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 ) { 528 if ( get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor ) { 433 529 update_post_meta( $post_id, 'classic-editor-remember', $editor ); 434 530 } … … 455 551 } 456 552 457 // Open the default editor when no $post and for "Add New" links. 553 // Open the default editor when no $post and for "Add New" links, 554 // or the alternate editor when the user is switching editors. 458 555 if ( empty( $post->ID ) || $post->post_status === 'auto-draft' ) { 459 if ( $settings['editor'] === 'classic' ) { 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 ) { 460 560 $use_block_editor = false; 461 561 } … … 467 567 if ( $use_block_editor && ! $editors['block_editor'] ) { 468 568 $use_block_editor = false; 469 } elseif ( ! $use_block_editor && ! $editors['classic_editor'] ) {569 } elseif ( ! $use_block_editor && ! $editors['classic_editor'] && $editors['block_editor'] ) { 470 570 $use_block_editor = true; 471 571 } … … 526 626 if ( did_action( 'enqueue_block_editor_assets' ) ) { 527 627 // Block Editor is loading, switch to Classic Editor. 528 $edit_url = add_query_arg( 'classic-editor', $edit_url );628 $edit_url = add_query_arg( 'classic-editor', '', $edit_url ); 529 629 $link_text = __( 'Switch to Classic Editor', 'classic-editor' ); 530 630 } else { … … 538 638 539 639 ?> 540 <p style="margin: 1em ;"><a href="<?php echo esc_url( $edit_url ); ?>"><?php echo $link_text; ?></a></p>640 <p style="margin: 1em 0;"><a href="<?php echo esc_url( $edit_url ); ?>"><?php echo $link_text; ?></a></p> 541 641 <?php 542 642 } … … 578 678 } 579 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 580 692 /** 581 693 * Checks which editors are enabled for the post type. … … 590 702 591 703 $classic_editor = post_type_supports( $post_type, 'editor' ); 592 $block_editor = use_block_editor_for_post_type( $post_type );704 $block_editor = self::can_edit_post_type( $post_type ); 593 705 594 706 $editors = array( … … 675 787 // Link to the Block Editor. 676 788 $url = remove_query_arg( 'classic-editor', $edit_url ); 677 $text = _ _( 'Block Editor', 'classic-editor' );789 $text = _x( 'Block Editor', 'Editor Name', 'classic-editor' ); 678 790 /* translators: %s: post title */ 679 791 $label = sprintf( __( 'Edit “%s” in the Block Editor', 'classic-editor' ), $title ); … … 682 794 // Link to the Classic Editor. 683 795 $url = add_query_arg( 'classic-editor', '', $edit_url ); 684 $text = _ _( 'Classic Editor', 'classic-editor' );796 $text = _x( 'Classic Editor', 'Editor Name', 'classic-editor' ); 685 797 /* translators: %s: post title */ 686 798 $label = sprintf( __( 'Edit “%s” in the Classic Editor', 'classic-editor' ), $title ); … … 709 821 } elseif ( $editors['classic_editor'] && ! $editors['block_editor'] ) { 710 822 // Forced to Classic Editor. 711 $state = '<span class="classic-editor-forced-state">' . _ _( 'Classic Editor', 'classic-editor' ) . '</span>';823 $state = '<span class="classic-editor-forced-state">' . _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) . '</span>'; 712 824 } elseif ( ! $editors['classic_editor'] && $editors['block_editor'] ) { 713 825 // Forced to Block Editor. 714 $state = '<span class="classic-editor-forced-state">' . _ _( 'Block Editor', 'classic-editor' ) . '</span>';826 $state = '<span class="classic-editor-forced-state">' . _x( 'Block Editor', 'Editor Name', 'classic-editor' ) . '</span>'; 715 827 } else { 716 828 $last_editor = get_post_meta( $post->ID, 'classic-editor-remember', true ); … … 723 835 } 724 836 725 $state = $is_classic ? _ _( 'Classic Editor', 'classic-editor' ) : __( 'Block Editor', 'classic-editor' );837 $state = $is_classic ? _x( 'Classic Editor', 'Editor Name', 'classic-editor' ) : _x( 'Block Editor', 'Editor Name', 'classic-editor' ); 726 838 } 727 839 … … 765 877 */ 766 878 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 879 if ( is_multisite() ) { 774 update_network_option( null, 'classic-editor-allow-sites', 'disallow' ); 775 } 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' ); 776 885 } 777 886 … … 780 889 */ 781 890 public static function uninstall() { 891 if ( is_multisite() ) { 892 delete_network_option( null, 'classic-editor-allow-sites' ); 893 } 894 782 895 delete_option( 'classic-editor-replace' ); 783 896 delete_option( 'classic-editor-allow-users' ); -
classic-editor/trunk/readme.txt
r1987370 r1989286 2 2 Contributors: azaozz, melchoyce, chanthaboune, alexislloyd, pento, youknowriad, desrosj, luciano-croce 3 3 Tags: editor, classic editor, block editor, gutenberg 4 Requires at least: 5.04 Requires at least: 4.9 5 5 Tested up to: 5.0 6 6 Stable tag: 1.1 … … 23 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 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 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. 28 26 … … 31 29 == Changelog == 32 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 33 39 = 1.1 = 34 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. 35 41 36 42 = 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.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. 49 55 50 56 = 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 CLassic editor after looking at post revisions.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. 54 60 55 61 = 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.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. 59 65 60 66 = 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.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. 63 69 64 70 = 0.2 = 65 Update for Gutenberg 1.9.66 Remove warning and automatic deactivation when Gutenberg is not active.71 * Update for Gutenberg 1.9. 72 * Remove warning and automatic deactivation when Gutenberg is not active. 67 73 68 74 = 0.1 =
Note: See TracChangeset
for help on using the changeset viewer.