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 | } |