gutenbergdocs/docs/how-to-guides/widgets/opting-out.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

2025-10-21 17:33:45 +00:00
# 恢复经典小工具编辑器
有多种方法可以禁用新的小工具区块编辑器。
## 使用 `remove_theme_support`
主题可以通过调用 `remove_theme_support( 'widgets-block-editor' )` 来禁用小工具区块编辑器。
例如,主题可以在 `functions.php` 文件中添加以下 PHP 代码:
```php
function example_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );
```
## 使用经典小工具插件
最终用户可以通过安装并激活[经典小工具插件](https://wordpress.org/plugins/classic-widgets/)来禁用小工具区块编辑器。
安装此插件后,可以通过停用和激活插件来切换小工具区块编辑器的开关状态。
## 使用过滤器
`use_widgets_block_editor` 过滤器用于控制是否启用小工具区块编辑器。
例如,网站管理员可以在 Must-Use 插件中添加以下 PHP 代码来禁用小工具区块编辑器:
```php
add_filter( 'use_widgets_block_editor', '__return_false' );
```
对于更高级的用法,您可以提供自定义函数。以下示例展示了如何为特定用户禁用小工具区块编辑器:
```php
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' );
```