From fc6df5e59684ae38a5778476cf556cbe5a6f0e54 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 21 Aug 2024 10:08:54 +0200 Subject: [PATCH 1/8] Remove unused param --- inc/default-filters.php | 2 +- inc/functions.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/inc/default-filters.php b/inc/default-filters.php index 475b3d0e..9a42cf20 100644 --- a/inc/default-filters.php +++ b/inc/default-filters.php @@ -20,7 +20,7 @@ add_action( 'enqueue_block_assets', __NAMESPACE__ . '\enqueue_block_assets' ); add_action( 'rest_api_init', __NAMESPACE__ . '\register_rest_fields' ); add_action( 'init', __NAMESPACE__ . '\register_attachment_post_meta' ); -add_filter( 'rest_index', __NAMESPACE__ . '\filter_rest_index', 10, 2 ); +add_filter( 'rest_index', __NAMESPACE__ . '\filter_rest_index' ); add_filter( 'mod_rewrite_rules', __NAMESPACE__ . '\filter_mod_rewrite_rules' ); diff --git a/inc/functions.php b/inc/functions.php index f0ba5299..64d16342 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -386,9 +386,8 @@ function register_rest_fields(): void { * Filters the REST API root index data to add custom settings. * * @param WP_REST_Response $response Response data. - * @param WP_REST_Request $request Request data. */ -function filter_rest_index( WP_REST_Response $response, WP_REST_Request $request ) { +function filter_rest_index( WP_REST_Response $response ) { /** This filter is documented in wp-admin/includes/images.php */ $image_size_threshold = (int) apply_filters( 'big_image_size_threshold', 2560, array( 0, 0 ), '', 0 ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound From 5af6b71800bd9eae069b35f9423cbedb5fead12d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 21 Aug 2024 11:12:10 +0200 Subject: [PATCH 2/8] Use HTML API for cross-origin isolation --- inc/class-cross-origin-isolation.php | 282 --------------------------- inc/default-filters.php | 20 +- inc/functions.php | 227 ++++++++++++++++++--- phpcs.xml.dist | 5 +- phpstan.neon.dist | 3 - 5 files changed, 212 insertions(+), 325 deletions(-) delete mode 100644 inc/class-cross-origin-isolation.php diff --git a/inc/class-cross-origin-isolation.php b/inc/class-cross-origin-isolation.php deleted file mode 100644 index 8cf2e2da..00000000 --- a/inc/class-cross-origin-isolation.php +++ /dev/null @@ -1,282 +0,0 @@ -needs_isolation() ) { - header( 'Cross-Origin-Opener-Policy: same-origin' ); - header( "Cross-Origin-Embedder-Policy: $coep" ); - } - - ob_start( [ $this, 'replace_in_dom' ] ); - } - - /** - * Filters the HTML link tag of an enqueued style. - * - * @since 1.6.0 - * - * @param mixed $tag The link tag for the enqueued style. - * @param string $handle The style's registered handle. - * @param string $href The stylesheet's source URL. - * @return string|mixed - */ - public function filter_style_loader_tag( $tag, string $handle, string $href ) { - return $this->add_attribute( $tag, 'href', $href ); - } - - /** - * Filters the HTML script tag of an enqueued script. - * - * @since 1.6.0 - * - * @param mixed $tag The ` + + + +HTML; + + $expected = << + + + + + + + + + + + +HTML; + + $actual = add_crossorigin_attributes( $html ); + + $this->assertSame( $expected, $actual ); + } + + /** + * @covers \MediaExperiments\override_media_templates + */ + public function test_override_media_templates(): void { + if ( ! function_exists( '\wp_print_media_templates' ) ) { + require_once ABSPATH . WPINC . '/media-template.php'; + } + + override_media_templates(); + + ob_start(); + do_action( 'admin_footer' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + $output = ob_get_clean(); + + $this->assertStringContainsString( '