和许多其他人一样,我在 TinyMCE 剥离 HTML 标签方面遇到了问题 - 特别是我在 Font Awesome 中使用的空标签。
我研究并尝试了解决方案,但没有任何效果。我对 PHP 不是特别擅长,但我遇到的问题是这样的:每个人都说修改tinymce.js 文件中的tinyMCE.init 函数。然而,在最新版本的 WP 中,我没有这个。我有 class-wp-editor.php,其中包含:
/*
* 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 checks against the full set of HTML 5.0 elements and attributes.
*/
if ( $set['teeny'] ) {
/**
* Filter the teenyMCE config before init.
*
* @since 2.7.0
*
* @param array $mceInit An array with teenyMCE config.
* @param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
} else {
/**
* Filter the TinyMCE config before init.
*
* @since 2.5.0
*
* @param array $mceInit An array with TinyMCE config.
* @param string $editor_id Unique editor identifier, e.g. 'content'.
*/
$mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
}
现在我知道我必须对 valid_elements、extended_valid_elements 或 verify_html 做一些事情,但我不知道该怎么做。我可以从注释中看到将其放在哪里,但我不知道该使用哪个或正确的语法。
我找到了这个 fiddle :http://fiddle.tinymce.com/j9baab/1但就像我说的,我在 WP 的任何地方都没有这个功能。
请帮忙!
最佳答案
您确实不想修改 class-wp-editor.php
文件,因为每次更新 WordPress 时它都会被覆盖。
扩展/修改 TinyMCE 设置的最简单方法是构建一个简单的 WordPress 插件并绑定(bind)到 WordPress 提供的 Hook 来更改编辑器的设置。
为了解决您向您想要查看的 init 添加选项的特殊愿望
'tiny_mce_before_init'
Hook 。您可以在插件中执行类似的操作:
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
编写一个简单的 WP 插件并不难 - 网络上有很多示例。对于这么简单的事情来说,它实际上只是一个 PHP 文件。构建插件后,您只需安装并激活它即可。激活后,每次调用 TinyMCE 时都会运行您的代码,并将您的选项注入(inject)到初始化代码中。
编辑:这是 OP 注释中的代码(比注释的格式更容易阅读):
<?php
/**
* Plugin Name: Disable TinyMCE Filters
* Plugin URI: http://mindspyder.com
* Description: This plugin disables annoying TinyMCE Filters.
* Version: 1.0.0
* Author: Brandon Snow
* Author URI: http://mindspyder.com
* License: GPL2
*/
add_filter('tiny_mce_before_init', 'add_my_options');
function add_my_options($opt) {
// $opt is the existing array of options for TinyMCE
// We simply add a new array element where the name is the name
// of the TinyMCE configuration setting. The value of the array
// object is the value to be used in the TinyMCE config.
$opt['extended_valid_elements'] = '*[*]';
return $opt;
}
?>
关于php - 停止 TinyMCE 在 WordPress 中剥离空标签 - 是的,我已经研究过了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36736410/