Php 使用wp_editor()无法正确格式化HTML Wordpress所见即所得编辑器无法正确格式化保存的HTML输出

Php 使用wp_editor()无法正确格式化HTML Wordpress所见即所得编辑器无法正确格式化保存的HTML输出,php,wordpress,plugins,Php,Wordpress,Plugins,我有一个屏幕截图,它准确地解释了发生了什么,我也会发布我的代码片段 我正在制作一个wordpress插件,它可以添加在我的自定义设置页面中调用的WYSIWYG编辑器中编辑的文本。我已经让它将保存的输入发布到我希望它去的地方(通过编辑主题模板文件,虽然不是我真正想要的,但它工作正常),但是它输出保存的文本,没有通过我的插件页面在所见即所得中选择的格式 我一直在读一些书,我想这可能和esc\uhtml有关吧?我真的不太确定 这段代码是我的实际WordPress插件: <?php /*/ Pl

我有一个屏幕截图,它准确地解释了发生了什么,我也会发布我的代码片段

我正在制作一个wordpress插件,它可以添加在我的自定义设置页面中调用的WYSIWYG编辑器中编辑的文本。我已经让它将保存的输入发布到我希望它去的地方(通过编辑主题模板文件,虽然不是我真正想要的,但它工作正常),但是它输出保存的文本,没有通过我的插件页面在所见即所得中选择的格式

我一直在读一些书,我想这可能和
esc\uhtml
有关吧?我真的不太确定

这段代码是我的实际WordPress插件:

<?php
/*/
Plugin Name: Custom Text Adder
Plugin URI: N/A
Description: Demonstrates how rubbish I am at pretty much everything I want to do
Version: 101
Author: JD
Author URI: N/A
/*/


// create custom plugin settings menu
add_action('admin_menu', 'custom_create_menu');


// Add Font-Size to WYSIWYG Editor
function wp_editor_fontsize_filter( $options ) {
    array_shift( $options );
    array_unshift( $options, 'fontsizeselect');
    array_unshift( $options, 'formatselect');
    return $options;
}
add_filter('mce_buttons_2', 'wp_editor_fontsize_filter');



function custom_create_menu() {

    //create new top-level menu
    add_menu_page('Custom Plugin Settings', 'Custom Settings', 'administrator', __FILE__, 'custom_settings_page',plugins_url('/img/icon.png', __FILE__));

    //call register settings function
    add_action( 'admin_init', 'register_mysettings' );
}


function register_mysettings() {
    //register our settings
    register_setting( 'custom-settings-group', 'new_option_name' );
    register_setting( 'custom-settings-group', 'some_other_option' );
    register_setting( 'custom-settings-group', 'option_etc' );
    register_setting( 'custom-settings-group', 'font_size' );
    register_setting( 'custom-settings-group', 'post_text' );
}

function custom_settings_page() {
?>
<div class="wrap">
<h2>Custom Text</h2>

<?php?>

<form method="post" action="options.php">
    <?php settings_fields( 'custom-settings-group' ); ?>



    <table class="form-table">

        <?php /* Bring the editor onto the page */

wp_editor( '', 'post_text', $settings = array() );



/**
 * 4.
 * Custom buttons for the editor.
 * This is a list separated with a comma after each feature
 * eg. link, unlink, bold, ...
 */

$settings = array(
    'textarea_name' => 'post_text',
    'media_buttons' => true,
    'tinymce' => array(
        'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
            'bullist,blockquote,|,justifyleft,justifycenter' .
            ',justifyright,justifyfull,|,link,unlink,|' .
            ',spellchecker,wp_fullscreen,wp_adv'
    )
);

submit_button( 'Save everything', 'primary', 'submit' ); ?>
</form>
</div>

自定义文本
这是主题home.php模板文件中的文本发布位置:

<?php if ( get_option('chameleon_quote') == 'on' ) { ?>
    <div id="category-name"> 
        <div id="category-inner">

            <div><?php print esc_html(get_option('post_text')); ?></div>
        <?php if ( get_option('post_text') <> '' ) { ?>
            <h3><?php echo esc_html(get_option('post_text')); ?></h3>
        <?php } ?>
        <?php if ( get_option('chameleon_quote_two') <> '' ) { ?>
            <p><?php echo esc_html(get_option('chameleon_quote_two')); ?></p>
        <?php } ?>  
        </div>
    </div> <!-- end .category-name -->
<?php } ?>


('post_text')
部分是我的工作。如您所见,我基本上复制了底部函数。

请尝试不使用esc\U html

<?php if ( get_option('chameleon_quote') == 'on' ) { ?>
    <div id="category-name"> 
        <div id="category-inner">

            <div><?php print get_option('post_text'); ?></div>
        <?php if ( get_option('post_text') <> '' ) { ?>
            <h3><?php echo get_option('post_text'); ?></h3>
        <?php } ?>
        <?php if ( get_option('chameleon_quote_two') <> '' ) { ?>
            <p><?php echo get_option('chameleon_quote_two'); ?></p>
        <?php } ?>  
        </div>
    </div> <!-- end .category-name -->
<?php } ?>


如果不使用esc\u html,会发生什么?直接回应信息,我爱你!该死的天才!我真不敢相信我从来没有想过要尝试一下,哈哈。今天你是上帝派来的!非常感谢你,罗伯特!没问题。请记住esc_html将文本中的所有字符转换为可读形式,以便您可以显示代码:)通过转义html字符,我还有一个问题,请道歉,我有没有办法将所见即所得保存的输出发布到已存在的位置,但是不需要在模板文件的源代码中添加任何内容?这一直困扰着我一段时间,因为它几乎使我的插件不是一个真正合适的插件。再次感谢你简单但却带给我们巨大快乐的回答!你能澄清一下你的问题吗?比如直接根据页面类型插入代码,或者不必编辑源主题文件就可以发布代码?抱歉:我想让我的插件将自定义设置页面wYSIWYG中输入的保存输入插入主题模板文件
home.php
,但不必编辑模板文件本身。因此,我可以说,将插件压缩,发送给使用该主题的朋友,然后他们就可以在插件设置中编辑文本,而无需编辑
home.php
文件本身,将该代码包含在上面的答案中。我希望这更简洁一点!谢谢你的帮助,这个问题真的很麻烦。:)通常,对于插件设计,最好不要让它直接编辑主题,因为一旦主题得到更新或更改,它将添加冗余代码或其他问题。就我个人而言,我会做一些短代码来手动显示信息,或者如果你想让它自动添加信息,可以使用add_filter()根据条件直接添加信息,或者可能对你有所帮助我在插件开始时就朝着这个方向走,而且似乎找不到将我的代码添加到网站特定区域的过滤器。我试着
the_content()
和其他一些,它发布了输出,但是在文章的末尾,或者每一篇文章的结尾,诸如此类的事情。我想我的主要问题是找到合适的过滤器,让它发布到网站的特定区域。再次感谢您的建议,我希望有一种方法可以让我点击“添加代表”!