PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / trunk
Wp Social Login and Register Social Counter vtrunk
trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / lib / onboard / classes / plugin-status.php
wp-social / lib / onboard / classes Last commit date
ajax.php 7 months ago plugin-data-sender.php 9 months ago plugin-installer.php 7 months ago plugin-skin.php 7 months ago plugin-status.php 4 years ago utils.php 3 years ago
plugin-status.php
124 lines
1 <?php
2
3 namespace WP_Social\Lib\Onboard\Classes;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Plugin_Status {
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', 'wp-social' );
58 $data['status'] = "activated";
59 } else {
60 $data['title'] = __( 'Activate Now', 'wp-social' );
61 $data['status'] = 'installed';
62 $data['activation_url'] = $this->activation_url( $name );
63 }
64 } else {
65 $data['title'] = __( 'Install Now', 'wp-social' );
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 }