0

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.

  • addslashes() and stripslashes() not work for you? – mor7ifer Mar 18 '12 at 18:44
  • I submitted it as an answer so you can mark as solved! – mor7ifer Mar 18 '12 at 18:59
0

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.

  • 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. – mor7ifer 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? – mor7ifer Mar 20 '12 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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