Skip to content
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

Facilitate Optimization Detective to be embedded in other plugins/themes #1081

Open
westonruter opened this issue Mar 22, 2024 · 1 comment
Labels
[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin [Plugin] Optimization Detective Issues for the Optimization Detective plugin

Comments

@westonruter
Copy link
Member

Feature Description

To increase the reach of the optimizations made possible by Optimization Detective, the plugin should be able to be embedded in popular plugins and themes without having to explicitly install the Optimization Plugin. In talking with Elementor at the WordCamp Asia Contributor Day, they pointed me to the plugin bootstrap file in woocommerce/action-scheduler as a way to do this.

Let's say someone installs the Optimization Detective plugin while the logic is also embedded in 2 other plugins as well as in a theme: only the copy with the most recent version should end up getting loaded. Additionally, if versions match between two copies, then the version in the actual Optimization Detective plugin should be favored.

This should also be explored for Embed Optimizer.

@westonruter westonruter added [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin labels Mar 22, 2024
@westonruter
Copy link
Member Author

westonruter commented Mar 22, 2024

Additionally, it may make sense for embedders to skip the output-buffering added in:

add_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX );

add_action( 'wp', 'od_maybe_add_template_output_buffer_filter' );

If the plugin is already doing output buffering, they may want to manually pass the buffer through od_optimize_template_output_buffer() (if od_can_optimize_response() returns true). For example, a plugin may want to do this:

<?php
ob_start( static function ( string $buffer ) {
	// Do plugin-specific processing.
	// ...
	
	// Apply Optimization Detective.
	if (
		function_exists( 'od_can_optimize_response' ) &&
		od_can_optimize_response() &&
		function_exists( 'od_optimize_template_output_buffer' )
	) {
		$buffer = od_optimize_template_output_buffer( $buffer );
	}
	
	return $buffer;
} );

To prevent double-processing, they currently would have to do the following to unhook the plugin's own output buffering:

remove_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX ); 
remove_action( 'wp', 'od_maybe_add_template_output_buffer_filter' ); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin [Plugin] Optimization Detective Issues for the Optimization Detective plugin
Projects
None yet
Development

No branches or pull requests

1 participant