Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I try to save inline javascript(Google analytics code) in wp-options table. But i can't figure out what validation function i shall use.

I have tried esc_js when saving to the database. But i can't figure out what to use when i shall echo it in the head section.

share|improve this question
    
addslashes() and stripslashes() not work for you? –  m0r7if3r Mar 18 '12 at 18:44
    
Thank you very much, that solved it. –  andeersg Mar 18 '12 at 18:56
    
I submitted it as an answer so you can mark as solved! –  m0r7if3r Mar 18 '12 at 18:59

1 Answer 1

up vote 0 down vote accepted

You can use addslashes() and stripslashes() to prepare any data for database entry. These are native PHP functions, not wordpress functions, so they do not necessarily need to be hooked anywhere specific in the wordpress load to work.

share|improve this answer
    
I just discovered that the output when using stripslashes is like this: <script type=\\\\\\\"text/javascript\\\\\\\"> I tought stripslashes removed them? –  andeersg Mar 20 '12 at 9:58
    
One instance of addslashes() will be undone by one instance of stripslashes(). If addslashes() is being called more than once (I don't know why you would ever do that), then you will need to call stripslashes() the same number of times. It looks like you're calling addslashes() 3 times based on the number of slashes there are. –  m0r7if3r Mar 20 '12 at 10:33
    
Hm, i only use the function one time. Think i must really go over my code. Thank you very much :) –  andeersg Mar 20 '12 at 11:09
    
How are you inserting the values into the database? –  m0r7if3r Mar 20 '12 at 11:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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