Fixing Added Slashes in WordPress
I was developing some theme options and in fields where I was going to allow the user to enter in some HTML I was noticing that whenever a link was entered in (e.g. <a href=”http://www.google.com”>Google</a>) the actual outputted markup was causing the URL to be broken due to added slashes. The output would look like the following
<a href=\"www.google.com\">Google</a>
After searching around for a solution to this I eventually found that this issue is largely related to the configuration on the server and PHP’s deprecated magic quotes. Fortunately there is a way around it. I added the following code at the top of my functions.php file and that seemed to fix the problem.
$_POST = array_map( 'stripslashes_deep', $_POST ); $_GET = array_map( 'stripslashes_deep', $_GET ); $_COOKIE = array_map( 'stripslashes_deep', $_COOKIE ); $_REQUEST = array_map( 'stripslashes_deep', $_REQUEST );
