WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to store html in wp_options (3 posts)

  1. teamplaylotto
    Member
    Posted 5 years ago #

    I have a plugin that a user can specify some html code in the options page to be added to the output of the plugin. if the content is using double quotes then all is fine but if the html contains single and double quotes then things can go a bit screwy.

    what is the best way to store html in wp_options and have it come back as it was entered?

    ie. user submits the options page and it has a textarea with
    <br /><a class='myclass' href="http://blahblah.com">Some "quoted" text and apostrophe's</a>

    how to store that without errors and be able to echo it out to the page to be displayed as html to be rendered by the browser?

  2. Vicky Arulsingam
    Member
    Posted 5 years ago #

    You could try using the function addslashes before you save the option.

    example:
    $html_code = addslashes($_POST['html_code']);
    update_option('myoptionname', $html_code);

    Then when displaying the code you use the stripslashes function.

    $myoption = stripslashes(get_option('myoptionname'));
    echo $myoption

  3. teamplaylotto
    Member
    Posted 5 years ago #

    thanks for replying.
    I did some playing with addslashes and it appears it might act differently if magic quotes are on so I now use this

    // add slashes to html if magic quotes is not on
    function atf_slashit($stringvar){
        if (!get_magic_quotes_gpc()){
            $stringvar = addslashes($stringvar);
        }
        return $stringvar;
    }
    // remove slashes if magic quotes is on
    function atf_deslashit($stringvar){
        if (1 == get_magic_quotes_gpc()){
            $stringvar = stripslashes($stringvar);
        }
        return $stringvar;
    }

    and add the html returned by the settings page by

    update_option('my_html_pre',atf_slashit($_POST['my_html_pre']));

    that seems to work and should be compatible if someone doesn't have magic quotes on

Topic Closed

This topic has been closed to new replies.

About this Topic