HTML not formatting correctly using wp_editor()

WordPress WYSIWYG Editor doesn’t format the saved HTML output correctly

I have a screenshot which explains exactly what’s going on, and I’ll post my code snippets too.

Screenshot Here

Read More

I’m making a wordpress plugin that adds text that is edited in the WYSIWYG editor that is called in on my custom settings page. I’ve got it to post the saved input to where I want it to go (via editing the themes template file though, not what I really wanted, but it’s working) but it outputs the saved text with none of the formatting that was chosen in the WYSIWYG via my plugin page.

I’ve been doing some reading, and I’m thinking it might be something to do with the esc_html perhaps? I’m really not too sure.

This snippet, is my actual WordPress plugin:

<?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>

And this one, is where the text is being posted to in the themes home.php template file:

<?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 } ?>

The ('post_text') parts are my doing. As you can see I basically copied the bottom function.

Related posts

Leave a Reply

1 comment

  1. try not using the 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 } ?>