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

Fix latest plugin version not being downloaded consistently #1693

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion plugins/performance-lab/includes/admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
// Replace new Plugin_Installer_Skin with new Quiet_Upgrader_Skin when output needs to be suppressed.
$skin = new WP_Ajax_Upgrader_Skin( array( 'api' => $plugin_data ) );
$upgrader = new Plugin_Upgrader( $skin );
$result = $upgrader->install( $plugin_data['download_link'] );
// Remove the version number from the link to download the latest plugin version.
$download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+(?:-\w+)?\.zip#', '$1.zip', $plugin_data['download_link'] );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+(?:-\w+)?\.zip#', '$1.zip', $plugin_data['download_link'] );
$download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d.*?.zip#', '$1.zip', $plugin_data['download_link'] );

Copy link
Member

Choose a reason for hiding this comment

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

Or rather, per #1693 (comment)

Suggested change
$download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+(?:-\w+)?\.zip#', '$1.zip', $plugin_data['download_link'] );
$download_link = (string) preg_replace( '#(\/plugin\/[^\/.]+)\..+?\.zip#', '$1.zip', $plugin_data['download_link'] );

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of regexing this from the download_link. Is there no externally controlled place (API responses or elsewhere) that exposes the format we want here?

$result = $upgrader->install( $download_link );

if ( is_wp_error( $result ) ) {
return $result;
Expand Down
Loading