0

I have wordpress installation where the magic quotes is set ON in the phpini file. this cause that every quote is duplicated every time I update a post.

I can't change the phpini is out of my capability, so the only way is by php code.

the parameter in my wp-config.php file is set with magic quote to 0.

Someone know where I add some code to perform it.

I use the custom post so I need of a solution with this compatible.

thanks in advance.

  • 1
    Talk to your hosting provider to disable this horrible feature. Or try creating a `.htaccess` containing `php_flag magic_quotes_gpc off`. – ThiefMaster May 11 '12 at 23:51
  • Wow, the rest of the world knew Magic Quotes was a disaster a decade ago... – sarnold May 12 '12 at 00:16
  • thanks for the response but if I comment the escape function I can't upgrade the system automatically in the future. and I need of more lucky to don't forget this. – Gianluca Lodigiani May 12 '12 at 00:59

2 Answers2

2
  1. Try putting ini_set( 'magic_quotes_gpc', 0 ); at the top of your pages
  2. Put php_flag magic_quotes_gpc off in an .htaccess file in your root Wordpress directory
  3. Use code to strip the slahes automatically for you. This would need to go at the top of the pages you wish this to work on:

.

if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • I have try the .htaccess way but I have this error: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. – Gianluca Lodigiani May 12 '12 at 00:54
0

at the end I have found this:

if ( get_magic_quotes_gpc() ) {
    $_POST      = array_map( 'stripslashes_deep', $_POST );
    $_GET       = array_map( 'stripslashes_deep', $_GET );
    $_COOKIE    = array_map( 'stripslashes_deep', $_COOKIE );
    $_REQUEST   = array_map( 'stripslashes_deep', $_REQUEST ); 
}

to set at the begin of my page.

and it works.

thanks to all.