-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn the AMP Optimizer into an injectable service #6065
Conversation
c3807c8
to
4562e6c
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6065 +/- ##
=============================================
+ Coverage 75.38% 75.44% +0.05%
- Complexity 5706 5714 +8
=============================================
Files 218 227 +9
Lines 17265 17335 +70
=============================================
+ Hits 13016 13079 +63
- Misses 4249 4256 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for 70dced8 are ready 🛎️!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, other than the test coverage complaints.
* Note: They will only be applied once, when this method is hit for the first time. | ||
*/ | ||
public function apply_filters() { | ||
if ( $this->already_applied ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance this would be undesirable? What if you wanted to change the configuration with a filter change on a subsequent call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alternative is to run the filters on every get()
and has()
, which can quickly become a performance issue.
If you want to change the configuration with a later filter call, you can instantiate a new configuration object instead.
Also, this should actually only be triggered when the optimizer is being run, which happens in the shutdown hook that collects the final output buffer after WordPress has finished. I don't think plugins should do anything after the optimizer has run.
Summary
This PR turns the AMP Optimizer into an injectable service and uses the injector configuration to configure it from a central location.
It also hooks the WordPress filters into the Optimizer's configuration object.
Fixes #6064
Depends on ampproject/amp-toolbox-php#150
Checklist