PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-filter-input.php +44 -45 trunk3.8.2 View file →
@@ -17,27 +17,27 @@
17 17 *
18 18 * @var array
19 19 */
20 20 public static $filter_callbacks = array(
21 - FILTER_DEFAULT => null,
21 + FILTER_DEFAULT => null,
22 22 // Validate.
23 - FILTER_VALIDATE_BOOLEAN => 'is_bool',
24 - FILTER_VALIDATE_EMAIL => 'is_email',
25 - FILTER_VALIDATE_FLOAT => 'is_float',
26 - FILTER_VALIDATE_INT => 'is_int',
27 - FILTER_VALIDATE_IP => array( __CLASS__, 'is_ip_address' ),
28 - FILTER_VALIDATE_REGEXP => array( __CLASS__, 'is_regex' ),
29 - FILTER_VALIDATE_URL => 'wp_http_validate_url',
23 + FILTER_VALIDATE_BOOLEAN => 'is_bool',
24 + FILTER_VALIDATE_EMAIL => 'is_email',
25 + FILTER_VALIDATE_FLOAT => 'is_float',
26 + FILTER_VALIDATE_INT => 'is_int',
27 + FILTER_VALIDATE_IP => array( __CLASS__, 'is_ip_address' ),
28 + FILTER_VALIDATE_REGEXP => array( __CLASS__, 'is_regex' ),
29 + FILTER_VALIDATE_URL => 'wp_http_validate_url',
30 30 // Sanitize.
31 - FILTER_SANITIZE_EMAIL => 'sanitize_email',
32 - FILTER_SANITIZE_ENCODED => 'esc_url_raw',
33 - FILTER_SANITIZE_NUMBER_FLOAT => 'floatval',
34 - FILTER_SANITIZE_NUMBER_INT => 'intval',
35 - FILTER_SANITIZE_SPECIAL_CHARS => 'htmlspecialchars',
36 - FILTER_SANITIZE_FULL_SPECIAL_CHARS => 'sanitize_text_field',
37 - FILTER_SANITIZE_URL => 'esc_url_raw',
31 + FILTER_SANITIZE_EMAIL => 'sanitize_email',
32 + FILTER_SANITIZE_ENCODED => 'esc_url_raw',
33 + FILTER_SANITIZE_NUMBER_FLOAT => 'floatval',
34 + FILTER_SANITIZE_NUMBER_INT => 'intval',
35 + FILTER_SANITIZE_SPECIAL_CHARS => 'htmlspecialchars',
36 + FILTER_SANITIZE_STRING => 'sanitize_text_field',
37 + FILTER_SANITIZE_URL => 'esc_url_raw',
38 38 // Other.
39 - FILTER_UNSAFE_RAW => null,
39 + FILTER_UNSAFE_RAW => null,
40 40 );
41 41
42 42 /**
43 43 * Returns input variable
@@ -75,36 +75,35 @@
75 75 if ( is_null( $super ) ) {
76 76 throw new \Exception( esc_html__( 'Invalid use, type must be one of INPUT_* family.', 'stream' ) );
77 77 }
78 78
79 - $value = isset( $super[ $variable_name ] ) ? $super[ $variable_name ] : null;
80 - $value = self::filter( $value, $filter, $options );
79 + $var = isset( $super[ $variable_name ] ) ? $super[ $variable_name ] : null;
80 + $var = self::filter( $var, $filter, $options );
81 81
82 - return $value;
82 + return $var;
83 83 }
84 84
85 85 /**
86 86 * Sanitize or validate input.
87 87 *
88 - * @param mixed $value Raw input value.
89 - * @param int $filter Filter callback.
90 - * @param array $options Filter callback parameters.
91 - *
88 + * @param mixed $var Raw input.
89 + * @param int $filter Filter callback.
90 + * @param array $options Filter callback parameters.
91 + * @throws \Exception Unsupported filter provided.
92 92 * @return mixed
93 - * @throws \Exception Unsupported filter provided.
94 93 */
95 - public static function filter( $value, $filter = null, $options = array() ) {
94 + public static function filter( $var, $filter = null, $options = array() ) {
96 95 // Default filter is a sanitizer, not validator.
97 96 $filter_type = 'sanitizer';
98 97
99 98 // Only filter value if it is not null.
100 - if ( isset( $value ) && $filter && FILTER_DEFAULT !== $filter ) {
99 + if ( isset( $var ) && $filter && FILTER_DEFAULT !== $filter ) {
101 100 if ( ! isset( self::$filter_callbacks[ $filter ] ) ) {
102 101 throw new \Exception( esc_html__( 'Filter not supported.', 'stream' ) );
103 102 }
104 103
105 104 $filter_callback = self::$filter_callbacks[ $filter ];
106 - $result = call_user_func( $filter_callback, $value );
105 + $result = call_user_func( $filter_callback, $var );
107 106
108 107 /**
109 108 * "filter_var / filter_input" treats validation/sanitization filters the same
110 109 * they both return output and change the var value, this shouldn't be the case here.
@@ -112,43 +111,44 @@
112 111 */
113 112 $filter_type = ( $filter < 500 ) ? 'validator' : 'sanitizer';
114 113 if ( 'validator' === $filter_type ) { // Validation functions.
115 114 if ( ! $result ) {
116 - $value = false;
115 + $var = false;
117 116 }
118 117 } else { // Santization functions.
119 - $value = $result;
118 + $var = $result;
120 119 }
121 120 }
122 121
123 122 // Detect FILTER_REQUIRE_ARRAY flag.
124 - if ( isset( $value ) && is_int( $options ) && FILTER_REQUIRE_ARRAY === $options ) {
125 - if ( ! is_array( $value ) ) {
126 - $value = ( 'validator' === $filter_type ) ? false : null;
123 + if ( isset( $var ) && is_int( $options ) && FILTER_REQUIRE_ARRAY === $options ) {
124 + if ( ! is_array( $var ) ) {
125 + $var = ( 'validator' === $filter_type ) ? false : null;
127 126 }
128 127 }
129 128
130 129 // Polyfill the `default` attribute only, for now.
131 130 if ( is_array( $options ) && ! empty( $options['options']['default'] ) ) {
132 - if ( 'validator' === $filter_type && false === $value ) {
133 - $value = $options['options']['default'];
134 - } elseif ( 'sanitizer' === $filter_type && null === $value ) {
135 - $value = $options['options']['default'];
131 + if ( 'validator' === $filter_type && false === $var ) {
132 + $var = $options['options']['default'];
133 + } elseif ( 'sanitizer' === $filter_type && null === $var ) {
134 + $var = $options['options']['default'];
136 135 }
137 136 }
138 137
139 - return $value;
138 + return $var;
140 139 }
141 140
142 141 /**
143 142 * Returns whether the variable is a Regular Expression or not?
144 143 *
145 - * @param string $maybe_regex Raw input value.
146 - *
144 + * @param string $var Raw input.
147 145 * @return boolean
148 146 */
149 - public static function is_regex( $maybe_regex ) {
150 - $test = @preg_match( $maybe_regex, '' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
147 + public static function is_regex( $var ) {
148 + // @codingStandardsIgnoreStart
149 + $test = @preg_match( $var, '' );
150 + // @codingStandardsIgnoreEnd
151 151
152 152 return false !== $test;
153 153 }
154 154
@@ -154,12 +154,11 @@
154 154
155 155 /**
156 156 * Returns whether the variable is an IP address or not?
157 157 *
158 - * @param string $maybe_ip Raw input.
159 - *
158 + * @param string $var Raw input.
160 159 * @return boolean
161 160 */
162 - public static function is_ip_address( $maybe_ip ) {
163 - return false !== \WP_Http::is_ip_address( $maybe_ip );
161 + public static function is_ip_address( $var ) {
162 + return false !== \WP_Http::is_ip_address( $var );
164 163 }
165 164 }