PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / Promotional / Onboard / Classes / PluginStatus.php

PluginStatus.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at Promotional/Onboard/Classes/PluginStatus.php

124 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Promotional\Onboard\Classes;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class PluginStatus {
8
9 private static $instance;
10 private $installedPlugins = [];
11 private $activatedPlugins = [];
12
13 public function __construct() {
14 $this->collect_installed_plugins();
15 $this->collect_activated_plugins();
16 }
17
18 private function collect_installed_plugins() {
19 foreach ( get_plugins() as $key => $plugin ) {
20 array_push( $this->installedPlugins, $key );
21 }
22 }
23
24 private function collect_activated_plugins() {
25 foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) {
26 array_push( $this->activatedPlugins, $plugin );
27 }
28 }
29
30 public static function instance() {
31 if ( ! static::$instance ) {
32 static::$instance = new static();
33 }
34
35 return static::$instance;
36 }
37
38 public function get_installed_plugins() {
39 return $this->installedPlugins;
40 }
41
42 public function get_activated_plugins() {
43 return $this->activatedPlugins;
44 }
45
46 public function get_status( $name ) {
47 $data = [
48 "url" => "",
49 "activation_url" => "",
50 "installation_url" => "",
51 "title" => "",
52 "status" => "",
53 ];
54
55 if ( $this->check_installed_plugin( $name ) ) {
56 if ( $this->check_activated_plugin( $name ) ) {
57 $data['title'] = __( 'Activated', 'emailkit' );
58 $data['status'] = "activated";
59 } else {
60 $data['title'] = __( 'Activate Now', 'emailkit' );
61 $data['status'] = 'installed';
62 $data['activation_url'] = $this->activation_url( $name );
63 }
64 } else {
65 $data['title'] = __( 'Install Now', 'emailkit' );
66 $data['status'] = 'not_installed';
67 $data['installation_url'] = $this->installation_url( $name );
68 $data['activation_url'] = $this->activation_url( $name );
69 }
70
71 return $data;
72 }
73
74 public function check_installed_plugin( $name ) {
75 return in_array( $name, $this->installedPlugins );
76 }
77
78 public function check_activated_plugin( $name ) {
79 return in_array( $name, $this->activatedPlugins );
80 }
81
82 public function activation_url( $pluginName ) {
83
84 return wp_nonce_url( 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 ), 'activate-plugin_' . $pluginName );
93 }
94
95 public function installation_url( $pluginName ) {
96 $action = 'install-plugin';
97 $pluginSlug = $this->get_plugin_slug( $pluginName );
98
99 return wp_nonce_url(
100 add_query_arg(
101 array(
102 'action' => $action,
103 'plugin' => $pluginSlug
104 ),
105 admin_url( 'update.php' )
106 ),
107 $action . '_' . $pluginSlug
108 );
109 }
110
111 public function get_plugin_slug( $name ) {
112 $split = explode( '/', $name );
113
114 return isset( $split[0] ) ? $split[0] : null;
115 }
116
117 public function activated_url( $pluginName ) {
118 return add_query_arg(
119 array(
120 'page' => $this->get_plugin_slug( $pluginName ),
121 ),
122 admin_url( 'admin.php' ) );
123 }
124 }