| 1 |
<?php |
| 2 |
|
| 3 |
namespace Buttonizer\Legacy\Utils; |
| 4 |
|
| 5 |
class ProInstallFree |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Download plugin/Latest version |
| 9 |
* |
| 10 |
* Since our standalone, we do not need to seperate installs |
| 11 |
* This is why we are downloading/updating our older plugin |
| 12 |
*/ |
| 13 |
public static function upgrade() |
| 14 |
{ |
| 15 |
// Include required libs for installation |
| 16 |
require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); |
| 17 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); |
| 18 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'); |
| 19 |
require_once(ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'); |
| 20 |
|
| 21 |
// Cannot update/install |
| 22 |
if (!current_user_can('install_plugins')) { |
| 23 |
wp_die(__('Sorry, you are not allowed to install plugins on this site. Please ask your administrator to update.', 'buttonizer-multifunctional-button')); |
| 24 |
} |
| 25 |
|
| 26 |
$upgrader = new \Plugin_Upgrader(new \WP_Ajax_Upgrader_Skin()); |
| 27 |
|
| 28 |
// Is the free version already installed? Update it to the newest version |
| 29 |
if (array_key_exists('buttonizer-multifunctional-button/buttonizer.php', \get_plugins())) { |
| 30 |
$upgrader->upgrade("buttonizer-multifunctional-button"); |
| 31 |
} else { |
| 32 |
$upgrader->install("https://downloads.wordpress.org/plugin/buttonizer-multifunctional-button.latest-stable.zip"); |
| 33 |
} |
| 34 |
|
| 35 |
self::activatePlugin(); |
| 36 |
} |
| 37 |
|
| 38 |
public static function activatePlugin() |
| 39 |
{ |
| 40 |
// Activate original plugin |
| 41 |
\activate_plugin("buttonizer-multifunctional-button", "", false, true); |
| 42 |
|
| 43 |
// Deactivate Buttonizer PRO |
| 44 |
\deactivate_plugins(plugin_basename(BUTTONIZER_PLUGIN_DIR), true); |
| 45 |
|
| 46 |
exit; |
| 47 |
} |
| 48 |
} |
| 49 |
|