From 03607c40ebf5910eaf820fbf42e4d2ed99128249 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde <73636812+ShyamGadde@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:04:31 +0530 Subject: [PATCH 1/2] Remove plugin version number from download link This is done so that it automatically downloads the latest version --- plugins/performance-lab/includes/admin/plugins.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index 285d503e5..76136c341 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -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+\.zip#', '$1.zip', $plugin_data['download_link'] ); + $result = $upgrader->install( $download_link ); if ( is_wp_error( $result ) ) { return $result; From 8398cfe364df9796055016f933a06a8b2d6e09b6 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde <73636812+ShyamGadde@users.noreply.github.com> Date: Sat, 23 Nov 2024 01:05:31 +0530 Subject: [PATCH 2/2] Update regex to handle version tags like `-rc` and `-beta` in plugin download links --- plugins/performance-lab/includes/admin/plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index 76136c341..36bec1e16 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -373,7 +373,7 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce $skin = new WP_Ajax_Upgrader_Skin( array( 'api' => $plugin_data ) ); $upgrader = new Plugin_Upgrader( $skin ); // Remove the version number from the link to download the latest plugin version. - $download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+\.zip#', '$1.zip', $plugin_data['download_link'] ); + $download_link = (string) preg_replace( '#(\/plugin\/[^\/]+)\.\d+\.\d+\.\d+(?:-\w+)?\.zip#', '$1.zip', $plugin_data['download_link'] ); $result = $upgrader->install( $download_link ); if ( is_wp_error( $result ) ) {