Wordpress插件正在剥离html标签 - 如何将某些标签列入白名单

时间:2018-02-06 10:00:47

标签: php html wordpress

我有这个插件 https://themeforest.net/item/upvote-social-bookmarking-wordpress-theme/15542355?ref=ThemeWarriors

问题是,他们的插件并没有使用Wordpress普通帖子,它有自己的帖子" post"类型是"故事"。提交故事时,没有WPEditor,只是一个空文本区域。

我已将TinyMce添加到textarea以允许用户提交使用html格式的故事,但该插件正在剥离html并仅将其转换为文本。 如果我尝试使用<strong>test text</strong>提交文字,则会在故事中显示标记(帖子)。

我已经伸出了他们的支持,但他们说它超出了他们的支持政策。他们让我尝试改变以下内容,但它没有成功:

'post_content'    => wp_kses_post( $warrior_description_topic ),

'post_content'    => $warrior_description_topic,

评论部分使用TinyMCE评论WP插件工作正常,因为评论是使用wordpress系统而不是插件,我只是希望能够在插件提交页面上使用相同的编辑器。

有问题的textarea是:

<textarea name="description" id="post-desc" rows="8" placeholder="<?php esc_html_e('Description', 'upvote-plugin'); ?>" required><?php if (isset($_POST['description'])) echo $_POST['description']; ?></textarea>

我想将TinyMCE编辑器添加到textarea并将某些标签列入白名单(强,斜体,下划线等)

如果您需要更多信息,请告诉我esc_html等要查找的内容,并发布与之相关的代码。我无法透露大部分代码,因为它是付费插件

1 个答案:

答案 0 :(得分:1)

要将TinyMCE编辑器添加到textarea,请将整个标记替换为:

// We use output buffering so that we could modify the TEXTAREA tag, where
// we'll add the "placeholder" and "required" attributes to that tag.
/* Original code:
<textarea name="description" id="post-desc" rows="8" placeholder="<?php esc_html_e('Description', 'upvote-plugin'); ?>" required><?php if (isset($_POST['description'])) echo $_POST['description']; ?></textarea>
*/
ob_start();
$content = isset( $_POST['description'] ) ? wp_unslash( $_POST['description'] ) : '';
wp_editor( $content, 'post-desc', array(
    'textarea_name' => 'description',
    'textarea_rows' => '8',
    'teeny'         => true, // TRUE to output the minimal editor config, such as the Comment editor.
) );
$editor = ob_get_clean();
$text = esc_html__( 'Description', 'upvote-plugin' );
$editor = str_replace( '<textarea ', '<textarea placeholder="' . $text . '" required ', $editor );
echo $editor;

有关function的详细信息,请参阅wp_editor

关于这一个:

  

'post_content' => $warrior_description_topic

如果这不起作用,那么请尽可能将代码发布到定义该变量的位置,如下所示:

$warrior_description_topic = // whatever code here.