wp_magic_quotes()WP 3.0.0

Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.

Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE, or $_ENV are needed, use those superglobals directly.

1 time — 0.000084 sec (very fast) | 50000 times — 1.83 sec (fast) | PHP 7.0.8, WP 4.6.1

No Hooks.

Return

null. Nothing.

Usage

wp_magic_quotes();

Examples

0

#1 Remove backslashes where they are unnecessary

When you receive a JSON string, you need to clean it up in order to parse it later and use it in your code.

$json = strval( $_POST['urls'] );

// Unfortunately, WP applies magic quotes to POST data.
if ( function_exists('wp_magic_quotes') && did_action('plugins_loaded') ) {

	$json = stripslashes( $json );
}

Changelog

Since 3.0.0 Introduced.

Code of wp_magic_quotes() WP 6.0

function wp_magic_quotes() {
	// Escape with wpdb.
	$_GET    = add_magic_quotes( $_GET );
	$_POST   = add_magic_quotes( $_POST );
	$_COOKIE = add_magic_quotes( $_COOKIE );
	$_SERVER = add_magic_quotes( $_SERVER );

	// Force REQUEST to be GET + POST.
	$_REQUEST = array_merge( $_GET, $_POST );
}