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

Install and activate Optimization Detective when the Embed Optimizer feature is activated from the Performance screen #1644

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 10 additions & 1 deletion plugins/performance-lab/includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function perflab_query_plugin_info( string $plugin_slug ) {
$plugins = array();
$standalone_plugins = array_merge(
array_flip( perflab_get_standalone_plugins() ),
array( 'optimization-detective' => array() ) // TODO: Programmatically discover the plugin dependencies and add them here.
array( 'optimization-detective' => array() ) // TODO: Programmatically discover the plugin dependencies and add them here. See <https://github.com/WordPress/performance/issues/1616>.
);
foreach ( $response->plugins as $plugin_data ) {
if ( ! isset( $standalone_plugins[ $plugin_data['slug'] ] ) ) {
Expand Down Expand Up @@ -324,6 +324,15 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
return $plugin_data;
}

// Add recommended plugins (soft dependencies) to the list of plugins installed and activated.
$standalone_plugin_data = perflab_get_standalone_plugin_data();
if ( isset( $standalone_plugin_data[ $plugin_slug ]['suggest'] ) ) {
$plugin_data['requires_plugins'] = array_merge(
$plugin_data['requires_plugins'],
$standalone_plugin_data[ $plugin_slug ]['suggest']
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment: For those reasons, I think we should simply hard-code here: If embed-optimizer, add optimization-detective to requires_plugins.


// Install and activate plugin dependencies first.
foreach ( $plugin_data['requires_plugins'] as $requires_plugin_slug ) {
$result = perflab_install_and_activate_plugin( $requires_plugin_slug );
Expand Down
4 changes: 3 additions & 1 deletion plugins/performance-lab/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ function perflab_render_generator(): void {
*
* @since 3.0.0
*
* @return array<string, array{'constant': string, 'experimental'?: bool}> Associative array of $plugin_slug => $plugin_data pairs.
* @return array<string, array{'constant': string, 'experimental'?: bool, 'suggest'?: string[]}> Associative array of $plugin_slug => $plugin_data pairs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to establish this as something we may want to do more, given that this is not a thing that WordPress Core supports.

Therefore instead of introducing a "schema" change here, I think we should for now hard-code this in perflab_install_and_activate_plugin(). Feels more hacky, but is more future-proof as it doesn't change any portion of the API. Given that this PR simply takes the "suggested" feature as if it was "required", that part would need more thought if we truly wanted to establish a way to suggest a feature.

*/
function perflab_get_standalone_plugin_data(): array {
/*
* Alphabetically sorted list of plugin slugs and their data.
* Supported keys per plugin are:
* - 'constant' (string, required)
* - 'experimental' (boolean, optional)
* - 'suggest' (string[], optional)
*/
return array(
'auto-sizes' => array(
Expand All @@ -103,6 +104,7 @@ function perflab_get_standalone_plugin_data(): array {
'embed-optimizer' => array(
'constant' => 'EMBED_OPTIMIZER_VERSION',
'experimental' => true,
'suggest' => array( 'optimization-detective' ),
),
'image-prioritizer' => array(
'constant' => 'IMAGE_PRIORITIZER_VERSION',
Expand Down
Loading