1

I have created a custom settings page with a couple of wp_editor() calls on it. When I enter some text in the editor, and format it (e.g. make it bold), and then save it, the value is saved in the database. If I reload the settings page again, it loads the text in the editor as bold.

However, when I load the options on a page, and echo it, it has no html tags what so ever.

I have not added any sanitation, and it would seem that it knows it is bold, because it works when loading the settings page.

Does anyone know how I can get it to not strip away html tags when printing the value from the editor field?

This is how I print it:

$options = get_option('settings');
echo $options['information'];

EDIT: This is how I create the wp_editor:

<?php wp_editor( $options['text'], 'text', array(
    'textarea_name' => 'settings[text]',
    'media_buttons' => false,
    'textarea_rows' => 10
)); ?>

It saves it automatically when I click the form submit button. That is created like this:

function settings_page() {

    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'test'));
    }

    ?>

        <div class="wrap">
            <?php screen_icon(); ?> <h2><?php _e('Settings', 'test'); ?></h2>

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

                <?php submit_button(); ?>
            </form>
        </div>

    <?php
}
  • Show us also how you build up the form field and how you save the content. – cybmeta Feb 7 '15 at 9:09
  • @cybmeta I've added some more code. – ptf Feb 8 '15 at 5:04
  • SOrry but that information is not enough, how do you save the data is needed, you are probably removing HTML before saving but we can not know if you don't show us that part of the code. "It save automatically when I click the button" doesn't provide the information needed. – cybmeta Feb 8 '15 at 20:10
  • That is literally what happens. I haven't done any logic what so ever for the saving. I'll try to add my own sanitation to see if it helps, but it does remember the formatting in admin mode. – ptf Feb 9 '15 at 2:58
1

You have to format the output:

echo wpautop( stripslashes ( $options['information'] ) );

see: https://codex.wordpress.org/Function_Reference/wpautop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.