1

Wordpress WYSIWYG 编辑器无法正确格式化保存的HTML 输出

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

截图在这里

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

我一直在做一些阅读,我想这可能与esc_html也许有关?我真的不太确定。

这个片段,是我真正的 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')零件是我做的。如您所见,我基本上复制了底部功能。

4

1 回答 1

3

尝试不使用 esc_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 } ?>
于 2013-04-17T13:26:47.433 回答