Skip to content
4 changes: 4 additions & 0 deletions includes/admin/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ function perflab_print_features_page_style() {
.plugin-card-top {
min-height: auto;
}
.plugin-card .perflab-plugin-experimental {
font-size: 80%;
font-weight: normal;
}
</style>
<?php
}
Expand Down
38 changes: 30 additions & 8 deletions includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function perflab_query_plugin_info( string $plugin_slug ) {
*/
function perflab_get_standalone_plugins() {
return array_keys(
perflab_get_standalone_plugin_version_constants()
perflab_get_standalone_plugin_data()
);
}

Expand All @@ -70,14 +70,24 @@ function perflab_render_plugins_ui() {
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$standalone_plugins = array();
foreach ( perflab_get_standalone_plugins() as $managed_standalone_plugin_slug ) {
$standalone_plugins[ $managed_standalone_plugin_slug ] = array(
'plugin_data' => perflab_query_plugin_info( $managed_standalone_plugin_slug ),
$plugins = array();
$experimental_plugins = array();

foreach ( perflab_get_standalone_plugin_data() as $plugin_slug => $plugin_data ) {
$plugin_data = array_merge(
$plugin_data, // Data defined within Performance Lab.
perflab_query_plugin_info( $plugin_slug ) // Data from wordpress.org.
);

// Separate experimental plugins so that they're displayed after non-experimental plugins.
if ( isset( $plugin_data['experimental'] ) && $plugin_data['experimental'] ) {
$experimental_plugins[ $plugin_slug ] = $plugin_data;
} else {
$plugins[ $plugin_slug ] = $plugin_data;
}
}

if ( empty( $standalone_plugins ) ) {
if ( empty( $plugins ) ) {
return;
}
?>
Expand All @@ -89,8 +99,11 @@ function perflab_render_plugins_ui() {
<h2 class="screen-reader-text"><?php esc_html_e( 'Plugins list', 'default' ); ?></h2>
<div id="the-list">
<?php
foreach ( $standalone_plugins as $standalone_plugin ) {
perflab_render_plugin_card( $standalone_plugin['plugin_data'] );
foreach ( $plugins as $plugin_data ) {
perflab_render_plugin_card( $plugin_data );
}
foreach ( $experimental_plugins as $plugin_data ) {
perflab_render_plugin_card( $plugin_data );
}
?>
</div>
Expand Down Expand Up @@ -269,6 +282,15 @@ function perflab_render_plugin_card( array $plugin_data ) {
<a href="<?php echo esc_url( $details_link ); ?>" class="thickbox open-plugin-details-modal">
<?php echo wp_kses_post( $title ); ?>
</a>
<?php
if ( isset( $plugin_data['experimental'] ) && $plugin_data['experimental'] ) {
?>
<em class="perflab-plugin-experimental">
<?php echo esc_html( _x( '(experimental)', 'plugin suffix', 'performance-lab' ) ); ?>
</em>
<?php
}
?>
</h3>
</div>
<div class="action-links">
Expand Down
53 changes: 40 additions & 13 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,56 @@ function perflab_render_generator() {
add_action( 'wp_head', 'perflab_render_generator' );

/**
* Gets the standalone plugin constants used for each available standalone plugin.
* Gets the standalone plugins and their data.
*
* @since 2.9.0
* @since n.e.x.t The $source parameter was removed.
* @since n.e.x.t
*
* @return array<string, string> Map of plugin slug and the version constant used.
* @return array<string, array{'constant': string, 'experimental'?: bool}> Associative array of $plugin_slug => $plugin_data pairs.
*/
function perflab_get_standalone_plugin_version_constants() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note for reviewers: This function is simply moved down (see bottom of the file), it's not being replaced as potentially the diff here may suggest.

function perflab_get_standalone_plugin_data() {
/*
* This list includes all standalone plugins that are part of the Performance Lab project,
* as `$plugin_slug => $version_constant` pairs.
* Alphabetically sorted list of plugin slugs and their data.
* Supported keys per plugin are:
* - 'constant' (string, required)
* - 'experimental' (boolean, optional)
*/
return array(
'webp-uploads' => 'WEBP_UPLOADS_VERSION',
'dominant-color-images' => 'DOMINANT_COLOR_IMAGES_VERSION',
'embed-optimizer' => 'EMBED_OPTIMIZER_VERSION',
'auto-sizes' => array(
'constant' => 'IMAGE_AUTO_SIZES_VERSION',
'experimental' => true,
),
'dominant-color-images' => array(
'constant' => 'DOMINANT_COLOR_IMAGES_VERSION',
),
'embed-optimizer' => array(
'constant' => 'EMBED_OPTIMIZER_VERSION',
'experimental' => true,
),
// TODO: Add image loading optimization plugin, dependent of Optimization Detective, once ready for end users.
'performant-translations' => 'PERFORMANT_TRANSLATIONS_VERSION',
'auto-sizes' => 'IMAGE_AUTO_SIZES_VERSION',
'speculation-rules' => 'SPECULATION_RULES_VERSION',
'performant-translations' => array(
'constant' => 'PERFORMANT_TRANSLATIONS_VERSION',
),
'speculation-rules' => array(
'constant' => 'SPECULATION_RULES_VERSION',
),
'webp-uploads' => array(
'constant' => 'WEBP_UPLOADS_VERSION',
),
);
}

/**
* Gets the standalone plugin constants used for each available standalone plugin.
*
* @since 2.9.0
* @since n.e.x.t The $source parameter was removed.
*
* @return array<string, string> Map of plugin slug and the version constant used.
*/
function perflab_get_standalone_plugin_version_constants() {
return wp_list_pluck( perflab_get_standalone_plugin_data(), 'constant' );
}

/**
* Places the Performance Lab's object cache drop-in in the drop-ins folder.
*
Expand Down