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
← All changes | src/rest-api/stats/class-endpoint-related.php +27 -6 3.24.0 → 3.24.3 View file →
@@ -62,8 +62,9 @@
62 62 /**
63 63 * Registers the routes for the endpoint.
64 64 *
65 65 * @since 3.17.0
66 + * @since 3.24.2 Registered the related posts arguments, and required an HTTP(S) URL with a host.
66 67 */
67 68 public function register_routes(): void {
68 69 /**
69 70 * GET /related
@@ -72,15 +73,19 @@
72 73 $this->register_rest_route(
73 74 '/',
74 75 array( 'GET' ),
75 76 array( $this, 'get_related_posts' ),
76 - array(
77 - 'url' => array(
78 - 'description' => __( 'The URL of the post.', 'wp-parsely' ),
79 - 'type' => 'string',
80 - 'required' => true,
77 + array_merge(
78 + array(
79 + 'url' => array(
80 + 'description' => __( 'The URL of the post.', 'wp-parsely' ),
81 + 'type' => 'string',
82 + 'pattern' => '^https?://\S+$',
83 + 'required' => true,
84 + 'validate_callback' => array( $this, 'validate_url' ),
85 + ),
81 86 ),
82 - $this->get_related_posts_param_args(),
87 + $this->get_related_posts_param_args()
83 88 )
84 89 );
85 90 }
86 91
@@ -103,8 +108,24 @@
103 108 return $related_posts;
104 109 }
105 110
106 111 return new WP_REST_Response( array( 'data' => $related_posts ), 200 );
112 + }
113 +
114 + /**
115 + * Validates that the URL has a host. The `pattern` argument checks the scheme.
116 + *
117 + * @since 3.24.2
118 + *
119 + * @param mixed $url The raw parameter value, as validation runs before type checks.
120 + * @return true|WP_Error
121 + */
122 + public function validate_url( $url ) {
123 + if ( ! is_string( $url ) || '' === (string) wp_parse_url( $url, PHP_URL_HOST ) ) {
124 + return new WP_Error( 'invalid_param', __( 'The parameter must be a URL with a host.', 'wp-parsely' ) );
125 + }
126 +
127 + return true;
107 128 }
108 129
109 130 /**
110 131 * Returns whether the endpoint is available for access by the current