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

Closes #17: Install link of RankMath must change based on the plugin of origin #19

Open
wants to merge 1 commit 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
43 changes: 42 additions & 1 deletion src/Controller/PluginFamily.php
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];
}
}
Loading