Last active
December 17, 2015 14:59
-
-
Save dphiffer/5628511 to your computer and use it in GitHub Desktop.
Post meta escaping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$str1 = '\\"'; | |
update_post_meta($post->ID, "test", $str1); | |
$str2 = get_post_meta($post->ID, "test", true); | |
echo "$str1<br>$str2"; | |
/* | |
Result: | |
\" | |
" | |
More realistic use case... | |
Input: {"key":"value with \"quotes\" in the content."} | |
Output: {"key":"value with "quotes" in the content."} | |
The problem is that the output has returned something different than the input, making JSON data unparsable. | |
Solution from [wp-hackers] list: serialize the string on the way in, unserialize on the way out. <sigh> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment