WordPress.org

Make WordPress Core

Ticket #18322: 18322.2.diff

File 18322.2.diff, 6.4 KB (added by NathanAtmoz, 3 years ago)
  • src/wp-includes/class-wp-request.php

    diff --git a/src/wp-includes/class-wp-request.php b/src/wp-includes/class-wp-request.php
    index e69de29..e728e10 100644
    a b  
     1<?php
     2/**
     3 * WordPress Request API.
     4 *
     5 * @package WordPress
     6 */
     7
     8/**
     9 * WordPress Request class.
     10 *
     11 * Core class used to implement unslashed GET, POST, COOKIE, SERVER, REQUEST functionality.
     12 *
     13 * @since 5.0.0
     14 */
     15final class WP_Request {
     16  /**
     17         * Unslashed GET superglobal.
     18         *
     19         * @since 5.0.0
     20         * @var array
     21         */
     22        private $get = array();
     23
     24        /**
     25         * Unslashed POST superglobal.
     26         *
     27         * @since 5.0.0
     28         * @var array
     29         */
     30        private $post = array();
     31
     32        /**
     33         * Unslashed COOKIE superglobal.
     34         *
     35         * @since 5.0.0
     36         * @var array
     37         */
     38        private $cookie = array();
     39
     40        /**
     41         * Unslashed server superglobal.
     42         *
     43         * @since 5.0.0
     44         * @var array
     45         */
     46        private $server = array();
     47
     48        /**
     49         * Unslashed REQUEST superglobal.
     50         *
     51         * @since 5.0.0
     52         * @var array
     53         */
     54        private $request = array();
     55
     56  /**
     57         * Static instance of this class.
     58         *
     59         * @since 5.0.0
     60         * @var $this
     61         */
     62  private static $instance = null;
     63
     64  /**
     65   * Class constructor. Set superglobals.
     66   *
     67   * @since 5.0.0
     68   */
     69  private function __construct() {
     70    $this->get     = $_GET;
     71    $this->post    = $_POST;
     72    $this->cookie  = $_COOKIE;
     73    $this->server  = $_SERVER;
     74    $this->request = $_REQUEST;
     75  }
     76
     77  /**
     78   * Return an instance of the WP_Request class.
     79   *
     80   * @since 5.0.0
     81   *
     82   * @return WP_Request An instance of this class.
     83   */
     84  public static function getInstance() {
     85    if( null === self::$instance ) {
     86      self::$instance = new WP_Request();
     87    }
     88    return self::$instance;
     89  }
     90
     91  /**
     92   * Declared to prevent cloning of the class.
     93   *
     94   * @since 5.0.0
     95   */
     96  private function __clone() {}
     97
     98  /**
     99   * Declared to prevent unserializing of the class.
     100   *
     101   * @since 5.0.0
     102   */
     103  private function __wakeup() {}
     104
     105  /**
     106   * Retrieve an unslashed GET variable.
     107   *
     108   * @since 5.0.0
     109   * @param string $key GET variable string.
     110   * @return mixed GET variable if one is set. Otherwise null.
     111   */
     112  public function get( $key ) {
     113    return $this->retrieve( 'get', $key );
     114  }
     115
     116  /**
     117   * Retrieve an unslashed POST variable.
     118   *
     119   * @since 5.0.0
     120   * @param string $key POST variable string.
     121   * @return mixed POST variable if one is set. Otherwise null.
     122   */
     123  public function post( $key ) {
     124    return $this->retrieve( 'post', $key );
     125  }
     126
     127  /**
     128   * Retrieve an unslashed COOKIE variable.
     129   *
     130   * @since 5.0.0
     131   * @param string $key COOKIE variable string.
     132   * @return mixed COOKIE variable if one is set. Otherwise null.
     133   */
     134  public function cookie( $key ) {
     135    return $this->retrieve( 'cookie', $key );
     136  }
     137
     138  /**
     139   * Retrieve an unslashed SERVER variable.
     140   *
     141   * @since 5.0.0
     142   * @param string $key SERVER variable string.
     143   * @return mixed SERVER variable if one is set. Otherwise null.
     144   */
     145  public function server( $key ) {
     146    return $this->retrieve( 'server', $key );
     147  }
     148
     149  /**
     150   * Retrieve an unslashed REQUEST variable.
     151   *
     152   * @since 5.0.0
     153   * @param string $key REQUEST variable string.
     154   * @return mixed REQUEST variable if one is set. Otherwise null.
     155   */
     156  public function request( $key ) {
     157    return $this->retrieve( 'request', $key );
     158  }
     159
     160  /**
     161   * Retrieve an unslashed variable.
     162   *
     163   * @since 5.0.0
     164   * @param string $kind Which of the globals to retrieve: get, post, cookie, server, or request.
     165   * @param string $key  Variable string.
     166   * @return mixed Variable if one is set. Otherwise null.
     167   */
     168  private function retrieve( $kind, $key ) {
     169    return is_string( $key ) && isset( $this->$kind[ $key ] ) ? $this->$kind[ $key ] : null;
     170  }
     171}
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index ec5a3d2..b2e83b2 100644
    a b All at ###SITENAME### 
    60756075                ), $email_change_email['message'], $email_change_email['headers']
    60766076        );
    60776077}
     6078
     6079/**
     6080 * Return the unslashed GET variable.
     6081 *
     6082 * @since 5.0.0
     6083 *
     6084 * @param string $key GET variable string
     6085 * @return mixed GET variable if one is set. Otherwise null.
     6086 */
     6087function _GET( $val ) {
     6088        return WP_Request::getInstance()->get( $val );
     6089}
     6090
     6091/**
     6092 * Return the unslashed POST variable.
     6093 *
     6094 * @since 5.0.0
     6095 *
     6096 * @param string $key POST variable string
     6097 * @return mixed POST variable if one is set. Otherwise null.
     6098 */
     6099function _POST( $val ) {
     6100        return WP_Request::getInstance()->post( $val );
     6101}
     6102
     6103/**
     6104 * Return the unslashed COOKIE variable.
     6105 *
     6106 * @since 5.0.0
     6107 *
     6108 * @param string $key COOKIE variable string
     6109 * @return mixed COOKIE variable if one is set. Otherwise null.
     6110 */
     6111function _COOKIE( $val ) {
     6112        return WP_Request::getInstance()->cookie( $val );
     6113}
     6114
     6115/**
     6116 * Return the unslashed SERVER variable.
     6117 *
     6118 * @since 5.0.0
     6119 *
     6120 * @param string $key SERVER variable string
     6121 * @return mixed SERVER variable if one is set. Otherwise null.
     6122 */
     6123function _SERVER( $val ) {
     6124        return WP_Request::getInstance()->server( $val );
     6125}
     6126
     6127/**
     6128 * Return the unslashed REQUEST variable.
     6129 *
     6130 * @since 5.0.0
     6131 *
     6132 * @param string $key REQUEST variable string
     6133 * @return mixed REQUEST variable if one is set. Otherwise null.
     6134 */
     6135function _REQUEST( $val ) {
     6136        return WP_Request::getInstance()->request( $val );
     6137}
  • src/wp-settings.php

    diff --git a/src/wp-settings.php b/src/wp-settings.php
    index 6edd3c9..0cd97b9 100644
    a b require( ABSPATH . WPINC . '/class-wp-roles.php' ); 
    149149require( ABSPATH . WPINC . '/class-wp-role.php' );
    150150require( ABSPATH . WPINC . '/class-wp-user.php' );
    151151require( ABSPATH . WPINC . '/class-wp-query.php' );
     152require( ABSPATH . WPINC . '/class-wp-request.php' );
    152153require( ABSPATH . WPINC . '/query.php' );
    153154require( ABSPATH . WPINC . '/date.php' );
    154155require( ABSPATH . WPINC . '/theme.php' );
    wp_plugin_directory_constants(); 
    256257
    257258$GLOBALS['wp_plugin_paths'] = array();
    258259
     260/**
     261 * WordPress Request object.
     262 *
     263 * Get superglobals before `wp_magic_quotes()` obliterates them.
     264 *
     265 * @global WP_Request $wp_request
     266 * @since 5.0.0
     267 */
     268$GLOBALS[ 'wp_request' ] = WP_Request::getInstance();
     269
    259270// Load must-use plugins.
    260271foreach ( wp_get_mu_plugins() as $mu_plugin ) {
    261272        include_once( $mu_plugin );