diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 0dc51a7a7d1..9c15a0771e8 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -482,6 +482,11 @@ public static function finish_output_buffering( $output ) { 'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat. ); + $assets = AMP_Content_Sanitizer::sanitize_document( $dom, self::$sanitizer_classes, $args ); + + self::$amp_scripts = array_merge( self::$amp_scripts, $assets['scripts'] ); + self::$amp_styles = array_merge( self::$amp_styles, $assets['styles'] ); + /* * @todo The sanitize method needs to be updated to sanitize the entire HTML element and not just the BODY. * This will require updating mandatory_parent_blacklist in amphtml-update.py to include elements that appear in the HEAD. @@ -490,11 +495,7 @@ public static function finish_output_buffering( $output ) { * from outside the body from being part of the whitelist sanitizer when it runs when theme support is not present, * as otherwise elements from the HEAD could get added to the BODY. */ - list( $sanitized_inner_body, $scripts, $styles ) = AMP_Content_Sanitizer::sanitize( $dom, self::$sanitizer_classes, $args ); - - self::$amp_scripts = array_merge( self::$amp_scripts, $scripts ); - self::$amp_styles = array_merge( self::$amp_styles, $styles ); - + $sanitized_inner_body = AMP_DOM_Utils::get_content_from_dom( $dom ); $output = preg_replace( '#(