From 7bee4765c8494542696a1974b0241f0b8209c681 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 11 Nov 2024 09:01:34 -0800 Subject: [PATCH 1/3] Install and activate Optimization Detective when the Embed Optimizer feature is activated --- plugins/performance-lab/includes/admin/plugins.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index 709300061..2b77ffb58 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -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 . ); foreach ( $response->plugins as $plugin_data ) { if ( ! isset( $standalone_plugins[ $plugin_data['slug'] ] ) ) { @@ -324,6 +324,11 @@ 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. + if ( 'embed-optimizer' === $plugin_slug ) { + $plugin_data['requires_plugins'][] = 'optimization-detective'; + } + // Install and activate plugin dependencies first. foreach ( $plugin_data['requires_plugins'] as $requires_plugin_slug ) { $result = perflab_install_and_activate_plugin( $requires_plugin_slug ); From b012d8d9683ee0592946d2da2f1bbd94b04311f1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 11 Nov 2024 09:13:20 -0800 Subject: [PATCH 2/3] Remove hard-coded reference to embed-optimizer --- plugins/performance-lab/includes/admin/plugins.php | 8 ++++++-- plugins/performance-lab/load.php | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index 2b77ffb58..155f2725e 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -325,8 +325,12 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce } // Add recommended plugins (soft dependencies) to the list of plugins installed and activated. - if ( 'embed-optimizer' === $plugin_slug ) { - $plugin_data['requires_plugins'][] = 'optimization-detective'; + $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'] + ); } // Install and activate plugin dependencies first. diff --git a/plugins/performance-lab/load.php b/plugins/performance-lab/load.php index 304089d13..50675a9df 100644 --- a/plugins/performance-lab/load.php +++ b/plugins/performance-lab/load.php @@ -83,7 +83,7 @@ function perflab_render_generator(): void { * * @since 3.0.0 * - * @return array Associative array of $plugin_slug => $plugin_data pairs. + * @return array Associative array of $plugin_slug => $plugin_data pairs. */ function perflab_get_standalone_plugin_data(): array { /* @@ -91,6 +91,7 @@ function perflab_get_standalone_plugin_data(): array { * Supported keys per plugin are: * - 'constant' (string, required) * - 'experimental' (boolean, optional) + * - 'suggest' (string[], optional) */ return array( 'auto-sizes' => array( @@ -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', From 70f90b6c4809b81b9a11277af7a8c51a214e3b45 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 11 Nov 2024 09:40:47 -0800 Subject: [PATCH 3/3] Revert "Remove hard-coded reference to embed-optimizer" This reverts commit b012d8d9683ee0592946d2da2f1bbd94b04311f1. --- plugins/performance-lab/includes/admin/plugins.php | 8 ++------ plugins/performance-lab/load.php | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index 155f2725e..2b77ffb58 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -325,12 +325,8 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce } // 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'] - ); + if ( 'embed-optimizer' === $plugin_slug ) { + $plugin_data['requires_plugins'][] = 'optimization-detective'; } // Install and activate plugin dependencies first. diff --git a/plugins/performance-lab/load.php b/plugins/performance-lab/load.php index 50675a9df..304089d13 100644 --- a/plugins/performance-lab/load.php +++ b/plugins/performance-lab/load.php @@ -83,7 +83,7 @@ function perflab_render_generator(): void { * * @since 3.0.0 * - * @return array Associative array of $plugin_slug => $plugin_data pairs. + * @return array Associative array of $plugin_slug => $plugin_data pairs. */ function perflab_get_standalone_plugin_data(): array { /* @@ -91,7 +91,6 @@ function perflab_get_standalone_plugin_data(): array { * Supported keys per plugin are: * - 'constant' (string, required) * - 'experimental' (boolean, optional) - * - 'suggest' (string[], optional) */ return array( 'auto-sizes' => array( @@ -104,7 +103,6 @@ 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',