WordPress.org

Ready to get started?Download WordPress

Forums

Need help with stripslashes() (2 posts)

  1. stevebluck
    Member
    Posted 3 years ago #

    Hello,

    I'm in the process of creating my theme. I am having trouble with the option input and textarea fields. Here is my code:

    <?php
    
    if(get_option($value['id']) != '')
    {
        echo stripslashes(get_option($value['id']));
    }
    else
    {
         echo (stripslashes($value['std']));
    }
    
    ?>

    Unfortunatley, this is not stripping the slashes! The slashes are still appearing. So if the user typed in <div id="foo">bar</div> it would add escape slashes before the quote marks.

    Any reason why my stripslashes() function is being ignored?

    Thank you.

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    Try htmlspecialcharacters I have seen this used for pagemeta.

    I am still finding my way around but I have used it like this:
    $scheme['menuBg'] = '#' .htmlspecialchars( get_post_meta( $postid, $prefix .'menu_bg_color', true ));

    B.T.W.
    You do not need the !="", the if is false if null, empty or 0 is returned.

    <?php
    if(get_option($value['id']))
    {
        echo htmlspecialchars(get_option($value['id']));
    }
    else
    {
        echo htmlspecialchars($value['std']);
    }
    ?>

    As you are outputting html then I am asuming that it is a template part, I notice that the structure is normally different and braces are rarely used in favor of :, I do not know why maybe someone else can explain, but the output would be like.

    <?php if(get_option($value['id'])) : ?>
     <?php echo htmlspecialchars(get_option($value['id'])); ?>
    <?php else: ?>
      <?php echo htmlspecialchars($value['std']); ?>
    <?php endif; ?>

    HTH

    David

Topic Closed

This topic has been closed to new replies.

About this Topic