Last active
January 27, 2019 21:18
-
-
Save kagg-design/18883cb7ab310e818ef91ffa81088d47 to your computer and use it in GitHub Desktop.
Function to check if Gutenberg is active.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if Block Editor is active. | |
* Must only be used after plugins_loaded action is fired. | |
* | |
* @return bool | |
*/ | |
function is_active() { | |
// Gutenberg plugin is installed and activated. | |
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) ); | |
// Block editor since 5.0. | |
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ); | |
if ( ! $gutenberg && ! $block_editor ) { | |
return false; | |
} | |
if ( is_classic_editor_plugin_active() ) { | |
$editor_option = get_option( 'classic-editor-replace' ); | |
$block_editor_active = array( 'no-replace', 'block' ); | |
return in_array( $editor_option, $block_editor_active, true ); | |
} | |
return true; | |
} | |
/** | |
* Check if Classic Editor plugin is active. | |
* | |
* @return bool | |
*/ | |
function is_classic_editor_plugin_active() { | |
if ( ! function_exists( 'is_plugin_active' ) ) { | |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
} | |
if ( is_plugin_active( 'classic-editor/classic-editor.php' ) ) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment