本文档介绍了禁用新的小部件块编辑器的多种方法,包括通过主题、插件和过滤器,以恢复经典小部件编辑器。
// 通过主题禁用小部件块编辑器
function example_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );
// 通过过滤器全局禁用小部件块编辑器
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' ); There are several ways to disable the new Widgets Block Editor.
remove_theme_supportThemes may disable the Widgets Block Editor by calling remove_theme_support( 'widgets-block-editor' ).
For example, a theme may have the following PHP code in functions.php.
function example_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );
End users may disable the Widgets Block Editor by installing and activating the Classic Widgets plugin.
With this plugin installed, the Widgets Block Editor can be toggled on and off by deactivating and activating the plugin.
the use_widgets_block_editor filter controls whether or not the Widgets Block Editor is enabled.
For example, a site administrator may include the following PHP code in a mu-plugin to disable the Widgets Block Editor.
add_filter( 'use_widgets_block_editor', '__return_false' );
For more advanced uses, you may supply your own function. In this example, the Widgets Block Editor is disabled for a specific user.
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' );