| @@ 159-199 (lines=41) @@ | ||
| 156 | } |
|
| 157 | } |
|
| 158 | ||
| 159 | if ( ! function_exists( 'rest_sanitize_request_arg' ) ) { |
|
| 160 | /** |
|
| 161 | * Sanitize a request argument based on details registered to the route. |
|
| 162 | * |
|
| 163 | * @param mixed $value |
|
| 164 | * @param WP_REST_Request $request |
|
| 165 | * @param string $param |
|
| 166 | * @return mixed |
|
| 167 | */ |
|
| 168 | function rest_sanitize_request_arg( $value, $request, $param ) { |
|
| 169 | ||
| 170 | $attributes = $request->get_attributes(); |
|
| 171 | if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) { |
|
| 172 | return $value; |
|
| 173 | } |
|
| 174 | $args = $attributes['args'][ $param ]; |
|
| 175 | ||
| 176 | if ( 'integer' === $args['type'] ) { |
|
| 177 | return (int) $value; |
|
| 178 | } |
|
| 179 | ||
| 180 | if ( isset( $args['format'] ) ) { |
|
| 181 | switch ( $args['format'] ) { |
|
| 182 | case 'date-time' : |
|
| 183 | return sanitize_text_field( $value ); |
|
| 184 | ||
| 185 | case 'email' : |
|
| 186 | /* |
|
| 187 | * sanitize_email() validates, which would be unexpected |
|
| 188 | */ |
|
| 189 | return sanitize_text_field( $value ); |
|
| 190 | ||
| 191 | case 'uri' : |
|
| 192 | return esc_url_raw( $value ); |
|
| 193 | } |
|
| 194 | } |
|
| 195 | ||
| 196 | return $value; |
|
| 197 | } |
|
| 198 | ||
| 199 | } |
|
| 200 | ||
| @@ 235-275 (lines=41) @@ | ||
| 232 | } |
|
| 233 | } |
|
| 234 | ||
| 235 | if ( ! function_exists( 'rest_sanitize_request_arg' ) ) { |
|
| 236 | /** |
|
| 237 | * Sanitize a request argument based on details registered to the route. |
|
| 238 | * |
|
| 239 | * @param mixed $value |
|
| 240 | * @param WP_REST_Request $request |
|
| 241 | * @param string $param |
|
| 242 | * @return mixed |
|
| 243 | */ |
|
| 244 | function rest_sanitize_request_arg( $value, $request, $param ) { |
|
| 245 | ||
| 246 | $attributes = $request->get_attributes(); |
|
| 247 | if ( ! isset( $attributes['args'][ $param ] ) || ! is_array( $attributes['args'][ $param ] ) ) { |
|
| 248 | return $value; |
|
| 249 | } |
|
| 250 | $args = $attributes['args'][ $param ]; |
|
| 251 | ||
| 252 | if ( 'integer' === $args['type'] ) { |
|
| 253 | return (int) $value; |
|
| 254 | } |
|
| 255 | ||
| 256 | if ( isset( $args['format'] ) ) { |
|
| 257 | switch ( $args['format'] ) { |
|
| 258 | case 'date-time' : |
|
| 259 | return sanitize_text_field( $value ); |
|
| 260 | ||
| 261 | case 'email' : |
|
| 262 | /* |
|
| 263 | * sanitize_email() validates, which would be unexpected |
|
| 264 | */ |
|
| 265 | return sanitize_text_field( $value ); |
|
| 266 | ||
| 267 | case 'uri' : |
|
| 268 | return esc_url_raw( $value ); |
|
| 269 | } |
|
| 270 | } |
|
| 271 | ||
| 272 | return $value; |
|
| 273 | } |
|
| 274 | ||
| 275 | } |
|
| 276 | ||