PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.3.2
Admin Columns v4.3.2
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Admin / AddonStatus.php
codepress-admin-columns / classes / Admin Last commit date
Asset 5 years ago HelpTab 5 years ago Main 5 years ago Menu 5 years ago Notice 5 years ago Preference 5 years ago ScreenOption 5 years ago Section 5 years ago AddonStatus.php 5 years ago Admin.php 5 years ago AdminNetwork.php 5 years ago AdminScripts.php 5 years ago Banner.php 5 years ago HelpTab.php 5 years ago Helpable.php 5 years ago MainFactory.php 5 years ago MainFactoryInterface.php 5 years ago Menu.php 5 years ago MenuFactory.php 5 years ago MenuFactoryInterface.php 5 years ago NetworkRequestHandler.php 5 years ago Page.php 5 years ago PageFactory.php 5 years ago PageFactoryInterface.php 5 years ago PageRequestHandler.php 5 years ago RequestHandler.php 5 years ago RequestHandlerInterface.php 5 years ago ScreenOption.php 5 years ago ScreenOptions.php 5 years ago Section.php 5 years ago SectionCollection.php 5 years ago Table.php 5 years ago Tooltip.php 5 years ago WpMenuFactory.php 5 years ago
AddonStatus.php
216 lines
1 <?php
2
3 namespace AC\Admin;
4
5 use AC\Integration;
6 use AC\PluginInformation;
7
8 class AddonStatus {
9
10 const REDIRECT_PARAM = 'ac-redirect';
11 const REDIRECT_TO_SITE = 1;
12 const REDIRECT_TO_NETWORK = 2;
13
14 /**
15 * @var PluginInformation
16 */
17 private $plugin;
18
19 /**
20 * @var Integration
21 */
22 private $integration;
23
24 /**
25 * @var bool
26 */
27 private $is_multisite;
28
29 /**
30 * @var bool
31 */
32 private $is_network_admin;
33
34 public function __construct( PluginInformation $plugin, Integration $integration, $is_multisite, $is_network_admin ) {
35 $this->plugin = $plugin;
36 $this->integration = $integration;
37 $this->is_multisite = (bool) $is_multisite;
38 $this->is_network_admin = (bool) $is_network_admin;
39 }
40
41 private function render_active_label() { ?>
42 <span class="active"><?php _e( 'Active', 'codepress-admin-columns' ); ?></span>
43 <?php
44 }
45
46 private function render_network_active_label() { ?>
47 <span class="active"><?php _e( 'Network Active', 'codepress-admin-columns' ); ?></span>
48 <?php
49 }
50
51 private function add_redirect( $url, $value ) {
52 return add_query_arg( [
53 self::REDIRECT_PARAM => $value,
54 ], $url );
55 }
56
57 private function render_network_deactivate() {
58 ?>
59 <a href="<?php echo esc_url( $this->add_redirect( $this->plugin->get_plugin_network_action_url( 'deactivate' ), self::REDIRECT_TO_NETWORK ) ); ?>" class="button right">
60 <?php _e( 'Deactivate', 'codepress-admin-columns' ); ?>
61 </a>
62 <?php
63 }
64
65 private function render_network_activate() {
66 ?>
67 <a href="<?php echo esc_url( $this->add_redirect( $this->plugin->get_plugin_network_action_url( 'activate' ), self::REDIRECT_TO_NETWORK ) ); ?>" class="button right button-primary">
68 <?php _e( 'Network Activate', 'codepress-admin-columns' ); ?>
69 </a>
70 <?php
71 }
72
73 private function render_deactivate() {
74 ?>
75 <a href="<?php echo esc_url( $this->add_redirect( $this->plugin->get_plugin_action_url( 'deactivate' ), self::REDIRECT_TO_SITE ) ); ?>" class="button right">
76 <?php _e( 'Deactivate', 'codepress-admin-columns' ); ?>
77 </a>
78 <?php
79 }
80
81 private function render_activate() {
82 ?>
83 <a href="<?php echo esc_url( $this->add_redirect( $this->plugin->get_plugin_action_url( 'activate' ), self::REDIRECT_TO_SITE ) ); ?>" class="button right button-primary">
84 <?php _e( 'Activate', 'codepress-admin-columns' ); ?>
85 </a>
86 <?php
87 }
88
89 private function render_install() {
90 ?>
91 <a href="#" class="button" data-install>
92 <?php esc_html_e( 'Download & Install', 'codepress-admin-columns' ); ?>
93 </a>
94 <?php
95 }
96
97 private function render_more_info() {
98 ?>
99 <a target="_blank" href="<?php echo esc_url( $this->integration->get_link() ); ?>" class="button">
100 <?php esc_html_e( 'Get this add-on', 'codepress-admin-columns' ); ?>
101 </a>
102 <?php
103 }
104
105 private function is_network_active() {
106 return $this->is_multisite && $this->plugin->is_network_active();
107 }
108
109 private function is_active() {
110 if ( $this->is_network_active() ) {
111 return false;
112 }
113
114 if ( $this->is_network_admin && $this->plugin->is_active() ) {
115 return false;
116 }
117
118 return $this->plugin->is_active();
119 }
120
121 private function is_network_deactivatable() {
122 return current_user_can( 'activate_plugins' )
123 && $this->is_multisite
124 && $this->is_network_admin
125 && $this->is_network_active();
126 }
127
128 private function is_network_activatable() {
129 return current_user_can( 'activate_plugins' )
130 && $this->is_multisite
131 && $this->is_network_admin
132 && $this->plugin->is_installed()
133 && ! $this->is_network_active();
134 }
135
136 private function is_deactivatable() {
137 if ( $this->is_network_deactivatable() ) {
138 return false;
139 }
140
141 return current_user_can( 'activate_plugins' )
142 && ! $this->is_network_admin
143 && $this->is_active();
144 }
145
146 private function is_activatable() {
147 if ( $this->is_network_activatable() ) {
148 return false;
149 }
150
151 return current_user_can( 'activate_plugins' )
152 && ! $this->is_network_admin
153 && $this->plugin->is_installed()
154 && ! $this->plugin->is_network_active()
155 && ! $this->is_active();
156 }
157
158 private function is_installable() {
159 if ( ! current_user_can( 'install_plugins' ) ) {
160 return false;
161 }
162
163 if ( $this->plugin->is_installed() ) {
164 return false;
165 }
166
167 return $this->is_multisite
168 ? $this->is_network_admin
169 : true;
170 }
171
172 private function show_more_info() {
173 return ! $this->is_installable() && ! $this->plugin->is_installed();
174 }
175
176 public function render() {
177 if ( ! ac_is_pro_active() ) {
178 $this->render_more_info();
179
180 return;
181 }
182
183 if ( $this->is_network_active() ) {
184 $this->render_network_active_label();
185 }
186
187 if ( $this->is_active() ) {
188 $this->render_active_label();
189 }
190
191 if ( $this->is_network_deactivatable() ) {
192 $this->render_network_deactivate();
193 }
194
195 if ( $this->is_deactivatable() ) {
196 $this->render_deactivate();
197 }
198
199 if ( $this->is_network_activatable() ) {
200 $this->render_network_activate();
201 }
202
203 if ( $this->is_activatable() ) {
204 $this->render_activate();
205 }
206
207 if ( $this->is_installable() ) {
208 $this->render_install();
209 }
210
211 if ( $this->show_more_info() ) {
212 $this->render_more_info();
213 }
214 }
215
216 }