Skip to content

Commit d2d5eae

Browse files
authored
Merge pull request #1693 from ShyamGadde/fix/download-link-plugin-version
Fix latest plugin version not being downloaded consistently
2 parents bc0081a + b59b0d2 commit d2d5eae

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @since 2.8.0
1717
*
1818
* @param string $plugin_slug The string identifier for the plugin in questions slug.
19-
* @return array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], download_link: string, version: string}|WP_Error Array of plugin data or WP_Error if failed.
19+
* @return array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], version: string}|WP_Error Array of plugin data or WP_Error if failed.
2020
*/
2121
function perflab_query_plugin_info( string $plugin_slug ) {
2222
$transient_key = 'perflab_plugins_info';
@@ -40,7 +40,6 @@ function perflab_query_plugin_info( string $plugin_slug ) {
4040
'requires',
4141
'requires_php',
4242
'requires_plugins',
43-
'download_link',
4443
'version', // Needed by install_plugin_install_status().
4544
);
4645

@@ -113,7 +112,7 @@ function perflab_query_plugin_info( string $plugin_slug ) {
113112
/**
114113
* Validated (mostly) plugin data.
115114
*
116-
* @var array<string, array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], download_link: string, version: string}> $plugins
115+
* @var array<string, array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], version: string}> $plugins
117116
*/
118117
return $plugins[ $plugin_slug ];
119118
}
@@ -343,11 +342,27 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
343342
}
344343
$processed_plugins[] = $plugin_slug;
345344

346-
$plugin_data = perflab_query_plugin_info( $plugin_slug );
345+
// Get the freshest data (including the most recent download_link) as opposed what is cached by perflab_query_plugin_info().
346+
$plugin_data = plugins_api(
347+
'plugin_information',
348+
array(
349+
'slug' => $plugin_slug,
350+
'fields' => array(
351+
'download_link' => true,
352+
'requires_plugins' => true,
353+
'sections' => false, // Omit the bulk of the response which we don't need.
354+
),
355+
)
356+
);
357+
347358
if ( $plugin_data instanceof WP_Error ) {
348359
return $plugin_data;
349360
}
350361

362+
if ( is_object( $plugin_data ) ) {
363+
$plugin_data = (array) $plugin_data;
364+
}
365+
351366
// Add recommended plugins (soft dependencies) to the list of plugins installed and activated.
352367
if ( 'embed-optimizer' === $plugin_slug ) {
353368
$plugin_data['requires_plugins'][] = 'optimization-detective';

0 commit comments

Comments
 (0)