Ejemplo n.º 1
0
 /**
  * Create a new instance from `$_GET`, `$_POST` and `$_SERVER` superglobals.
  *
  * @return MC4WP_Request
  */
 public static function create_from_globals()
 {
     $get = mc4wp_sanitize_deep($_GET);
     $get = stripslashes_deep($get);
     $post = mc4wp_sanitize_deep($_POST);
     $post = stripslashes_deep($post);
     $server = mc4wp_sanitize_deep($_SERVER);
     return new self($get, $post, $server);
 }
Ejemplo n.º 2
0
 /**
  * Create a new instance from `$_GET`, `$_POST` and `$_SERVER` superglobals.
  *
  * @return MC4WP_Request
  */
 public static function create_from_globals()
 {
     $get_data = is_array($_GET) ? $_GET : array();
     $get_data = mc4wp_sanitize_deep($get_data);
     $get_data = stripslashes_deep($get_data);
     $post_data = is_array($_POST) ? $_POST : array();
     $post_data = mc4wp_sanitize_deep($post_data);
     $post_data = stripslashes_deep($post_data);
     $server_data = is_array($_SERVER) ? $_SERVER : array();
     $server_data = mc4wp_sanitize_deep($server_data);
     return new self($get_data, $post_data, $server_data);
 }
 /**
  * Load stored data from cookie.
  */
 public function load()
 {
     if (empty($this->data)) {
         if (!empty($_COOKIE[self::COOKIE_NAME])) {
             $raw = stripslashes($_COOKIE[self::COOKIE_NAME]);
             $data = json_decode($raw, true);
             if (is_array($data)) {
                 $this->data = mc4wp_sanitize_deep($data);
             }
         }
     }
     return $this->data;
 }
/**
 * Sanitizes all values in a mixed variable.
 *
 * @access public
 *
 * @param mixed $value
 *
 * @return mixed
 */
function mc4wp_sanitize_deep($value)
{
    if (is_scalar($value)) {
        $value = sanitize_text_field($value);
    } elseif (is_array($value)) {
        $value = array_map('mc4wp_sanitize_deep', $value);
    } elseif (is_object($value)) {
        $vars = get_object_vars($value);
        foreach ($vars as $key => $data) {
            $value->{$key} = mc4wp_sanitize_deep($data);
        }
    }
    return $value;
}