Make WordPress Core

Ticket #22325: 22325.2.diff

File 22325.2.diff, 2.4 KB (added by rmccue, 12 years ago)

Use static variables with accessor functions

  • wp-includes/class-wp.php

    diff --git wp-includes/class-wp.php wp-includes/class-wp.php
    index 36faf66..005f03e 100644
    class WP { 
    8484        var $did_permalink = false;
    8585
    8686        /**
     87         * Unslashed GET superglobal
     88         *
     89         * @since 3.6.0
     90         * @var array
     91         */
     92        public static $GET = array();
     93
     94        /**
     95         * Unslashed POST superglobal
     96         *
     97         * @since 3.6.0
     98         * @var array
     99         */
     100        public static $POST = array();
     101
     102        /**
     103         * Unslashed REQUEST superglobal
     104         *
     105         * @since 3.6.0
     106         * @var array
     107         */
     108        public static $REQUEST = array();
     109
     110        /**
    87111         * Add name to list of public query variables.
    88112         *
    89113         * @since 2.1.0
    class WP { 
    552576                do_action_ref_array('wp', array(&$this));
    553577        }
    554578
     579        /**
     580         * Retrieve an unslashed GET variable
     581         *
     582         * @param string $key GET variable string
     583         * @param mixed $default Default value to return
     584         * @return string|array GET variable if one is set, default otherwise
     585         */
     586        public static function GET( $key, $default = null) {
     587                if ( isset( self::$GET[ $key] ) )
     588                        return self::$GET[ $key ];
     589
     590                return $default;
     591        }
     592
     593        /**
     594         * Retrieve an unslashed POST variable
     595         *
     596         * @param string $key POST variable string
     597         * @param mixed $default Default value to return
     598         * @return string|array POST variable if one is set, default otherwise
     599         */
     600        public static function POST( $key, $default = null) {
     601                if ( isset( self::$POST[ $key] ) )
     602                        return self::$POST[ $key ];
     603
     604                return $default;
     605        }
     606
     607        /**
     608         * Retrieve an unslashed REQUEST variable
     609         *
     610         * @param string $key REQUEST variable string
     611         * @param mixed $default Default value to return
     612         * @return string|array REQUEST variable if one is set, default otherwise
     613         */
     614        public static function REQUEST( $key, $default = null) {
     615                if ( isset( self::$REQUEST[ $key] ) )
     616                        return self::$REQUEST[ $key ];
     617
     618                return $default;
     619        }
    555620}
    556621
    557622/**
  • wp-includes/load.php

    diff --git wp-includes/load.php wp-includes/load.php
    index 8a94962..0c4c547 100644
    function wp_magic_quotes() { 
    537537                $_COOKIE = stripslashes_deep( $_COOKIE );
    538538        }
    539539
     540        // During setup, we don't have a global request object
     541        if ( class_exists( 'WP' ) ) {
     542                // Store the unslashed superglobals
     543                WP::$GET     = $_GET;
     544                WP::$POST    = $_POST;
     545                WP::$REQUEST = array_merge( $_GET, $_POST );
     546        }
     547
    540548        // Escape with wpdb.
    541549        $_GET    = add_magic_quotes( $_GET    );
    542550        $_POST   = add_magic_quotes( $_POST   );