title: "恢复经典小工具编辑器" post_status: publish comment_status: open taxonomy: category: - gutenberg-docs post_tag: - Widgets - How To Guides - Repos


恢复经典小工具编辑器

有多种方法可以禁用新的小工具区块编辑器。

使用 remove_theme_support

主题可以通过调用 remove_theme_support( 'widgets-block-editor' ) 来禁用小工具区块编辑器。

例如,主题可以在 functions.php 文件中添加以下 PHP 代码。

function example_theme_support() {
    remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );

使用经典小工具插件

最终用户可以通过安装并激活经典小工具插件来禁用小工具区块编辑器。

安装此插件后,可以通过停用和激活插件来切换小工具区块编辑器的开关。

使用过滤器

use_widgets_block_editor 过滤器控制是否启用小工具区块编辑器。

例如,站点管理员可以在 mu-plugin 中包含以下 PHP 代码以禁用小工具区块编辑器。

add_filter( 'use_widgets_block_editor', '__return_false' );

对于更高级的用法,您可以提供自定义函数。在此示例中,为特定用户禁用了小工具区块编辑器。

function example_use_widgets_block_editor( $use_widgets_block_editor ) {
    if ( 123 === get_current_user_id() ) {
        return false;
    }
    return $use_widgets_block_editor;
}
add_filter( 'use_widgets_block_editor', 'example_use_widgets_block_editor' );