Skip to content

Commit

Permalink
update plugin family to corresponding version
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Dec 30, 2024
1 parent f008e33 commit 78bc9fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand All @@ -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,
Expand Down Expand Up @@ -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];
}
}

0 comments on commit 78bc9fc

Please sign in to comment.