Skip to content
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

Avoid passing incomplete data to perflab_render_plugin_card() and show error when plugin directory API query fails #1175

Merged

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Apr 23, 2024

Summary

When working on Image Prioritizer (#1172), I added the plugin to the perflab_get_standalone_plugin_data() but then I started getting PHPUnit test failures. I also got a bunch of warnings on the Performance screen:

image

The issue here is that Image Prioritizer is not on WordPress.org yet, so the call to perflab_query_plugin_info() is returning an empty array. Nevertheless, this logic in perflab_render_plugin_card() is not working as expected:

function perflab_render_plugin_card( array $plugin_data ) {
// If no plugin data is returned, return.
if ( empty( $plugin_data ) ) {
return;
}

This is because we are merging the response from WordPress.org with our own data from perflab_get_standalone_plugin_data() meaning $plugin_data will never be empty:

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;
}
}

This scenario could happen not only if the plugin is not on WordPress.org but also if the query fails due to WordPress.org being down. So with this PR an error is now shown when an error occurs:

image

This PR also removes the standalone plugin version from being referenced on the Performance screen. It was only referenced in aria-label and data-title attributes.

Lastly, when a WordPress.org Plugins API query fails during installation, an error message is now displayed rather than just a generic error.

Related: #1170

@westonruter westonruter added [Type] Bug An existing feature is broken Performance Lab Plugin Issue relates to work in the Performance Lab Plugin only labels Apr 23, 2024
@westonruter westonruter added this to the performance-lab 3.1.0 milestone Apr 23, 2024
Copy link

github-actions bot commented Apr 23, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter westonruter mentioned this pull request Apr 23, 2024

/** This filter is documented in wp-admin/includes/class-wp-plugin-install-list-table.php */
$description = apply_filters( 'plugin_install_description', $description, $plugin_data );
$version = $plugin_data['version'];
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't see a need for the version to be mentioned among the features, so I removed it.

wp_die(
wp_kses(
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.', 'default' ),
__( 'https://wordpress.org/support/forums/', 'default' )
),
) . ' ' . $api->get_error_message(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Now the specific error is shown rather than just the generic message.

The error message may include markup such as is returned by validate_plugin_requirements().
@@ -304,7 +304,7 @@ function perflab_install_activate_plugin_callback() {

$result = activate_plugin( $plugin_basename );
if ( is_wp_error( $result ) ) {
wp_die( esc_html( $result->get_error_message() ) );
wp_die( wp_kses_post( $result->get_error_message() ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes HTML mistakenly being escaped:

image

Now:

image

Co-authored-by: Pascal Birchler <pascalb@google.com>
'short_description' => true,
'icons' => true,
),
'fields' => array_fill_keys( $fields, true ),
Copy link
Member

Choose a reason for hiding this comment

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

Nice ❤️

@mukeshpanchal27 mukeshpanchal27 merged commit ae46209 into trunk Apr 24, 2024
14 checks passed
@mukeshpanchal27 mukeshpanchal27 deleted the fix/passing-incomplete-data-to-render-plugin-card branch April 24, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Lab Plugin Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants