Home > Backend Development > PHP Tutorial > Why is WordPress Still Escaping Data After Disabling Magic Quotes?

Why is WordPress Still Escaping Data After Disabling Magic Quotes?

Patricia Arquette
Release: 2024-10-29 06:56:02
Original
349 people have browsed it

Why is WordPress Still Escaping Data After Disabling Magic Quotes?

WordPress' Auto-Escaping Quandary with Magic Quotes Disabled

Despite disabling magic quotes in PHP's configuration, WordPress continues to automatically escape POST data, particularly single quotes. This puzzling behavior has often baffled developers.

Cause and Solution

The root cause lies within WordPress's bootstrapping process. WordPress initiates auto-escaping when its multisite functionality is active. To resolve this, add the following code before WordPress is bootstrapped:

<code class="php">$_GET       = array_map('stripslashes_deep', $_GET);
$_POST      = array_map('stripslashes_deep', $_POST);
$_COOKIE    = array_map('stripslashes_deep', $_COOKIE);
$_SERVER    = array_map('stripslashes_deep', $_SERVER);
$_REQUEST   = array_map('stripslashes_deep', $_REQUEST);</code>
Copy after login

This code will strip slashes from WordPress's request objects before auto-escaping occurs.

Alternative Approaches

While stripslashes_deep effectively addresses the issue, consider these alternative approaches:

  • Use "strip locally": Only strip slashes from specific POST data elements. For instance: $post = array_map('stripslashes_deep', $_POST);
  • Disable WordPress's auto-escaping: Add define('AUTOMATIC_ESCAPING_DISABLED', true); to your WordPress configuration file (wp-config.php). This disables auto-escaping, but it should be used cautiously.

The above is the detailed content of Why is WordPress Still Escaping Data After Disabling Magic Quotes?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template