我有一个插件,它使用wp_editor()
函数加载TinyMCE编辑器的实例。
但是,编辑器会受到自定义样式的影响,以便通过add_editor_style()
作用虽然这可能会让用户更好地了解内容在前端的外观,但我不希望这样,因为内容只会显示在后端。
有没有办法加载WordPress编辑器的实例而不受自定义样式的影响?
我有一个插件,它使用wp_editor()
函数加载TinyMCE编辑器的实例。
但是,编辑器会受到自定义样式的影响,以便通过add_editor_style()
作用虽然这可能会让用户更好地了解内容在前端的外观,但我不希望这样,因为内容只会显示在后端。
有没有办法加载WordPress编辑器的实例而不受自定义样式的影响?
虽然@s\\u ha\\u dum的解决方案在自定义插件页面上运行良好,但如果在调用第一个编辑器实例后在post editor页面上使用TinyMCE,它将失败,因为它可能会影响所有编辑器,或者至少会影响同一页面上稍后的编辑器。TinyMCE仅在第一次运行时将自定义样式解析为其设置。
如何删除的自定义样式one editor only?
假设我们在仅使用静态方法的类中用富编辑器替换摘录框:
wp_editor(
self::unescape( $post->post_excerpt ),
\'excerpt\', // $editor_id
array (
\'textarea_rows\' => 15
, \'media_buttons\' => FALSE
, \'teeny\' => TRUE
, \'tinymce\' => TRUE
, \'first_init\' => TRUE
)
);
要删除一个特殊编辑器ID的自定义样式,我们可以筛选teeny_mce_before_init
如果我们已经设置\'teeny\' => TRUE
和tiny_mce_before_init
否则看见_WP_Editors::editor_settings()
:
// For people who really REALLY know what they\'re doing with TinyMCE
// You can modify $mceInit to add, remove, change elements of the config before tinyMCE.init
// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
if ( $set[\'teeny\'] ) {
$mceInit = apply_filters(\'teeny_mce_before_init\', $mceInit, $editor_id);
} else {
$mceInit = apply_filters(\'tiny_mce_before_init\', $mceInit, $editor_id);
}
在这个例子中teeny_mce_before_init
, 我们需要一个简单的助手方法:public static function no_custom_css( $settings, $editor_id )
{
\'excerpt\' === $editor_id and $settings[\'content_css\'] = \'\';
return $settings;
}
现在我们在调用之前将其注册为回调wp_editor()
:add_filter( \'teeny_mce_before_init\', array ( __CLASS__, \'no_custom_css\' ), 10, 2 );
仅此而已。现在只有ID为的编辑器才不会获得自定义样式。没有不稳定的副作用,我们的代码在所有情况下都与其他代码保持兼容。我相信你想要remove_editor_styles
. 看起来是这样的removes the theme support 对于编辑器样式。
remove_editor_styles();
如果在编辑器启动之前在插件的后端页面上运行,那么应该可以解决问题。可能有一个参数可以传递给编辑器函数,或者一个钩子,但我首先想到的是删除对受影响页面的编辑器样式支持。未经测试,我对编辑器样式做得不多,但它似乎非常简单。