| @@ -27,10 +27,10 @@ | ||
| 27 | 27 | const TYPE_ARRAY = 'array'; |
| 28 | 28 | const TYPE_TEXTAREA = 'textarea'; |
| 29 | 29 | const TYPE_KSES_POST = 'kses-post'; |
| 30 | 30 | |
| 31 | - const GET_REQUEST = 'get'; | |
| 32 | - const POST_REQUEST = 'post'; | |
| 31 | + private const GET_REQUEST = 'get'; | |
| 32 | + private const POST_REQUEST = 'post'; | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Common data sanitizer method |
| 36 | 36 | * |
| @@ -146,8 +146,9 @@ | ||
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $sanitized_value; |
| 150 | + | |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | /** |
| 153 | 154 | * Dynamically get value |
| @@ -216,66 +217,18 @@ | ||
| 216 | 217 | /** |
| 217 | 218 | * Check input has key or not |
| 218 | 219 | * |
| 219 | 220 | * @since 2.0.2 |
| 220 | - * @since 4.0.0 param $method added. | |
| 221 | 221 | * |
| 222 | 222 | * @param string $key input key name. |
| 223 | - * @param string $method request method. | |
| 224 | - * | |
| 225 | 223 | * @return boolean |
| 226 | 224 | */ |
| 227 | - public static function has( $key, $method = '' ) { | |
| 228 | - if ( empty( $method ) ) { | |
| 229 | - //phpcs:ignore WordPress.Security.NonceVerification | |
| 230 | - return isset( $_REQUEST[ $key ] ); | |
| 231 | - } | |
| 232 | - | |
| 225 | + public static function has( $key ) { | |
| 233 | 226 | //phpcs:ignore WordPress.Security.NonceVerification |
| 234 | - return self::GET_REQUEST === $method ? isset( $_GET[ $key ] ) : isset( $_POST[ $key ] ); | |
| 227 | + return isset( $_REQUEST[ $key ] ); | |
| 235 | 228 | } |
| 236 | 229 | |
| 237 | 230 | /** |
| 238 | - * Check input has any keys. | |
| 239 | - * | |
| 240 | - * @since 4.0.0 | |
| 241 | - * | |
| 242 | - * @param array $keys keys. | |
| 243 | - * @param string $method request method. | |
| 244 | - * | |
| 245 | - * @return boolean | |
| 246 | - */ | |
| 247 | - public static function has_any( array $keys, $method = '' ) { | |
| 248 | - foreach ( $keys as $key ) { | |
| 249 | - if ( self::has( $key, $method ) ) { | |
| 250 | - return true; | |
| 251 | - } | |
| 252 | - } | |
| 253 | - | |
| 254 | - return false; | |
| 255 | - } | |
| 256 | - | |
| 257 | - /** | |
| 258 | - * Check input has all keys. | |
| 259 | - * | |
| 260 | - * @since 4.0.0 | |
| 261 | - * | |
| 262 | - * @param array $keys keys. | |
| 263 | - * @param string $method request method. | |
| 264 | - * | |
| 265 | - * @return boolean | |
| 266 | - */ | |
| 267 | - public static function has_all( array $keys, $method = '' ) { | |
| 268 | - foreach ( $keys as $key ) { | |
| 269 | - if ( ! self::has( $key, $method ) ) { | |
| 270 | - return false; | |
| 271 | - } | |
| 272 | - } | |
| 273 | - | |
| 274 | - return true; | |
| 275 | - } | |
| 276 | - | |
| 277 | - /** | |
| 278 | 231 | * Sanitize & unslash a request data |
| 279 | 232 | * |
| 280 | 233 | * @since 2.1.3 |
| 281 | 234 | * |
| @@ -312,9 +265,9 @@ | ||
| 312 | 265 | * @param bool $allow_iframe if set true then iframe tag will be allowed. |
| 313 | 266 | * |
| 314 | 267 | * @return array |
| 315 | 268 | */ |
| 316 | - public static function sanitize_array( array $input, array $sanitize_mapping = array(), $allow_iframe = false ): array { | |
| 269 | + public static function sanitize_array( array $input, array $sanitize_mapping = array(), $allow_iframe = false ):array { | |
| 317 | 270 | $array = array(); |
| 318 | 271 | |
| 319 | 272 | if ( $allow_iframe ) { |
| 320 | 273 | add_filter( 'wp_kses_allowed_html', __CLASS__ . '::allow_iframe', 10, 2 ); |
| @@ -331,9 +284,9 @@ | ||
| 331 | 284 | if ( isset( $sanitize_mapping[ $key ] ) ) { |
| 332 | 285 | $callback = $sanitize_mapping[ $key ]; |
| 333 | 286 | $value = call_user_func( $callback, wp_unslash( $value ) ); |
| 334 | 287 | } else { |
| 335 | - $value = is_null( $value ) ? null : sanitize_text_field( wp_unslash( $value ) ); | |
| 288 | + $value = sanitize_text_field( wp_unslash( $value ) ); | |
| 336 | 289 | } |
| 337 | 290 | $array[ $key ] = $value; |
| 338 | 291 | } |
| 339 | 292 | } |
| @@ -363,212 +316,6 @@ | ||
| 363 | 316 | 'allow' => true, |
| 364 | 317 | 'style' => true, |
| 365 | 318 | ); |
| 366 | 319 | return $tags; |
| 367 | - } | |
| 368 | - | |
| 369 | - /** | |
| 370 | - * This method is used with wp_kses_allowed_html filter | |
| 371 | - * to allow svg tags. | |
| 372 | - * | |
| 373 | - * @since 4.0.0 | |
| 374 | - * | |
| 375 | - * @param array $allowed_tags allowed HTML tags. | |
| 376 | - * | |
| 377 | - * @return array | |
| 378 | - */ | |
| 379 | - public static function allow_svg( $allowed_tags ) { | |
| 380 | - $attr_id = array( 'id' => true ); | |
| 381 | - $attr_fill = array( 'fill' => true ); | |
| 382 | - $attr_dims = array( | |
| 383 | - 'width' => true, | |
| 384 | - 'height' => true, | |
| 385 | - 'x' => true, | |
| 386 | - 'y' => true, | |
| 387 | - ); | |
| 388 | - $attr_transform = array( 'transform' => true ); | |
| 389 | - $attr_clip = array( | |
| 390 | - 'clip-path' => true, | |
| 391 | - 'clip-rule' => true, | |
| 392 | - ); | |
| 393 | - $attr_center = array( | |
| 394 | - 'cx' => true, | |
| 395 | - 'cy' => true, | |
| 396 | - ); | |
| 397 | - $attr_stroke = array( | |
| 398 | - 'stroke' => true, | |
| 399 | - 'stroke-width' => true, | |
| 400 | - 'stroke-linecap' => true, | |
| 401 | - 'stroke-linejoin' => true, | |
| 402 | - 'stroke-dasharray' => true, | |
| 403 | - 'stroke-dashoffset' => true, | |
| 404 | - ); | |
| 405 | - $attr_style = array( 'style' => true ); | |
| 406 | - $attr_opacity = array( 'opacity' => true ); | |
| 407 | - $attr_xlink = array( 'xlink:href' => true ); | |
| 408 | - | |
| 409 | - $svg_tags = array( | |
| 410 | - 'svg' => array_merge( | |
| 411 | - $attr_id, | |
| 412 | - $attr_fill, | |
| 413 | - $attr_dims, | |
| 414 | - $attr_style, | |
| 415 | - array( | |
| 416 | - 'class' => true, | |
| 417 | - 'aria-hidden' => true, | |
| 418 | - 'aria-label' => true, | |
| 419 | - 'role' => true, | |
| 420 | - 'xmlns' => true, | |
| 421 | - 'viewbox' => true, | |
| 422 | - 'viewBox' => true, | |
| 423 | - 'opacity' => true, | |
| 424 | - ) | |
| 425 | - ), | |
| 426 | - 'g' => array_merge( | |
| 427 | - $attr_id, | |
| 428 | - $attr_fill, | |
| 429 | - $attr_clip, | |
| 430 | - $attr_transform, | |
| 431 | - $attr_style, | |
| 432 | - $attr_opacity | |
| 433 | - ), | |
| 434 | - 'defs' => array(), | |
| 435 | - 'clipPath' => $attr_id, | |
| 436 | - 'clippath' => $attr_id, | |
| 437 | - 'path' => array_merge( | |
| 438 | - $attr_id, | |
| 439 | - $attr_fill, | |
| 440 | - $attr_stroke, | |
| 441 | - $attr_clip, | |
| 442 | - $attr_transform, | |
| 443 | - $attr_style, | |
| 444 | - array( | |
| 445 | - 'd' => true, | |
| 446 | - 'fill-rule' => true, | |
| 447 | - 'mask' => true, | |
| 448 | - 'opacity' => true, | |
| 449 | - ) | |
| 450 | - ), | |
| 451 | - 'mask' => array_merge( | |
| 452 | - $attr_id, | |
| 453 | - $attr_fill, | |
| 454 | - $attr_dims, | |
| 455 | - $attr_style, | |
| 456 | - array( | |
| 457 | - 'maskunits' => true, | |
| 458 | - 'mask-type' => true, | |
| 459 | - 'opacity' => true, | |
| 460 | - ) | |
| 461 | - ), | |
| 462 | - 'circle' => array_merge( | |
| 463 | - $attr_id, | |
| 464 | - $attr_fill, | |
| 465 | - $attr_center, | |
| 466 | - $attr_transform, | |
| 467 | - $attr_stroke, | |
| 468 | - $attr_style, | |
| 469 | - array( | |
| 470 | - 'r' => true, | |
| 471 | - 'opacity' => true, | |
| 472 | - ) | |
| 473 | - ), | |
| 474 | - 'ellipse' => array_merge( | |
| 475 | - $attr_id, | |
| 476 | - $attr_fill, | |
| 477 | - $attr_center, | |
| 478 | - $attr_transform, | |
| 479 | - $attr_style, | |
| 480 | - array( | |
| 481 | - 'rx' => true, | |
| 482 | - 'ry' => true, | |
| 483 | - 'opacity' => true, | |
| 484 | - ) | |
| 485 | - ), | |
| 486 | - 'rect' => array_merge( | |
| 487 | - $attr_id, | |
| 488 | - $attr_fill, | |
| 489 | - $attr_dims, | |
| 490 | - $attr_stroke, | |
| 491 | - $attr_transform, | |
| 492 | - $attr_style, | |
| 493 | - array( | |
| 494 | - 'maskunits' => true, | |
| 495 | - 'rx' => true, | |
| 496 | - 'opacity' => true, | |
| 497 | - ) | |
| 498 | - ), | |
| 499 | - 'line' => array_merge( | |
| 500 | - $attr_id, | |
| 501 | - $attr_stroke, | |
| 502 | - $attr_transform, | |
| 503 | - $attr_style, | |
| 504 | - array( | |
| 505 | - 'x1' => true, | |
| 506 | - 'x2' => true, | |
| 507 | - 'y1' => true, | |
| 508 | - 'y2' => true, | |
| 509 | - 'opacity' => true, | |
| 510 | - ) | |
| 511 | - ), | |
| 512 | - 'polyline' => array_merge( | |
| 513 | - $attr_id, | |
| 514 | - $attr_fill, | |
| 515 | - $attr_stroke, | |
| 516 | - $attr_transform, | |
| 517 | - $attr_style, | |
| 518 | - array( | |
| 519 | - 'points' => true, | |
| 520 | - 'opacity' => true, | |
| 521 | - ) | |
| 522 | - ), | |
| 523 | - 'polygon' => array_merge( | |
| 524 | - $attr_id, | |
| 525 | - $attr_fill, | |
| 526 | - $attr_stroke, | |
| 527 | - $attr_transform, | |
| 528 | - $attr_style, | |
| 529 | - array( | |
| 530 | - 'points' => true, | |
| 531 | - 'opacity' => true, | |
| 532 | - ) | |
| 533 | - ), | |
| 534 | - 'lineargradient' => array_merge( | |
| 535 | - $attr_id, | |
| 536 | - $attr_xlink, | |
| 537 | - array( | |
| 538 | - 'x1' => true, | |
| 539 | - 'y1' => true, | |
| 540 | - 'x2' => true, | |
| 541 | - 'y2' => true, | |
| 542 | - 'gradientunits' => true, | |
| 543 | - 'gradienttransform' => true, | |
| 544 | - 'spreadmethod' => true, | |
| 545 | - ) | |
| 546 | - ), | |
| 547 | - 'radialgradient' => array_merge( | |
| 548 | - $attr_id, | |
| 549 | - $attr_center, | |
| 550 | - $attr_xlink, | |
| 551 | - array( | |
| 552 | - 'r' => true, | |
| 553 | - 'fx' => true, | |
| 554 | - 'fy' => true, | |
| 555 | - 'gradientunits' => true, | |
| 556 | - 'gradienttransform' => true, | |
| 557 | - 'spreadmethod' => true, | |
| 558 | - ) | |
| 559 | - ), | |
| 560 | - 'stop' => array( | |
| 561 | - 'offset' => true, | |
| 562 | - 'stop-color' => true, | |
| 563 | - 'stop-opacity' => true, | |
| 564 | - ), | |
| 565 | - 'use' => array_merge( | |
| 566 | - $attr_id, | |
| 567 | - $attr_dims, | |
| 568 | - $attr_xlink | |
| 569 | - ), | |
| 570 | - ); | |
| 571 | - | |
| 572 | - return array_merge( $allowed_tags, $svg_tags ); | |
| 573 | 320 | } |
| 574 | 321 | } |