Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugins/optimization-detective/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

// @codeCoverageIgnoreStart
add_action( 'init', 'od_initialize_extensions', PHP_INT_MAX );
add_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX );

// Backward compatibility with WP<6.9.
if ( ! function_exists( 'wp_start_template_enhancement_output_buffer' ) ) {
add_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX );
}

OD_URL_Metrics_Post_Type::add_hooks();
OD_Storage_Lock::add_hooks();
add_action( 'wp', 'od_maybe_add_template_output_buffer_filter' );
Expand Down
8 changes: 7 additions & 1 deletion plugins/optimization-detective/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ function_exists( 'perflab_server_timing_use_output_buffer' )
) {
$callback = perflab_wrap_server_timing( $callback, 'optimization-detective', 'exist' );
}
add_filter( 'od_template_output_buffer', $callback );

// Backward compatibility with WP<6.9.
if ( function_exists( 'wp_start_template_enhancement_output_buffer' ) ) {
add_filter( 'wp_template_enhancement_output_buffer', $callback );
} else {
add_filter( 'od_template_output_buffer', $callback );
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion plugins/optimization-detective/tests/test-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ class Test_OD_Hooks extends WP_UnitTestCase {
*/
public function test_hooks_added(): void {
$this->assertEquals( PHP_INT_MAX, has_action( 'init', 'od_initialize_extensions' ) );
$this->assertEquals( PHP_INT_MAX, has_filter( 'template_include', 'od_buffer_output' ) );

// Backward compatibility with WP<6.9.
if ( version_compare( $GLOBALS['wp_version'], '6.9', '<' ) ) {
$this->assertEquals( PHP_INT_MAX, has_filter( 'template_include', 'od_buffer_output' ) );
} else {
$this->assertFalse( has_filter( 'template_include', 'od_buffer_output' ) );
}

$this->assertEquals( 10, has_filter( 'wp', 'od_maybe_add_template_output_buffer_filter' ) );
$this->assertEquals( 10, has_action( 'wp_head', 'od_render_generator_meta_tag' ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ public function test_od_maybe_add_template_output_buffer_filter( Closure $set_up
remove_all_filters( 'od_template_output_buffer' ); // In case go_to() caused them to be added.

od_maybe_add_template_output_buffer_filter();
$this->assertSame( $expected_has_filter, has_filter( 'od_template_output_buffer' ) );

// Backward compatibility with WP<6.9.
if ( version_compare( $GLOBALS['wp_version'], '6.9', '<' ) ) {
$this->assertSame( $expected_has_filter, has_filter( 'od_template_output_buffer' ) );
} else {
$this->assertSame( $expected_has_filter, has_filter( 'wp_template_enhancement_output_buffer' ) );
}
}

/**
Expand Down
Loading