PluginProbe
Parse.ly / 3.24.3
Parse.ly v3.24.3
3.24.3 3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 All 107 releases
wp-parsely / src / rest-api / content-helper / validations / class-validate-url-exclusion-list.php

class-validate-url-exclusion-list.php in Parse.ly 3.24.3, at src/rest-api/content-helper/validations/class-validate-url-exclusion-list.php

67 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for validating the URL exclusion list parameter
4 *
5 * @package Parsely
6 * @since 3.19.0
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\REST_API\Content_Helper\Validations;
12
13 use Parsely\REST_API\Base_Validation;
14 use WP_REST_Request;
15 use WP_Error;
16
17 /**
18 * Class for validating the URL exclusion list parameter.
19 *
20 * @since 3.19.0
21 */
22 class Validate_Url_Exclusion_List extends Base_Validation {
23 /**
24 * Validates the URL exclusion list parameter.
25 *
26 * @since 3.17.0
27 * @since 3.19.0 Refactored to use the Base_Validation class.
28 *
29 * @param mixed $param The parameter value.
30 * @param WP_REST_Request $request The request object.
31 * @return true|WP_Error Whether the parameter is valid.
32 */
33 public static function validate( $param, WP_REST_Request $request ) {
34 if ( ! is_array( $param ) ) {
35 return new WP_Error(
36 'invalid_url_exclusion_list',
37 __( 'The URL exclusion list must be an array.', 'wp-parsely' )
38 );
39 }
40
41 return true;
42 }
43
44 /**
45 * Sanitizes the URL exclusion list parameter.
46 *
47 * @since 3.19.0
48 *
49 * @param mixed $value The value to sanitize.
50 * @param WP_REST_Request $request The request object.
51 * @param string $param The parameter name.
52 * @return array<string> The sanitized URL exclusion list.
53 */
54 public static function sanitize( $value, $request, $param ) {
55 if ( ! is_array( $value ) ) {
56 return array();
57 }
58
59 return array_filter(
60 $value,
61 function ( $url ) {
62 return is_string( $url ) && false !== filter_var( $url, FILTER_VALIDATE_URL );
63 }
64 );
65 }
66 }
67