-
Notifications
You must be signed in to change notification settings - Fork 135
Show plugin cards when external requests are disabled #2190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 11 commits
d1dae91
d40dca2
727be0c
d49280c
9db2772
2c2777f
661fa92
0e26be7
19f15f0
e79cc1c
e4e34af
2270f60
9598ba3
9ae95ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these functions can be put directly into |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,225 @@ | ||||||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
* Local Plugin Fallback functionality for Performance Lab. | ||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* Provides fallback functionality to show plugin cards for locally installed | ||||||||||||||||||||||||||||||||||||||||
* performance-related plugins when external API requests are disabled or fail. | ||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* @package performance-lab | ||||||||||||||||||||||||||||||||||||||||
* @since n.e.x.t | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// @codeCoverageIgnoreStart | ||||||||||||||||||||||||||||||||||||||||
if ( ! defined( 'ABSPATH' ) ) { | ||||||||||||||||||||||||||||||||||||||||
exit; // Exit if accessed directly. | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
// @codeCoverageIgnoreEnd | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// Ensure this file is loaded when Performance Lab plugin is active. | ||||||||||||||||||||||||||||||||||||||||
if ( ! function_exists( 'perflab_get_local_plugin_fallback_data' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||
* Gets local plugin information for Performance Lab standalone plugins. | ||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* This function provides fallback data when external API requests to WordPress.org | ||||||||||||||||||||||||||||||||||||||||
* are disabled or fail, allowing the Performance Lab interface to still show | ||||||||||||||||||||||||||||||||||||||||
* cards for locally installed performance plugins. | ||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* @since n.e.x.t | ||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||
* @param string[] $plugin_slugs Array of plugin slugs to get local info for. | ||||||||||||||||||||||||||||||||||||||||
* @return array<string, array{name: string, slug: string, short_description: string, requires: string|false, requires_php: string|false, requires_plugins: string[], version: string, is_installed: bool, is_active: bool}> Local plugin data keyed by slug. | ||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||
function perflab_get_local_plugin_fallback_data( array $plugin_slugs ): array { | ||||||||||||||||||||||||||||||||||||||||
// Ensure we have access to plugin functions. | ||||||||||||||||||||||||||||||||||||||||
if ( ! function_exists( 'get_plugins' ) ) { | ||||||||||||||||||||||||||||||||||||||||
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
// Ensure we have access to plugin functions. | |
if ( ! function_exists( 'get_plugins' ) ) { | |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
} | |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constant is always defined. No need for this if
statement.
if ( ! defined( 'WP_PLUGIN_DIR' ) ) { | |
return ''; | |
} |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugins we feature all use readme.txt
, so I think we can just use that.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this regular expression right? The description is the paragraph before the == Description ==
. For example, it is line 10 here, not line 14:
performance/plugins/performance-lab/readme.txt
Lines 1 to 14 in 4f17dd7
=== Performance Lab === | |
Contributors: wordpressdotorg | |
Tested up to: 6.8 | |
Stable tag: 4.0.0 | |
License: GPLv2 or later | |
License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
Tags: performance, site health, measurement, optimization, diagnostics | |
Performance plugin from the WordPress Performance Team, which is a collection of standalone performance features. | |
== Description == | |
The Performance Lab plugin is a collection of features focused on enhancing performance of your site, most of which should eventually be merged into WordPress core. The plugin facilitates the discovery and activation of the individual performance feature plugins which the performance team is developing. In this way you can test the features to get their benefits before they become available in WordPress core. You can also play an important role by providing feedback to further improve the solutions. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two conditions can be combined.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markdown isn't allowed in plugin descriptions, so these can be removed.
// Remove markdown formatting and clean up. | |
$description = preg_replace( '/\*\*(.*?)\*\*/', '$1', $description ) ?? $description; | |
$description = preg_replace( '/\*(.*?)\*/', '$1', $description ) ?? $description; | |
$description = preg_replace( '/\[([^\]]+)\]\([^\)]+\)/', '$1', $description ) ?? $description; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't used anymore.
/** | |
* Sanitizes plugin description for display. | |
* | |
* @since n.e.x.t | |
* | |
* @param string $description Raw plugin description. | |
* @return string Sanitized description. | |
*/ | |
function perflab_sanitize_plugin_description( string $description ): string { | |
if ( '' === $description ) { | |
return ''; | |
} | |
// Strip all HTML tags and decode entities. | |
$description = wp_strip_all_tags( $description ); | |
$description = html_entity_decode( $description, ENT_QUOTES, 'UTF-8' ); | |
return trim( $description ); | |
} |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Embed Optimizer has a hard dependency on Optimization Detective. | |
// For known Performance Lab plugins, add their specific dependencies. | |
// Embed Optimizer has a soft dependency on Optimization Detective. | |
if ( 'embed-optimizer' === $plugin_slug ) { | |
$requires_plugins[] = 'optimization-detective'; | |
} |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is now duplicated with:
performance/plugins/performance-lab/includes/admin/plugins.php
Lines 429 to 432 in 4f17dd7
// Add recommended plugins (soft dependencies) to the list of plugins installed and activated. | |
if ( 'embed-optimizer' === $plugin_slug ) { | |
$plugin_data['requires_plugins'][] = 'optimization-detective'; | |
} |
It would be good to extract this into a separate helper function.
In fact, this information could be added as part of perflab_get_standalone_plugin_data()
, like as a new suggests_plugins
key.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? It would be parsed out of RequiresPlugins
, no?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is no longer used.
/** | |
* Gets plugin settings URL for a given plugin slug. | |
* | |
* This attempts to determine the settings URL for locally installed performance plugins. | |
* | |
* @since n.e.x.t | |
* | |
* @param string $plugin_slug Plugin slug. | |
* @return string|null Settings URL or null if not available. | |
*/ | |
function perflab_get_local_plugin_settings_url( string $plugin_slug ): ?string { | |
return perflab_get_plugin_settings_url( $plugin_slug ); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? It's already being loaded below.