From 2ea897a97258098a88d2bb9068ca321a384dd948 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 23 Dec 2024 15:47:19 -0800 Subject: [PATCH] Fix name of Image Prioritizer function --- plugins/embed-optimizer/detect.js | 2 +- plugins/image-prioritizer/helper.php | 10 +++++++--- plugins/image-prioritizer/hooks.php | 4 +++- .../image-prioritizer/tests/test-helper.php | 18 +++++++++--------- plugins/image-prioritizer/tests/test-hooks.php | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/embed-optimizer/detect.js b/plugins/embed-optimizer/detect.js index 38068387b..6e69af80d 100644 --- a/plugins/embed-optimizer/detect.js +++ b/plugins/embed-optimizer/detect.js @@ -57,7 +57,7 @@ export async function initialize( { isDebug } ) { '.wp-block-embed > .wp-block-embed__wrapper[data-od-xpath]' ); - for ( const embedWrapper of embedWrappers ) { + for ( /** @type {HTMLElement} */ const embedWrapper of embedWrappers ) { monitorEmbedWrapperForResizes( embedWrapper, isDebug ); } diff --git a/plugins/image-prioritizer/helper.php b/plugins/image-prioritizer/helper.php index 789a6a843..20cf15e77 100644 --- a/plugins/image-prioritizer/helper.php +++ b/plugins/image-prioritizer/helper.php @@ -98,15 +98,19 @@ function image_prioritizer_filter_extension_module_urls( $extension_module_urls } /** - * Filters additional properties for the element item schema for Optimization Detective. + * Filters additional properties for the root schema for Optimization Detective. * * @since 0.3.0 * @access private * - * @param array $additional_properties Additional properties. + * @param array|mixed $additional_properties Additional properties. * @return array Additional properties. */ -function image_prioritizer_add_element_item_schema_properties( array $additional_properties ): array { +function image_prioritizer_add_root_schema_properties( $additional_properties ): array { + if ( ! is_array( $additional_properties ) ) { + $additional_properties = array(); + } + $additional_properties['lcpElementExternalBackgroundImage'] = array( 'type' => 'object', 'properties' => array( diff --git a/plugins/image-prioritizer/hooks.php b/plugins/image-prioritizer/hooks.php index 636590875..8418cf2da 100644 --- a/plugins/image-prioritizer/hooks.php +++ b/plugins/image-prioritizer/hooks.php @@ -11,6 +11,8 @@ } add_action( 'od_init', 'image_prioritizer_init' ); + +// TODO: The remainder filters should be added in image_prioritizer_init(). add_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' ); -add_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_element_item_schema_properties' ); +add_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_root_schema_properties' ); add_filter( 'rest_request_before_callbacks', 'image_prioritizer_filter_rest_request_before_callbacks', 10, 3 ); diff --git a/plugins/image-prioritizer/tests/test-helper.php b/plugins/image-prioritizer/tests/test-helper.php index dfd05b854..5a51129ed 100644 --- a/plugins/image-prioritizer/tests/test-helper.php +++ b/plugins/image-prioritizer/tests/test-helper.php @@ -265,17 +265,17 @@ public function test_image_prioritizer_filter_extension_module_urls(): void { } /** - * Test image_prioritizer_add_element_item_schema_properties. + * Test image_prioritizer_add_root_schema_properties. * - * @covers ::image_prioritizer_add_element_item_schema_properties + * @covers ::image_prioritizer_add_root_schema_properties */ - public function test_image_prioritizer_add_element_item_schema_properties(): void { + public function test_image_prioritizer_add_root_schema_properties(): void { $initial_schema = array( 'foo' => array( 'type' => 'string', ), ); - $filtered_schema = image_prioritizer_add_element_item_schema_properties( $initial_schema ); + $filtered_schema = image_prioritizer_add_root_schema_properties( $initial_schema ); $this->assertCount( 2, $filtered_schema ); $this->assertArrayHasKey( 'foo', $filtered_schema ); $this->assertArrayHasKey( 'lcpElementExternalBackgroundImage', $filtered_schema ); @@ -286,7 +286,7 @@ public function test_image_prioritizer_add_element_item_schema_properties(): voi /** * @return array */ - public function data_provider_for_test_image_prioritizer_add_element_item_schema_properties_inputs(): array { + public function data_provider_for_test_image_prioritizer_add_root_schema_properties_inputs(): array { return array( 'bad_type' => array( 'input_value' => 'not_an_object', @@ -437,17 +437,17 @@ public function data_provider_for_test_image_prioritizer_add_element_item_schema } /** - * Test image_prioritizer_add_element_item_schema_properties for various inputs. + * Test image_prioritizer_add_root_schema_properties for various inputs. * - * @covers ::image_prioritizer_add_element_item_schema_properties + * @covers ::image_prioritizer_add_root_schema_properties * - * @dataProvider data_provider_for_test_image_prioritizer_add_element_item_schema_properties_inputs + * @dataProvider data_provider_for_test_image_prioritizer_add_root_schema_properties_inputs * * @param mixed $input_value Input value. * @param string|null $expected_exception Expected exception message. * @param array|null $output_value Output value. */ - public function test_image_prioritizer_add_element_item_schema_properties_inputs( $input_value, ?string $expected_exception, ?array $output_value ): void { + public function test_image_prioritizer_add_root_schema_properties_inputs( $input_value, ?string $expected_exception, ?array $output_value ): void { $data = $this->get_sample_url_metric( array() )->jsonSerialize(); $data['lcpElementExternalBackgroundImage'] = $input_value; $exception_message = null; diff --git a/plugins/image-prioritizer/tests/test-hooks.php b/plugins/image-prioritizer/tests/test-hooks.php index 840212da4..d08d4393c 100644 --- a/plugins/image-prioritizer/tests/test-hooks.php +++ b/plugins/image-prioritizer/tests/test-hooks.php @@ -13,7 +13,7 @@ class Test_Image_Prioritizer_Hooks extends WP_UnitTestCase { public function test_hooks_added(): void { $this->assertEquals( 10, has_action( 'od_init', 'image_prioritizer_init' ) ); $this->assertEquals( 10, has_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' ) ); - $this->assertEquals( 10, has_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_element_item_schema_properties' ) ); + $this->assertEquals( 10, has_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_root_schema_properties' ) ); $this->assertEquals( 10, has_filter( 'rest_request_before_callbacks', 'image_prioritizer_filter_rest_request_before_callbacks' ) ); } }