Skip to content

Commit

Permalink
Added compatiblity for custom download link (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeawhanlee authored Dec 30, 2024
1 parent 9e13846 commit 83714bd
Showing 1 changed file with 42 additions and 1 deletion.
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];
}
}

0 comments on commit 83714bd

Please sign in to comment.