class-base-exception.php
2 years ago
class-cache-constants.php
2 years ago
class-cache-exception.php
2 years ago
class-key-exception.php
2 years ago
class-keytypes.php
2 years ago
class-option-exception.php
2 years ago
class-plugin-installer.php
2 years ago
class-quiet-skin.php
2 years ago
class-settings-exception.php
2 years ago
class-plugin-installer.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Data\Utils; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | use SuperbAddons\Data\Utils\QuietSkin; |
| 8 | |
| 9 | require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); |
| 10 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 11 | require_once(ABSPATH . 'wp-admin/includes/misc.php'); |
| 12 | require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 13 | require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); |
| 14 | |
| 15 | class PluginInstaller |
| 16 | { |
| 17 | public static function Install($plugin) |
| 18 | { |
| 19 | // Sanitize $plugin |
| 20 | switch ($plugin) { |
| 21 | case 'elementor': |
| 22 | // Allowed |
| 23 | $plugin_path = $plugin . '/' . $plugin . '.php'; |
| 24 | break; |
| 25 | default: |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | self::ActivatePlugin($plugin_path); |
| 30 | if (\is_plugin_active($plugin_path)) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | $plugins_api = \plugins_api( |
| 35 | 'plugin_information', |
| 36 | array( |
| 37 | 'slug' => $plugin, |
| 38 | 'fields' => array( |
| 39 | 'short_description' => false, |
| 40 | 'sections' => false, |
| 41 | 'requires' => false, |
| 42 | 'rating' => false, |
| 43 | 'ratings' => false, |
| 44 | 'downloaded' => false, |
| 45 | 'last_updated' => false, |
| 46 | 'added' => false, |
| 47 | 'tags' => false, |
| 48 | 'compatibility' => false, |
| 49 | 'homepage' => false, |
| 50 | 'donate_link' => false, |
| 51 | ), |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | if (is_wp_error($plugins_api)) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | $upgrader = new \Plugin_Upgrader(new QuietSkin()); |
| 60 | |
| 61 | $installation_result = $upgrader->install($plugins_api->download_link); |
| 62 | |
| 63 | if (!$installation_result || is_wp_error($installation_result)) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | self::ActivatePlugin($plugin_path); |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | private static function ActivatePlugin($plugin_path) |
| 73 | { |
| 74 | if (file_exists(WP_PLUGIN_DIR . '/' . $plugin_path)) { |
| 75 | \activate_plugin($plugin_path, '', false, true); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |