Omit validation errors sanitized by filter or tree-shaking option #1413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: Tree-shaking option was eliminated in v1.2, per #2501.
When CSS tree-shaking is accepted by an options or by filter, the
removed_unused_css_rules
validation error is always being shown on an invalid URL screen. Similarly, when a theme is configured to forcibly accept sanitization for other errors, such as an illegal CSS rule, as in the core theme sanitizer:https://github.com/Automattic/amp-wp/blob/60fe63749e273c938d6ab2375ff89725ed1f2389/includes/sanitizers/class-amp-core-theme-sanitizer.php#L191-L201
These are also being shown always for every invalid URL. This adds noise and creates confusion.
We should just omit such validation errors from ever being included in validation results so that they never show up. By omitting validation errors that are forcibly-accepted as sanitized by a filter, we avoid needlessly creating
amp_validation_error
taxonomy terms when they'll always be accepted anyway. This is particularly important for validation errors such as created by scripts with variable contents. Consider, for example, a template that does:(For a more common scenario, consider the case when a nonce is output.) You may have considered adding a filter to automatically accept this validation error:
However, what this results in is a new
amp_validation_error
term added to the database every time that the URL is re-validated. Since the text is random, then that validation error will become disassociated with the URL the next time it is checked, and another validation error will come and take its place. This repeats until many duplicatedamp_validation_error
terms fill up the database.🎗 At some point we need to add a cronjob to delete
amp_validation_error
terms that have zero URLs associated with them.So, the changes in this PR also prevent this from being a problem. Such filter-accepted validation errors will never see the light of day.
The changes in this PR extend the “staleness” determination beyond the active theme/plugins to include changes to whether tree shaking will be automatically accepted. In this way, if the user re-checks a URL after enabling auto tree-shaking then the validation error for tree shaking will no longer appear.
Before
After