From 1578abaec82d22ef16b176f20710704318402b37 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 16 Aug 2021 22:41:55 -0700 Subject: [PATCH] Run AMP_Script_Sanitizer first --- includes/amp-helper-functions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index fa84913ef2d..0e6f7e51c56 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -1478,6 +1478,11 @@ function amp_get_content_sanitizers( $post = null ) { $native_post_forms_allowed = amp_is_native_post_form_allowed(); $sanitizers = [ + // The AMP_Script_Sanitizer runs first because based on whether it allows custom scripts + // to be kept, it may impact impact the behavior of other sanitizers. For example, if custom + // scripts are kept then this is a signal that tree shaking in AMP_Style_Sanitizer cannot be + // performed. + AMP_Script_Sanitizer::class => [], AMP_Embed_Sanitizer::class => [ 'amp_to_amp_linking_enabled' => $amp_to_amp_linking_enabled, ], @@ -1515,7 +1520,6 @@ function amp_get_content_sanitizers( $post = null ) { 'native_img_used' => $native_img_used, ], AMP_Block_Sanitizer::class => [], // Note: Block sanitizer must come after embed / media sanitizers since its logic is using the already sanitized content. - AMP_Script_Sanitizer::class => [], AMP_Style_Sanitizer::class => [ 'skip_tree_shaking' => is_customize_preview(), ],