-
Notifications
You must be signed in to change notification settings - Fork 133
Description
In at least one case, there is a need currently for a tag visitor to run after another tag visitor has run:
performance/plugins/auto-sizes/optimization-detective.php
Lines 54 to 66 in e34711d
/** | |
* Registers the tag visitor for image tags. | |
* | |
* @since 1.1.0 | |
* | |
* @param OD_Tag_Visitor_Registry $registry Tag visitor registry. | |
*/ | |
function auto_sizes_register_tag_visitors( OD_Tag_Visitor_Registry $registry ): void { | |
$registry->register( 'auto-sizes', 'auto_sizes_visit_tag' ); | |
} | |
// Important: The Image Prioritizer's IMG tag visitor is registered at priority 10, so priority 100 ensures that the loading attribute has been correctly set by the time the Auto Sizes visitor runs. | |
add_action( 'od_register_tag_visitors', 'auto_sizes_register_tag_visitors', 100 ); |
The tag visitor in Enhanced Responsive Sizes needs to run after the IMG tag visitor be
The Image Prioritizer's tag visitor is currently registered with the name ID of img-tags
which is not ideal:
performance/plugins/image-prioritizer/helper.php
Lines 33 to 35 in e34711d
// Note: The class is invocable (it has an __invoke() method). | |
$img_visitor = new Image_Prioritizer_Img_Tag_Visitor(); | |
$registry->register( 'img-tags', $img_visitor ); |
It should rather be prefixed like image-prioritizer-img
. The image-prioritizer-img
string could even be defined as a class constant like Image_Prioritizer_Img_Tag_Visitor::ID
. When Enhanced Responsive Sizes registers its tag visitor, it should be able to explicitly declare this dependency:
function auto_sizes_register_tag_visitors( OD_Tag_Visitor_Registry $registry ): void {
$dependencies = array();
if ( class_exists( 'Image_Prioritizer_Img_Tag_Visitor' ) ) {
$dependencies[] = Image_Prioritizer_Img_Tag_Visitor::ID;
}
$registry->register( 'auto-sizes', 'auto_sizes_visit_tag', $dependencies );
}
Then there wouldn't be a need to rely on action priorities (and the current implementation of OD_Tag_Visitor_Registry
) to ensure that one tag visitor runs before another.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status