WordPress.org

Ready to get started?Download WordPress

Forums

Stripslashes in functions.php (16 posts)

  1. phil799
    Member
    Posted 4 years ago #

    I am creating an options panel for my theme and I want to use the strip slashes function. How would I go about doing this?
    Code is here: http://pastebin.com/hB856fd1

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    What do you want to use stripslashes for?

  3. phil799
    Member
    Posted 4 years ago #

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

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    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);

  5. phil799
    Member
    Posted 4 years ago #

    What would I do specifically for my case. Code is here: http://pastebin.com/hB856fd1

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    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).
    planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/
    There's also the write-up by Otto here.
    ottodestruct.com/blog/2009/wordpress-settings-api-tutorial/

    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 ... ;)

  7. phil799
    Member
    Posted 4 years ago #

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

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    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
    }

    ..now 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...

  9. phil799
    Member
    Posted 4 years ago #

    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/tlrdesign.com/html/labs/wp-content/themes/Jeans/functions.php:46) in /nfs/c04/h02/mnt/80144/domains/tlrdesign.com/html/labs/wp-includes/pluggable.php on line 868". What's wrong?

    2. How do I output these settings?

    Once again, thanks so much!!

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    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.

  11. phil799
    Member
    Posted 4 years ago #

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

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

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

    http://php.net/manual/en/function.header.php

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

  13. phil799
    Member
    Posted 4 years ago #

    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.

  14. Mark / t31os
    Moderator
    Posted 4 years ago #

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

    Eg.

    <?php
    $some_option = get_option( 'your_option_name' );
    if( $some_option ) {
    // PHP STUFF
    }
    ?>

    or

    <?php
    $some_option = get_option( 'your_option_name' );
    if( $some_option ) {
    ?>
    <!-- HTML STUFF -->
    <?php
    }
    ?>
  15. phil799
    Member
    Posted 4 years ago #

    Thanks! Sorry about the confusion.

  16. Mark / t31os
    Moderator
    Posted 4 years ago #

    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.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic