WordPress.org

Make WordPress Core

Ticket #17856: magic_quotes.diff

File magic_quotes.diff, 4.0 KB (added by troydavisson, 10 years ago)
  • wp-includes/load.php

     
    645645        return false;
    646646}
    647647
     648/**
     649 * Loads getters for _GET, _POST, _SERVER and _COOKIE as provided by PHP
     650 * minus magic_quotes_gpc escaping
     651 *
     652 * @access private
     653 * @since x.x
     654 */
     655function wp_input_init() {
     656        wp_input_get();
     657        wp_input_post();
     658        wp_input_cookie();
     659        wp_input_server();
     660}
     661
     662/**
     663 * Goes through the provided super global and strips slashes if magic_quotes_qpc
     664 * is turned on
     665 *
     666 * @param array $superglobal
     667 * @return array Cleaned super global
     668 */
     669function wp_input_load($superglobal) {
     670        if ( get_magic_quotes_gpc() )
     671                $superglobal = stripslashes_deep($superglobal);
     672        return $superglobal;
     673}
     674
     675/**
     676 * Getter for the _GET superglobal
     677 *
     678 * @staticvar boolean $loaded Determines if array has been loaded
     679 * @staticvar array $vals Holds the super global values for fetching later
     680 * @param string $key Name of specific key to fetch
     681 * @return mixed Value of the super global key or null
     682 */
     683function wp_input_get($key = null) {
     684        static $loaded = false;
     685        static $vals = array();
     686
     687        if ( !$loaded ) {
     688                $vals = wp_input_load($_GET);
     689                $loaded = true;
     690                return true;
     691        }
     692
     693        if ( array_key_exists( $key, $vals ) )
     694                return $vals[$key];
     695        return null;
     696
     697}
     698
     699/**
     700 * Getter for the _POST superglobal
     701 *
     702 * @staticvar boolean $loaded Determines if array has been loaded
     703 * @staticvar array $vals Holds the super global values for fetching later
     704 * @param string $key Name of specific key to fetch
     705 * @return mixed Value of the super global key or null
     706 */
     707function wp_input_post($key = null) {
     708        static $loaded = false;
     709        static $vals = array();
     710
     711        if ( !$loaded ) {
     712                $vals = wp_input_load($_POST);
     713                $loaded = true;
     714                return true;
     715        }
     716
     717        if ( array_key_exists( $key, $vals ) )
     718                return $vals[$key];
     719        return null;
     720
     721}
     722
     723/**
     724 * Getter for _GET and _POST (similar to _REQUEST).  Checks _POST first and then _GET
     725 *
     726 * @param string $key
     727 * @return mixed Value of super global or null if none found
     728 */
     729function wp_input_get_post($key) {
     730        $var_post = wp_input_post($key);
     731        if ( $var_post !== null )
     732                return $var_post;
     733        $var_get = wp_input_get($key);
     734        if ( $var_get !== null )
     735                return $var_get;
     736        return null;
     737}
     738
     739/**
     740 * Getter for the _COOKIE superglobal
     741 *
     742 * @staticvar boolean $loaded Determines if array has been loaded
     743 * @staticvar array $vals Holds the super global values for fetching later
     744 * @param string $key Name of specific key to fetch
     745 * @return mixed Value of the super global key or null
     746 */
     747function wp_input_cookie($key = null) {
     748        static $loaded = false;
     749        static $vals = array();
     750
     751        if ( !$loaded ) {
     752                $vals = wp_input_load($_COOKIE);
     753                $loaded = true;
     754                return true;
     755        }
     756
     757        if ( array_key_exists( $key, $vals ) )
     758                return $vals[$key];
     759        return null;
     760
     761}
     762
     763/**
     764 * Getter for the _SERVER superglobal. No magic_quotes_gpc cleaning needed
     765 *
     766 * @staticvar boolean $loaded Determines if array has been loaded
     767 * @staticvar array $vals Holds the super global values for fetching later
     768 * @param string $key Name of specific key to fetch
     769 * @return mixed Value of the super global key or null
     770 */
     771function wp_input_server($key = null) {
     772        static $loaded = false;
     773        static $vals = array();
     774
     775        if ( !$loaded ) {
     776                $vals = $_SERVER;
     777                $loaded = true;
     778                return true;
     779        }
     780
     781        if ( array_key_exists( $key, $vals ) )
     782                return $vals[$key];
     783        return null;
     784
     785}
     786
     787
    648788?>
  • wp-settings.php

     
    138138require( ABSPATH . WPINC . '/nav-menu-template.php' );
    139139require( ABSPATH . WPINC . '/admin-bar.php' );
    140140
     141// Set initial getters for _GET, _POST, _COOKIE and _SERVER
     142wp_input_init();
     143
    141144// Load multisite-specific files.
    142145if ( is_multisite() ) {
    143146        require( ABSPATH . WPINC . '/ms-functions.php' );