Skip to content

Instantly share code, notes, and snippets.

@gschoppe
Forked from senlin/classic-editor-addon.php
Last active November 2, 2018 19:47
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gschoppe/ce88a7821764ef11803a5c64350078b6 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Classic Editor Addon
* Plugin Author: Pieter Bos (https://so-wp.com) and Greg Schoppe (https://gschoppe.com)
* Description: The Classic Editor plugin doesn't remove Gutenberg by default. with this function we set the option that controls this from no-replace to replace and we remove the Settings link from the main Plugins page
*/
function classic_editor_addon_hardcode_replace( $value ) {
return 'replace';
}
function classic_editor_addon_remove_settings_link( $links, $file ) {
if ( $file === 'classic-editor/classic-editor.php' && current_user_can( 'manage_options' ) ) {
array_shift( $links );
}
return $links;
}
function classic_editor_addon_init() {
/**
* Remove the Try Gutenberg Panel, slated for WordPress 4.9.6
*/
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
if ( function_exists( 'classic_editor_init_actions' ) ) {
/**
* Change the default option of "no-replace" to "replace",
* which means the checkbox will be unticked and the bloody plugin
* does what it says from the get-go (L336).
*/
add_filter( 'pre_option_classic-editor-replace', 'classic_editor_addon_hardcode_replace' );
/**
* Remove Settings link to the settings from the Plugins screen (L277).
*/
add_filter( 'plugin_action_links', 'classic_editor_addon_remove_settings_link', 10, 2 );
}
}
add_action( 'plugins_loaded', 'classic_editor_addon_init', 1, 0 );
@senlin
Copy link

senlin commented Jun 10, 2018

Hi @gschoppe Greg,

I came to realise that the filter of the plugin_action_links with the classic_editor_addon_remove_settings_link function does not work.

To make it work, the filter needs to be replaced with an action:
add_action( 'plugins_loaded', 'classic_editor_addon_remove_settings_link' );

And the function itself can be simplified by:

function classic_editor_addon_remove_settings_link() {
	remove_filter( 'plugin_action_links', 'classic_editor_add_settings_link' );
}

You can see, the changes also in my original gist (updated of course with your changes).

What do you think about releasing this together as a plugin in the WP Plugin Repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment