Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Implemented single WordPress.org API request to get plugin information
  • Loading branch information
narenin committed Sep 25, 2024
commit 23bd59163464a79af8a3e822498419d11f86bd78
18 changes: 17 additions & 1 deletion plugins/performance-lab/includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function perflab_query_plugin_info( string $plugin_slug ) {

$plugins = array();
foreach ( $data['plugins'] as $plugin_data ) {
$plugins[ $plugin_data['slug'] ] = wp_array_slice_assoc(
$plugin_info = wp_array_slice_assoc(
$plugin_data,
array(
'name',
Expand All @@ -54,6 +54,17 @@ function perflab_query_plugin_info( string $plugin_slug ) {
'version',
)
);

// Ensure the 'requires_plugins' is always an array.
if ( ! isset( $plugin_info['requires_plugins'] ) || ! is_array( $plugin_info['requires_plugins'] ) ) {
$plugin_info['requires_plugins'] = array();
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this code needed? Right below the if $plugin_info['requires_plugins'] is not set, then it is set to false, which will then never occur. Apparently this if statement could be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// Ensure 'requires' and 'requires_php' are either strings or false.
$plugin_info['requires'] = isset( $plugin_info['requires'] ) ? $plugin_info['requires'] : false;
$plugin_info['requires_php'] = isset( $plugin_info['requires_php'] ) ? $plugin_info['requires_php'] : false;

$plugins[ $plugin_data['slug'] ] = $plugin_info;
}

set_transient( $transient_key, $plugins, HOUR_IN_SECONDS );
Expand All @@ -62,6 +73,11 @@ function perflab_query_plugin_info( string $plugin_slug ) {
return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'default' ) );
}

/**
* Validated (mostly) plugin data.
*
* @var array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: array<string>, download_link: string, version: string} $plugin
*/
return $plugins[ $plugin_slug ];
}

Expand Down