From 78bc9fc574f235728e3758c24553f68b34d70ac5 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Mon, 30 Dec 2024 10:17:15 +0200 Subject: [PATCH 1/2] update plugin family to corresponding version --- composer.json | 2 +- .../PluginFamily/Controller/PluginFamily.php | 43 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 541620840f..5e33d1e954 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "composer/installers": "^1.0 || ^2.0", "voku/simple_html_dom": "^4.8", "wp-media/apply-filters-typed": "^1.0", - "wp-media/plugin-family": "^1.0.3" + "wp-media/plugin-family": "dev-17/enhancement-rankmath-install-link-must-change-based-on-plugin-origin" }, "require-dev": { "php": "^7 || ^8", diff --git a/inc/Dependencies/WPMedia/PluginFamily/Controller/PluginFamily.php b/inc/Dependencies/WPMedia/PluginFamily/Controller/PluginFamily.php index c81f9e873c..7f83db1b5e 100644 --- a/inc/Dependencies/WPMedia/PluginFamily/Controller/PluginFamily.php +++ b/inc/Dependencies/WPMedia/PluginFamily/Controller/PluginFamily.php @@ -165,6 +165,15 @@ private function get_plugin(): string { * @return string */ private function get_download_url(): string { + + $slug = $this->get_slug(); + + $custom_download_url = $this->maybe_get_custom_download_url( $slug ); + + if ( false !== $custom_download_url ) { + return $custom_download_url; + } + $plugin_install = ABSPATH . 'wp-admin/includes/plugin-install.php'; if ( ! defined( 'ABSPATH' ) || ! file_exists( $plugin_install ) ) { @@ -178,7 +187,7 @@ private function get_download_url(): string { require_once $plugin_install; // @phpstan-ignore-line $data = [ - 'slug' => $this->get_slug(), + 'slug' => $slug, 'fields' => [ 'download_link' => true, 'short_description' => false, @@ -251,4 +260,36 @@ private function set_error( $error ) { wp_safe_redirect( wp_get_referer() ); exit; } + + /** + * Returns a custom download url for plugin if exists. + * + * @param string $plugin_slug plugin slug. + * @return string|bool + */ + private function maybe_get_custom_download_url( string $plugin_slug ) { + $parent_plugin_slug = $this->get_parent_plugin_slug(); + + $urls = [ + 'seo-by-rank-math' => 'https://rankmath.com/downloads/plugin-family/' . $parent_plugin_slug, + ]; + + if ( ! isset( $urls[ $plugin_slug ] ) ) { + return false; + } + + return $urls[ $plugin_slug ]; + } + + /** + * Get parent plugin slug. + * + * @return string + */ + private function get_parent_plugin_slug(): string { + $plugin_path = plugin_basename( __FILE__ ); + $chunks = explode( '/', $plugin_path ); + + return $chunks[0]; + } } From 65b652e0ab0c0e97e57f84830fe978c053e7cd33 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Mon, 30 Dec 2024 12:14:11 +0200 Subject: [PATCH 2/2] adjust composer file --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5e33d1e954..8f3b7e9da8 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "composer/installers": "^1.0 || ^2.0", "voku/simple_html_dom": "^4.8", "wp-media/apply-filters-typed": "^1.0", - "wp-media/plugin-family": "dev-17/enhancement-rankmath-install-link-must-change-based-on-plugin-origin" + "wp-media/plugin-family": "^1.0" }, "require-dev": { "php": "^7 || ^8",