wordpress magic quotes by php code

958 Views Asked by At

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.

2

There are 2 best solutions below

0
Gianluca Lodigiani On BEST ANSWER

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.

1
John Conde On
  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);
}