Skip to content

Commit 03b05fd

Browse files
committed
Avoid transient cache for plugin installation to ensure latest version
Replaced transient-cached plugin data with a real-time `plugins_api()` call during installation to avoid installing outdated versions.
1 parent 8398cfe commit 03b05fd

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

plugins/performance-lab/includes/admin/plugins.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,24 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
343343
}
344344
$processed_plugins[] = $plugin_slug;
345345

346-
$plugin_data = perflab_query_plugin_info( $plugin_slug );
346+
$plugin_data = plugins_api(
347+
'plugin_information',
348+
array(
349+
'slug' => $plugin_slug,
350+
'fields' => array(
351+
'sections' => false,
352+
),
353+
)
354+
);
355+
347356
if ( $plugin_data instanceof WP_Error ) {
348357
return $plugin_data;
349358
}
350359

360+
if ( is_object( $plugin_data ) ) {
361+
$plugin_data = (array) $plugin_data;
362+
}
363+
351364
// Add recommended plugins (soft dependencies) to the list of plugins installed and activated.
352365
if ( 'embed-optimizer' === $plugin_slug ) {
353366
$plugin_data['requires_plugins'][] = 'optimization-detective';
@@ -372,9 +385,7 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
372385
// Replace new Plugin_Installer_Skin with new Quiet_Upgrader_Skin when output needs to be suppressed.
373386
$skin = new WP_Ajax_Upgrader_Skin( array( 'api' => $plugin_data ) );
374387
$upgrader = new Plugin_Upgrader( $skin );
375-
// Remove the version number from the link to download the latest plugin version.
376-
$download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+(?:-\w+)?\.zip#', '$1.zip', $plugin_data['download_link'] );
377-
$result = $upgrader->install( $download_link );
388+
$result = $upgrader->install( $plugin_data['download_link'] );
378389

379390
if ( is_wp_error( $result ) ) {
380391
return $result;

0 commit comments

Comments
 (0)