在这里,我分享了一个自定义函数,您可以使用它来检查Gutenberg是否启用。
if ( is_gutenberg_enable() ) {
// Do your code
}
这是一个自定义函数:
/**
* Check if Gutenberg is enable.
* Must be used not earlier than plugins_loaded action fired.
*
* @return bool
*/
function is_gutenberg_enable() {
$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;
}