ajax.php
3 weeks ago
install-notice.php
3 weeks ago
install-tracker.php
3 weeks ago
onboard-status.php
3 weeks ago
plugin-data-sender.php
1 year ago
plugin-installer.php
3 weeks ago
plugin-skin.php
1 year ago
plugin-status.php
4 years ago
utils.php
1 year ago
plugin-status.php
128 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ElementsKit_Lite\Libs\Framework\Classes; |
| 4 | |
| 5 | defined( 'ABSPATH' ) || exit; |
| 6 | |
| 7 | class Plugin_Status { |
| 8 | private static $instance; |
| 9 | private $installedPlugins = array(); |
| 10 | private $activatedPlugins = array(); |
| 11 | |
| 12 | public function __construct() { |
| 13 | $this->collect_installed_plugins(); |
| 14 | $this->collect_activated_plugins(); |
| 15 | } |
| 16 | |
| 17 | private function collect_installed_plugins() { |
| 18 | foreach ( get_plugins() as $key => $plugin ) { |
| 19 | array_push( $this->installedPlugins, $key ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | private function collect_activated_plugins() { |
| 24 | foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) { |
| 25 | array_push( $this->activatedPlugins, $plugin ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public static function instance() { |
| 30 | if ( ! static::$instance ) { |
| 31 | static::$instance = new static(); |
| 32 | } |
| 33 | |
| 34 | return static::$instance; |
| 35 | } |
| 36 | |
| 37 | public function get_installed_plugins() { |
| 38 | return $this->installedPlugins; |
| 39 | } |
| 40 | |
| 41 | public function get_activated_plugins() { |
| 42 | return $this->activatedPlugins; |
| 43 | } |
| 44 | |
| 45 | public function get_status( $name ) { |
| 46 | $data = array( |
| 47 | 'url' => '', |
| 48 | 'activation_url' => '', |
| 49 | 'installation_url' => '', |
| 50 | 'title' => '', |
| 51 | 'status' => '', |
| 52 | ); |
| 53 | |
| 54 | if ( $this->check_installed_plugin( $name ) ) { |
| 55 | if ( $this->check_activated_plugin( $name ) ) { |
| 56 | $data['title'] = __( 'Activated', 'elementskit-lite' ); |
| 57 | $data['status'] = 'activated'; |
| 58 | } else { |
| 59 | $data['title'] = __( 'Activate Now', 'elementskit-lite' ); |
| 60 | $data['status'] = 'installed'; |
| 61 | $data['activation_url'] = $this->activation_url( $name ); |
| 62 | } |
| 63 | } else { |
| 64 | $data['title'] = __( 'Install Now', 'elementskit-lite' ); |
| 65 | $data['status'] = 'not_installed'; |
| 66 | $data['installation_url'] = $this->installation_url( $name ); |
| 67 | $data['activation_url'] = $this->activation_url( $name ); |
| 68 | } |
| 69 | |
| 70 | return $data; |
| 71 | } |
| 72 | |
| 73 | public function check_installed_plugin( $name ) { |
| 74 | return in_array( $name, $this->installedPlugins ); |
| 75 | } |
| 76 | |
| 77 | public function check_activated_plugin( $name ) { |
| 78 | return in_array( $name, $this->activatedPlugins ); |
| 79 | } |
| 80 | |
| 81 | public function activation_url( $pluginName ) { |
| 82 | |
| 83 | return wp_nonce_url( |
| 84 | add_query_arg( |
| 85 | array( |
| 86 | 'action' => 'activate', |
| 87 | 'plugin' => $pluginName, |
| 88 | 'plugin_status' => 'all', |
| 89 | 'paged' => '1&s', |
| 90 | ), |
| 91 | admin_url( 'plugins.php' ) |
| 92 | ), |
| 93 | 'activate-plugin_' . $pluginName |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | public function installation_url( $pluginName ) { |
| 98 | $action = 'install-plugin'; |
| 99 | $pluginSlug = $this->get_plugin_slug( $pluginName ); |
| 100 | |
| 101 | return wp_nonce_url( |
| 102 | add_query_arg( |
| 103 | array( |
| 104 | 'action' => $action, |
| 105 | 'plugin' => $pluginSlug, |
| 106 | ), |
| 107 | admin_url( 'update.php' ) |
| 108 | ), |
| 109 | $action . '_' . $pluginSlug |
| 110 | ); |
| 111 | } |
| 112 | |
| 113 | public function get_plugin_slug( $name ) { |
| 114 | $split = explode( '/', $name ); |
| 115 | |
| 116 | return isset( $split[0] ) ? $split[0] : null; |
| 117 | } |
| 118 | |
| 119 | public function activated_url( $pluginName ) { |
| 120 | return add_query_arg( |
| 121 | array( |
| 122 | 'page' => $this->get_plugin_slug( $pluginName ), |
| 123 | ), |
| 124 | admin_url( 'admin.php' ) |
| 125 | ); |
| 126 | } |
| 127 | } |
| 128 |