@@ -163,6 +163,7 @@ function od_add_template_output_buffer_filter( $template ) {
163
163
od_get_url_metrics_breakpoint_sample_size (),
164
164
od_get_url_metric_freshness_ttl ()
165
165
);
166
+ $ link_collection = new OD_Link_Collection ();
166
167
167
168
/**
168
169
* Fires when Optimization Detective is initialized to optimize the current response.
@@ -179,15 +180,17 @@ function od_add_template_output_buffer_filter( $template ) {
179
180
$ post_id ,
180
181
$ query_vars ,
181
182
$ slug ,
182
- $ current_etag
183
+ $ current_etag ,
184
+ $ link_collection
183
185
)
184
186
);
185
187
186
- $ callback = static function ( string $ buffer ) use ( $ tag_visitor_registry , $ group_collection , $ slug , $ post_id ): string {
188
+ $ callback = static function ( string $ buffer ) use ( $ tag_visitor_registry , $ group_collection , $ link_collection , $ slug , $ post_id ): string {
187
189
return od_optimize_template_output_buffer (
188
190
$ buffer ,
189
191
$ tag_visitor_registry ,
190
192
$ group_collection ,
193
+ $ link_collection ,
191
194
$ slug ,
192
195
$ post_id
193
196
);
@@ -304,11 +307,12 @@ function od_is_response_html_content_type(): bool {
304
307
* @param string $buffer Template output buffer.
305
308
* @param OD_Tag_Visitor_Registry $tag_visitor_registry Tag visitor registry.
306
309
* @param OD_URL_Metric_Group_Collection $group_collection URL Metric group collection.
310
+ * @param OD_Link_Collection $link_collection Link collection.
307
311
* @param non-empty-string $slug Slug.
308
312
* @param positive-int|null $post_id The ID for the od_url_metric post if it exists.
309
313
* @return string Filtered template output buffer.
310
314
*/
311
- function od_optimize_template_output_buffer ( string $ buffer , OD_Tag_Visitor_Registry $ tag_visitor_registry , OD_URL_Metric_Group_Collection $ group_collection , string $ slug , ?int $ post_id ): string {
315
+ function od_optimize_template_output_buffer ( string $ buffer , OD_Tag_Visitor_Registry $ tag_visitor_registry , OD_URL_Metric_Group_Collection $ group_collection , OD_Link_Collection $ link_collection , string $ slug , ?int $ post_id ): string {
312
316
313
317
// If the content-type is not HTML or the output does not start with '<', then abort since the buffer is definitely not HTML.
314
318
if (
@@ -328,7 +332,6 @@ function od_optimize_template_output_buffer( string $buffer, OD_Tag_Visitor_Regi
328
332
return $ buffer ;
329
333
}
330
334
331
- $ link_collection = new OD_Link_Collection ();
332
335
$ visited_tag_state = new OD_Visited_Tag_State ();
333
336
$ tag_visitor_context = new OD_Tag_Visitor_Context (
334
337
$ processor ,
0 commit comments