Skip to content

Commit

Permalink
Merge pull request #1573 from WordPress/fix/follow-up-1562
Browse files Browse the repository at this point in the history
Performance Lab: Query only required standalone plugins to get information
  • Loading branch information
mukeshpanchal27 authored Oct 2, 2024
2 parents 3549de6 + dc9f0e3 commit 5952d55
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions plugins/performance-lab/includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
function perflab_query_plugin_info( string $plugin_slug ) {
$transient_key = 'perflab_plugins_info';
$plugins = get_transient( $transient_key );
$fields = array(

if ( is_array( $plugins ) ) {
// If the specific plugin_slug is not in the cache, return an error.
if ( ! isset( $plugins[ $plugin_slug ] ) ) {
return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'performance-lab' ) );
}
return $plugins[ $plugin_slug ]; // Return cached plugin info if found.
}

$fields = array(
'name',
'slug',
'short_description',
Expand All @@ -32,14 +41,6 @@ function perflab_query_plugin_info( string $plugin_slug ) {
'version', // Needed by install_plugin_install_status().
);

if ( is_array( $plugins ) ) {
// If the specific plugin_slug is not in the cache, return an error.
if ( ! isset( $plugins[ $plugin_slug ] ) ) {
return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'performance-lab' ) );
}
return $plugins[ $plugin_slug ]; // Return cached plugin info if found.
}

// Proceed with API request since no cache hit.
$response = plugins_api(
'query_plugins',
Expand Down Expand Up @@ -67,8 +68,12 @@ function perflab_query_plugin_info( string $plugin_slug ) {
return new WP_Error( 'no_plugins', __( 'No plugins found in the API response.', 'performance-lab' ) );
}

$plugins = array();
$plugins = array();
$standalone_plugins = array_flip( perflab_get_standalone_plugins() );
foreach ( $response->plugins as $plugin_data ) {
if ( ! isset( $standalone_plugins[ $plugin_data['slug'] ] ) ) {
continue;
}
$plugins[ $plugin_data['slug'] ] = wp_array_slice_assoc( $plugin_data, $fields );
}

Expand Down

0 comments on commit 5952d55

Please sign in to comment.