Skip to content

Commit 514c513

Browse files
committed
Remove od_store_url_metric_validity filter to be re-added in follow-up PR
1 parent ec59d85 commit 514c513

File tree

3 files changed

+0
-90
lines changed

3 files changed

+0
-90
lines changed

plugins/image-prioritizer/helper.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -136,66 +136,6 @@ function image_prioritizer_add_element_item_schema_properties( array $additional
136136
return $additional_properties;
137137
}
138138

139-
/**
140-
* Validates that the provided background image URL is valid.
141-
*
142-
* @since n.e.x.t
143-
*
144-
* @param bool|WP_Error|mixed $validity Validity. Valid if true or a WP_Error without any errors, or invalid otherwise.
145-
* @param OD_Strict_URL_Metric $url_metric URL Metric, already validated against the JSON Schema.
146-
* @return bool|WP_Error Validity. Valid if true or a WP_Error without any errors, or invalid otherwise.
147-
*/
148-
function image_prioritizer_filter_store_url_metric_validity( $validity, OD_Strict_URL_Metric $url_metric ) {
149-
if ( ! is_bool( $validity ) && ! ( $validity instanceof WP_Error ) ) {
150-
$validity = (bool) $validity;
151-
}
152-
153-
$data = $url_metric->get( 'lcpElementExternalBackgroundImage' );
154-
if ( ! is_array( $data ) ) {
155-
return $validity;
156-
}
157-
158-
$r = wp_safe_remote_head(
159-
$data['url'],
160-
array(
161-
'redirection' => 3, // Allow up to 3 redirects.
162-
)
163-
);
164-
if ( $r instanceof WP_Error ) {
165-
return new WP_Error(
166-
WP_DEBUG ? $r->get_error_code() : 'head_request_failure',
167-
__( 'HEAD request for background image URL failed.', 'image-prioritizer' ) . ( WP_DEBUG ? ' ' . $r->get_error_message() : '' ),
168-
array(
169-
'code' => 500,
170-
)
171-
);
172-
}
173-
$response_code = wp_remote_retrieve_response_code( $r );
174-
if ( $response_code < 200 || $response_code >= 400 ) {
175-
return new WP_Error(
176-
'background_image_response_not_ok',
177-
__( 'HEAD request for background image URL did not return with a success status code.', 'image-prioritizer' ),
178-
array(
179-
'code' => WP_DEBUG ? $response_code : 400,
180-
)
181-
);
182-
}
183-
184-
$content_type = wp_remote_retrieve_header( $r, 'Content-Type' );
185-
if ( ! is_string( $content_type ) || ! str_starts_with( $content_type, 'image/' ) ) {
186-
return new WP_Error(
187-
'background_image_response_not_image',
188-
__( 'HEAD request for background image URL did not return an image Content-Type.', 'image-prioritizer' ),
189-
array(
190-
'code' => 400,
191-
)
192-
);
193-
}
194-
195-
// TODO: Check for the Content-Length and return invalid if it is gigantic?
196-
return $validity;
197-
}
198-
199139
/**
200140
* Gets the path to a script or stylesheet.
201141
*

plugins/image-prioritizer/hooks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313
add_action( 'od_init', 'image_prioritizer_init' );
1414
add_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' );
1515
add_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_element_item_schema_properties' );
16-
add_filter( 'od_store_url_metric_validity', 'image_prioritizer_filter_store_url_metric_validity', 10, 2 );

plugins/optimization-detective/storage/rest-api.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,6 @@ function od_handle_rest_request( WP_REST_Request $request ) {
210210
);
211211
}
212212

213-
/**
214-
* Filters whether a URL Metric is valid for storage.
215-
*
216-
* This allows for custom validation constraints to be applied beyond what can be expressed in JSON Schema. This is
217-
* also necessary because the 'validate_callback' key in a JSON Schema is not respected when gathering the REST API
218-
* endpoint args via the {@see rest_get_endpoint_args_for_schema()} function. Besides this, the REST API doesn't
219-
* support 'validate_callback' for any nested arguments in any case, meaning that custom constraints would be able
220-
* to be applied to multidimensional objects, such as the items inside 'elements'.
221-
*
222-
* This filter only applies when storing a URL Metric via the REST API. It does not run when a stored URL Metric
223-
* loaded from the od_url_metric post type. This means that validation logic enforced via this filter can be more
224-
* expensive, such as doing filesystem checks or HTTP requests.
225-
*
226-
* @since n.e.x.t
227-
*
228-
* @param bool|WP_Error $validity Validity. Valid if true or a WP_Error without any errors, or invalid otherwise.
229-
* @param OD_Strict_URL_Metric $url_metric URL Metric, already validated against the JSON Schema.
230-
*/
231-
$validity = apply_filters( 'od_store_url_metric_validity', true, $url_metric );
232-
if ( false === $validity || ( $validity instanceof WP_Error && $validity->has_errors() ) ) {
233-
if ( false === $validity ) {
234-
$validity = new WP_Error( 'invalid_url_metric', __( 'Validity of URL Metric was rejected by filter.', 'optimization-detective' ) );
235-
}
236-
if ( ! isset( $validity->error_data['code'] ) ) {
237-
$validity->error_data['code'] = 400;
238-
}
239-
return $validity;
240-
}
241-
242213
// TODO: This should be changed from store_url_metric($slug, $url_metric) instead be update_post( $slug, $group_collection ). As it stands, store_url_metric() is duplicating logic here.
243214
$result = OD_URL_Metrics_Post_Type::store_url_metric(
244215
$request->get_param( 'slug' ),

0 commit comments

Comments
 (0)