From 08df15ab586b50f3fd34db2ad5c67c6fc1a3a145 Mon Sep 17 00:00:00 2001
From: Aaron Jorbin <jorbin@git.wordpress.org>
Date: Fri, 13 Sep 2019 22:19:34 +0000
Subject: [PATCH] GENERAL: Remove magic quote functions

The path to magic quote sanity took a fun and exciting turn: PHP core removed it and WordPress updated the minimum version.

For the formally external pclzip, the code is commented out to make investigating easier and in case we ever need to merge upstream (if that still exists) changes.

Props ayeshrajans, jrf, jorbin.
See #47783.
Fixes #18322.


git-svn-id: https://develop.svn.wordpress.org/trunk@46105 602fd350-edb4-49c9-b593-d223f7449a82
---
 src/wp-admin/includes/class-pclzip.php             | 10 ++++++++++
 src/wp-includes/formatting.php                     | 10 +---------
 src/wp-includes/load.php                           |  7 -------
 src/wp-includes/rest-api/class-wp-rest-request.php |  9 ---------
 4 files changed, 11 insertions(+), 25 deletions(-)

diff --git a/src/wp-admin/includes/class-pclzip.php b/src/wp-admin/includes/class-pclzip.php
index ae0af7a8f1..aaaeef5804 100644
--- a/src/wp-admin/includes/class-pclzip.php
+++ b/src/wp-admin/includes/class-pclzip.php
@@ -5326,6 +5326,10 @@
   {
     $v_result=1;
 
+	// EDIT for WordPress 5.3.0
+	// magic_quote functions are deprecated in PHP 7.4, now assuming it's always off.
+	/*
+
     // ----- Look if function exists
     if (   (!function_exists("get_magic_quotes_runtime"))
 	    || (!function_exists("set_magic_quotes_runtime"))) {
@@ -5344,6 +5348,7 @@
 	if ($this->magic_quotes_status == 1) {
 	  @set_magic_quotes_runtime(0);
 	}
+	*/
 
     // ----- Return
     return $v_result;
@@ -5360,6 +5365,10 @@
   {
     $v_result=1;
 
+	// EDIT for WordPress 5.3.0
+	// magic_quote functions are deprecated in PHP 7.4, now assuming it's always off.
+	/*
+
     // ----- Look if function exists
     if (   (!function_exists("get_magic_quotes_runtime"))
 	    || (!function_exists("set_magic_quotes_runtime"))) {
@@ -5376,6 +5385,7 @@
   	  @set_magic_quotes_runtime($this->magic_quotes_status);
 	}
 
+	*/
     // ----- Return
     return $v_result;
   }
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index fd9fca04f0..d953b8796b 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -2713,10 +2713,6 @@ function untrailingslashit( $string ) {
  * @return string Returns a string escaped with slashes.
  */
 function addslashes_gpc( $gpc ) {
-	if ( get_magic_quotes_gpc() ) {
-		$gpc = stripslashes( $gpc );
-	}
-
 	return wp_slash( $gpc );
 }
 
@@ -4782,8 +4778,6 @@ function map_deep( $value, $callback ) {
 /**
  * Parses a string into variables to be stored in an array.
  *
- * Uses {@link https://secure.php.net/parse_str parse_str()} and stripslashes if
- * {@link https://secure.php.net/magic_quotes magic_quotes_gpc} is on.
  *
  * @since 2.2.1
  *
@@ -4792,9 +4786,7 @@ function map_deep( $value, $callback ) {
  */
 function wp_parse_str( $string, &$array ) {
 	parse_str( $string, $array );
-	if ( get_magic_quotes_gpc() ) {
-		$array = stripslashes_deep( $array );
-	}
+
 	/**
 	 * Filters the array of variables derived from a parsed string.
 	 *
diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php
index 2c63c6b277..be56883040 100644
--- a/src/wp-includes/load.php
+++ b/src/wp-includes/load.php
@@ -925,13 +925,6 @@ function wp_set_internal_encoding() {
  * @access private
  */
 function wp_magic_quotes() {
-	// If already slashed, strip.
-	if ( get_magic_quotes_gpc() ) {
-		$_GET    = stripslashes_deep( $_GET );
-		$_POST   = stripslashes_deep( $_POST );
-		$_COOKIE = stripslashes_deep( $_COOKIE );
-	}
-
 	// Escape with wpdb.
 	$_GET    = add_magic_quotes( $_GET );
 	$_POST   = add_magic_quotes( $_POST );
diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php
index ab281179eb..7b2a32e618 100644
--- a/src/wp-includes/rest-api/class-wp-rest-request.php
+++ b/src/wp-includes/rest-api/class-wp-rest-request.php
@@ -689,15 +689,6 @@ class WP_REST_Request implements ArrayAccess {
 
 		parse_str( $this->get_body(), $params );
 
-		/*
-		 * Amazingly, parse_str follows magic quote rules. Sigh.
-		 *
-		 * NOTE: Do not refactor to use `wp_unslash`.
-		 */
-		if ( get_magic_quotes_gpc() ) {
-			$params = stripslashes_deep( $params );
-		}
-
 		/*
 		 * Add to the POST parameters stored internally. If a user has already
 		 * set these manually (via `set_body_params`), don't override them.