Support » Themes and Templates » Stripslashes in functions.php

Viewing 15 replies - 1 through 15 (of 15 total)
  • esmi


    Forum Moderator

    What do you want to use stripslashes for?

    The options pane has a text area and if someone uses the symbol ‘ it shows a slash after so…



    Forum Moderator

    Try adding the following to functions.php:

    // Strip slashes
    function theme_stripslashes_array($array) {
    	if ( get_magic_quotes_gpc() == 0 ) return is_array($array) ? array_map('theme_stripslashes_array', $array) : stripslashes($array);

    Then just before you update the theme option, use:

    $this_post_option = theme_stripslashes_array($this_post_option);

    What would I do specifically for my case. Code is here:

    I’ve seen that approach to theme option pages before(old method, i remember reading it in a tutorial), and i just want to point something out, you’re storing each option in it’s own row of the options table (20 theme options is going to end up as 20 rows in the options table), this is needless and using up un-necessary space in the DB, plus your script will be more intensive having to query 10 (or however many options) over a single option holding data for all the fields..

    There’s no requirement to do this any more theme’s should make use of the settings API(it’s not fully idiot proof, heck i struggled with it), but at least this way you can store a group of options as one row in the database quite easily.

    This blog has a great demonstration (it’s quite basic to, so easier to follow).
    There’s also the write-up by Otto here.

    The reason i linked the ozh tutorial first is because it illustrates how to use an array of options, which may not otherwise be obvious by looking at the example given by Otto, since the example given only uses one field.

    It may not be important to you(whatever works), but thought i’d throw the information out there, in case you felt a desire to be particular about such things … 😉

    Unfortunately, these tutorials only work for plugins, I need to make options for a theme.

    It works for theme’s to(i should of said that before), i’ve done it myself… like i said above, there was a particular reason i linked to the examples, first shows how to use an array of options, the second is the same but doesn’t make that key point obvious(hence the first link).

    By all means if you like the method you have and find it easier, then stick with what you have, i just wanted to point out that you need not store options all in seperate options (one row of the database per option, one query per option when you retrieve them – instead of one query for all).

    The functions file is loaded on every page, so the less queries it has to run the faster it’ll be for you. I’ll give you an example..

    $my_option1 = get_option('first_option');
    $my_option2 = get_option('second_option');
    // 2 queries
    // Or looped example
    foreach( $something as $somethingelse ) {
    // etc etc..
    echo get_option( $somethingelse ); // 1 per query for each result in this loop
    } compare to that to an option storing all the data in one row as an array…

    $my_options =  get_option();
    // That's it 1 query, you've got the data
    echo $my_option['first_option']; // first option (no more queries needed)
    echo $my_option['second_option']; // second option (just referencing the array, no more queries still)
    // and so on..

    I know the settings API isn’t easy to follow for everyone, i’m just trying to highlight the differences, for the sake of all reading…

    Thanks, but 2 questions.

    1. I click save changes and this comes up “Warning: Cannot modify header information – headers already sent by (output started at /nfs/c04/h02/mnt/80144/domains/ in /nfs/c04/h02/mnt/80144/domains/ on line 868”. What’s wrong?

    2. How do I output these settings?

    Once again, thanks so much!!

    Why not look at how some other theme’s do it, take the code, have a play around and you’ll get to understand and learn in the process..

    1. What code is on the line mentioned in the error?
    2. You’ll need to provide some context to the question, it’s a little too general to know what you mean.

    1. “header(“Location: $location”, true, $status);”
    2. I’m trying to display an about message that the user types in via the options pane.

    header("Location: $location", true, $status);

    .. header redirects must occur before output, if you’ve echo’ed/printed or output any elements or data to the screen prior to that line, then that error will naturally appear..

    2. I’m trying to display an about message that the user types in via the options pane.

    What message, where’s it coming from?
    What options pane? One you’ve created or one of the regular WordPress options page?

    Still need a few more details please on no.2 …

    In regards to 2, the options panel that the code renders will have a textbox in which they type in a message. I would like to display it in the footer.

    Ok, but what’s the problem, do you need an example?


    $some_option = get_option( 'your_option_name' );
    if( $some_option ) {
    // PHP STUFF


    $some_option = get_option( 'your_option_name' );
    if( $some_option ) {
    <!-- HTML STUFF -->

    Thanks! Sorry about the confusion.

    It’s no problem at all, it’s just easier for me to suggest something if i have clear idea of what you mean.. 😉

    Happy to help all the same.. 🙂

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Stripslashes in functions.php’ is closed to new replies.