remove_editor_styles()
云策文档标注
概述
remove_editor_styles() 函数用于移除所有可视化编辑器样式表,确保主题不再支持编辑器样式。该函数返回布尔值表示操作成功与否。
关键要点
- 移除所有可视化编辑器样式表,通过撤销主题对 'editor-style' 的支持实现
- 返回 true 表示成功移除,false 表示没有样式表可移除(例如主题不支持 'editor-style')
- 内部使用 _remove_theme_support() 和 current_theme_supports() 函数,并仅在管理界面更新全局变量 $GLOBALS['editor_styles']
代码示例
function remove_editor_styles() {
if ( ! current_theme_supports( 'editor-style' ) ) {
return false;
}
_remove_theme_support( 'editor-style' );
if ( is_admin() ) {
$GLOBALS['editor_styles'] = array();
}
return true;
}注意事项
- 仅在主题支持 'editor-style' 时生效,否则直接返回 false
- 在管理界面中会清空 $GLOBALS['editor_styles'] 数组,影响编辑器样式加载
- 自 WordPress 3.1.0 版本引入,使用时需注意版本兼容性
原文内容
Removes all visual editor stylesheets.
Source
function remove_editor_styles() {
if ( ! current_theme_supports( 'editor-style' ) ) {
return false;
}
_remove_theme_support( 'editor-style' );
if ( is_admin() ) {
$GLOBALS['editor_styles'] = array();
}
return true;
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |