It’s a simple question with a strangely elusive answer.
get_magic_quotes_gpc() reports 0. I repeat, magic quotes are off. Magic quotes appear to have been disabled in php.ini (not at runtime).
Nevertheless, all POST data including single quotes (‘) is escaped when accessed in PHP. What could be causing this?
While preparing a test case, I discovered the general origin of the problem. We’re bootstrapping WordPress as our application integrates with a WordPress multisite installation. When I disable the WordPress bootstrapping, the auto-escaping is disabled. Where may WordPress’ auto-escape code be located?
I think I found it. Problem (bug): http://core.trac.wordpress.org/ticket/18322
Solution: http://codex.wordpress.org/Function_Reference/stripslashes_deep
Note: As suggested by @Alexandar O’Mara, you might want to reconsider overwriting the superglobals like this. If it’s appropriate for your situation, for example, you might just “strip locally” using an alternative like
$post = array_map('stripslashes_deep', $_POST);Also see @quickshiftin’s excellent answer.