-
Notifications
You must be signed in to change notification settings - Fork 382
Description
Theme support currently has the following logic that us run on the buffered output:
This is not ideal. Normally when the sanitizer run, they identify the AMP component scripts that are required once they detect that a given AMP component is present in the page. When the sanitizer is not involved in sanitizing however, then the plugin currently requires manual inclusion of the required AMP components (cf. #874):
This isn't good. Merely the presence of an <amp-analytics> element in the response should automatically result in the amp-analytics AMP component script being included. The same should go for when a form is included in a template, which currently results in issues like #802.
So one way or another, we need to identify which elements are used in the page and then add the required AMP components. With #857 we now have the output buffering so we could just take the entire output and feed it into the sanitizers once, instead of doing so once for each instance of the_content. It would certainly be simpler to do this, but my main concern is what would be more performant.
If we didn't sanitize the entire buffered output, then we'd need another mechanism to look through the raw unparsed HTML to identify whether a given element is present which needs an AMP component. Searching unparsed HTML is going to be less reliable than looking at the DOM.
I've written more about this in https://github.com/Automattic/amp-wp/pull/871/files#r162198204