Skip to content

Instantly share code, notes, and snippets.

@contactjavas
Forked from mihdan/is_gutenberg_active.php
Created January 5, 2024 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contactjavas/5e9a91326af3857b244b0fd96e641288 to your computer and use it in GitHub Desktop.
Save contactjavas/5e9a91326af3857b244b0fd96e641288 to your computer and use it in GitHub Desktop.
Function to check if Gutenberg is active.
/**
* Check if Gutenberg is active.
* Must be used not earlier than plugins_loaded action fired.
*
* @return bool
*/
private function is_gutenberg_active() {
$gutenberg = false;
$block_editor = false;
if ( has_filter( 'replace_editor', 'gutenberg_init' ) ) {
// Gutenberg is installed and activated.
$gutenberg = true;
}
if ( version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' ) ) {
// Block editor.
$block_editor = true;
}
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = ( get_option( 'classic-editor-replace' ) === 'no-replace' );
return $use_block_editor;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment