Ticket #42438: 42438-function.diff
File 42438-function.diff, 3.6 KB (added by , 2 years ago) |
---|
-
src/wp-includes/general-template.php
diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php index 3f042865ad..10120a11de 100644
function wp_resource_hints() { 3423 3423 } 3424 3424 } 3425 3425 3426 /** 3427 * Specify resources to preload. 3428 * 3429 * @global array $wp_preload_resources 3430 * @since 6.1.0 3431 * 3432 * @param array $preload_resources { 3433 * Array of resources and their attributes, or URLs to print for resource preloads. 3434 * 3435 * @type array ...$0 { 3436 * Array of resource attributes. 3437 * 3438 * @type string $href URL to include in resource preloads. Required. 3439 * @type string $as How the browser should treat the resource 3440 * (`script`, `style`, `image`, `document`, etc). 3441 * @type string $crossorigin Indicates the CORS policy of the specified resource. 3442 * @type string $type Type of the resource (`text/html`, `text/css`, etc). 3443 * @type string $media Accepts media types or media queries. Allows responsive preloading. 3444 * @type string $imagesizes Responsive source size to the source Set. 3445 * @type string $imagesrcset Responsive image sources to the source set. 3446 * } 3447 * } 3448 */ 3449 function wp_add_preload_resources( $preload_resources ) { 3450 global $wp_preload_resources; 3451 3452 if ( ! is_array( $wp_preload_resources ) ) { 3453 $wp_preload_resources = array(); 3454 } 3455 $wp_preload_resources = array_merge( $wp_preload_resources, $preload_resources ); 3456 } 3457 3426 3458 /** 3427 3459 * Prints resource preloads directives to browsers. 3428 3460 * … … function wp_resource_hints() { 3437 3469 * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload 3438 3470 * @link https://web.dev/preload-responsive-images/ 3439 3471 * 3472 * @global array $wp_preload_resources 3440 3473 * @since 6.1.0 3441 3474 */ 3442 3475 function wp_preload_resources() { 3476 global $wp_preload_resources; 3443 3477 /** 3444 3478 * Filters domains and URLs for resource preloads. 3445 3479 * … … function wp_preload_resources() { 3462 3496 * } 3463 3497 * } 3464 3498 */ 3465 $preload_resources = apply_filters( 'wp_preload_resources', array() ); 3466 3499 $preload_resources = apply_filters( 'wp_preload_resources', is_array( $wp_preload_resources ) ? $wp_preload_resources : array() ); 3467 3500 if ( ! is_array( $preload_resources ) ) { 3468 3501 return; 3469 3502 } -
tests/phpunit/tests/general/wpPreloadResources.php
diff --git tests/phpunit/tests/general/wpPreloadResources.php tests/phpunit/tests/general/wpPreloadResources.php index 53fd2646a6..b0c43e79cd 100644
5 5 * @group template 6 6 * @ticket 42438 7 7 * @covers ::wp_preload_resources 8 * @covers ::wp_add_preload_links 8 9 */ 9 10 class Tests_General_wpPreloadResources extends WP_UnitTestCase { 11 /** 12 * Set up. 13 */ 14 public function set_up() { 15 parent::set_up(); 10 16 17 global $wp_preload_resources; 18 $wp_preload_resources = array(); 19 } 11 20 /** 12 21 * @dataProvider data_preload_resources 13 22 * … … class Tests_General_wpPreloadResources extends WP_UnitTestCase { 25 34 $this->assertSame( $expected, $actual ); 26 35 } 27 36 37 /** 38 * Test the `wp_add_preload_links()` function. 39 * 40 * @dataProvider data_preload_resources 41 * 42 * @ticket 42438 43 */ 44 public function test_wp_add_preload_resources( $expected, $preload_resources ) { 45 wp_add_preload_resources( $preload_resources ); 46 $actual = get_echo( 'wp_preload_resources' ); 47 $this->assertSame( $expected, $actual ); 48 } 49 28 50 /** 29 51 * Test provider for all preload link possible combinations. 30 52 * … … class Tests_General_wpPreloadResources extends WP_UnitTestCase { 249 271 ), 250 272 ); 251 273 } 252 253 274 }