| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Plugins Widget |
| 4 |
* |
| 5 |
* Grab current Child Site plugin data & build Widget |
| 6 |
* |
| 7 |
* @package MainWP/Plugins |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class MainWP_Widget_Plugins |
| 19 |
*/ |
| 20 |
class MainWP_Widget_Plugins { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 21 |
/** |
| 22 |
* Method get_class_name() |
| 23 |
* |
| 24 |
* Get Class Name |
| 25 |
* |
| 26 |
* @return string __CLASS__ Class Name. |
| 27 |
*/ |
| 28 |
public static function get_class_name() { |
| 29 |
return __CLASS__; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Method render() |
| 34 |
* |
| 35 |
* Fire off render_widget(). |
| 36 |
*/ |
| 37 |
public static function render() { |
| 38 |
static::render_widget(); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Method prepair_icons() |
| 43 |
* |
| 44 |
* Utilizes WP API to grab plugin icons, last_updated, active_installs |
| 45 |
*/ |
| 46 |
public function prepare_icons() { |
| 47 |
include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // NOSONAR - WP compatible. |
| 48 |
|
| 49 |
$args = array( |
| 50 |
'fields' => array( |
| 51 |
'last_updated' => true, |
| 52 |
'icons' => true, |
| 53 |
'active_installs' => true, |
| 54 |
), |
| 55 |
); |
| 56 |
|
| 57 |
$api = plugins_api( 'query_plugins', $args ); |
| 58 |
|
| 59 |
if ( is_wp_error( $api ) ) { |
| 60 |
$this->error = $api; |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$this->items = $api->plugins; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/** |
| 69 |
* Method render_widget() |
| 70 |
* |
| 71 |
* Build Plugins Widget |
| 72 |
* |
| 73 |
* @uses \MainWP\Dashboard\MainWP_DB::query() |
| 74 |
* @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id() |
| 75 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_object() |
| 76 |
* @uses \MainWP\Dashboard\MainWP_DB::free_result() |
| 77 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() |
| 78 |
*/ |
| 79 |
public static function render_widget() { // phpcs:ignore -- NOSONAR - complex. |
| 80 |
$current_wpid = MainWP_System_Utility::get_current_wpid(); |
| 81 |
if ( empty( $current_wpid ) ) { |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
$sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid ); |
| 86 |
$websites = MainWP_DB::instance()->query( $sql ); |
| 87 |
$allPlugins = array(); |
| 88 |
if ( $websites ) { |
| 89 |
$website = MainWP_DB::fetch_object( $websites ); |
| 90 |
if ( $website && '' !== $website->plugins ) { |
| 91 |
$plugins = json_decode( $website->plugins, 1 ); |
| 92 |
if ( is_array( $plugins ) && ! empty( $plugins ) ) { |
| 93 |
foreach ( $plugins as $plugin ) { |
| 94 |
if ( isset( $plugin['mainwp'] ) && ( 'T' === $plugin['mainwp'] ) ) { |
| 95 |
continue; |
| 96 |
} |
| 97 |
$allPlugins[] = $plugin; |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
MainWP_DB::free_result( $websites ); |
| 102 |
} |
| 103 |
|
| 104 |
static::render_html_widget( $website, $allPlugins ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Method render_html_widget(). |
| 109 |
* |
| 110 |
* Render HTML plugins widget for current site |
| 111 |
* |
| 112 |
* @param object $website Object containing the child site info. |
| 113 |
* @param array $allPlugins Array containing all detected plugins data. |
| 114 |
* |
| 115 |
* @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having() |
| 116 |
* @uses \MainWP\Dashboard\MainWP_Utility::sortmulti() |
| 117 |
*/ |
| 118 |
public static function render_html_widget( $website, $allPlugins ) { // phpcs:ignore -- NOSONAR - complex. |
| 119 |
|
| 120 |
$is_demo = MainWP_Demo_Handle::is_demo_mode(); |
| 121 |
|
| 122 |
$actived_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 1 ); |
| 123 |
$actived_plugins = MainWP_Utility::sortmulti( $actived_plugins, 'name', 'asc' ); |
| 124 |
|
| 125 |
$inactive_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 0 ); |
| 126 |
$inactive_plugins = MainWP_Utility::sortmulti( $inactive_plugins, 'name', 'asc' ); |
| 127 |
|
| 128 |
$wp_info = MainWP_DB::instance()->get_website_option( $website, 'site_info' ); |
| 129 |
$wp_info = ! empty( $wp_info ) ? json_decode( $wp_info, true ) : array(); |
| 130 |
|
| 131 |
if ( ! is_array( $wp_info ) ) { |
| 132 |
$wp_info = array(); |
| 133 |
} |
| 134 |
|
| 135 |
$use_tzformat = ! empty( $wp_info['format_datetime'] ) && is_array( $wp_info['format_datetime'] ) ? $wp_info['format_datetime'] : array(); |
| 136 |
$offs = ! empty( $use_tzformat['gmt_offset'] ) ? intval( $use_tzformat['gmt_offset'] ) : 0; |
| 137 |
$offs_info = esc_html__( ' - Timezone:', 'mainwp' ) . ' UTC' . ( $offs >= 0 ? '+' . $offs : $offs ); |
| 138 |
|
| 139 |
?> |
| 140 |
<div class="ui grid mainwp-widget-header"> |
| 141 |
<div class="twelve wide column"> |
| 142 |
<h2 class="ui header handle-drag"> |
| 143 |
<?php |
| 144 |
/** |
| 145 |
* Filter: mainwp_plugins_widget_title |
| 146 |
* |
| 147 |
* Filters the Plugins widget title text. |
| 148 |
* |
| 149 |
* @param object $website Object containing the child site info. |
| 150 |
* |
| 151 |
* @since 4.1 |
| 152 |
*/ |
| 153 |
echo esc_html( apply_filters( 'mainwp_plugins_widget_title', esc_html__( 'Plugins', 'mainwp' ), $website ) ); |
| 154 |
?> |
| 155 |
<div class="sub header"><?php esc_html_e( 'Installed plugins on the child site', 'mainwp' ); ?></div> |
| 156 |
</h2> |
| 157 |
</div> |
| 158 |
<div class="four wide column right aligned"> |
| 159 |
<div class="ui dropdown right pointing mainwp-dropdown-tab"> |
| 160 |
<i class="vertical ellipsis icon"></i> |
| 161 |
<div class="menu"> |
| 162 |
<a class="item" data-tab="active_plugins" data-value="active_plugins" title="<?php esc_attr_e( 'Active', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Active', 'mainwp' ); ?></a> |
| 163 |
<a class="item" data-tab="inactive_plugins" data-value="inactive_plugins" title="<?php esc_attr_e( 'Inactive', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Inactive', 'mainwp' ); ?></a> |
| 164 |
</div> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
</div> |
| 168 |
<div class="mainwp-scrolly-overflow"> |
| 169 |
<?php |
| 170 |
/** |
| 171 |
* Action: mainwp_plugins_widget_top |
| 172 |
* |
| 173 |
* Fires at the top of the Plugins widget on the Individual site overview page. |
| 174 |
* |
| 175 |
* @param object $website Object containing the child site info. |
| 176 |
* @param array $allPlugins Array containing all detected plugins data. |
| 177 |
* |
| 178 |
* @since 4.1 |
| 179 |
*/ |
| 180 |
do_action( 'mainwp_plugins_widget_top', $website, $allPlugins ); |
| 181 |
$site_info = $website->name . ' (' . $website->url . ') ' . ( ! empty( $offs_info ) ? $offs_info : '' ); |
| 182 |
?> |
| 183 |
<div id="mainwp-widget-active-plugins" class="ui tab active" data-tab="active_plugins" site-info="<?php echo esc_attr( $site_info ); ?>" site-id="<?php echo intval( $website->id ); ?>"> |
| 184 |
<?php |
| 185 |
/** |
| 186 |
* Action: mainwp_before_active_plugins_list |
| 187 |
* |
| 188 |
* Fires before the active plugins list in the Plugins widget on the Individual site overview page. |
| 189 |
* |
| 190 |
* @param object $website Object containing the child site info. |
| 191 |
* @param array $actived_plugins Array containing all active plugins data. |
| 192 |
* |
| 193 |
* @since 4.1 |
| 194 |
*/ |
| 195 |
do_action( 'mainwp_before_active_plugins_list', $website, $actived_plugins ); |
| 196 |
?> |
| 197 |
<div class="ui divided selection middle aligned list"> |
| 198 |
<?php |
| 199 |
$_count = count( $actived_plugins ); |
| 200 |
for ( $i = 0; $i < $_count; $i++ ) { |
| 201 |
$slug = wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ); |
| 202 |
$plugin_directory = dirname( $slug ); |
| 203 |
$plugin_name = $actived_plugins[ $i ]['name']; |
| 204 |
$plugin_title = $plugin_name . ' ' . $actived_plugins[ $i ]['version']; |
| 205 |
?> |
| 206 |
<div class="item <?php echo esc_html( dirname( $slug ) ); ?> row-manage-item" plugin-title="<?php echo esc_attr( $plugin_title ); ?>" plugin-name="<?php echo esc_attr( $plugin_name ); ?>" plugin-slug="<?php echo esc_attr( $slug ); ?>"> |
| 207 |
<input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ); ?>"/> |
| 208 |
<input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> |
| 209 |
<div class="right floated pluginsAction"> |
| 210 |
<div class="ui right pointing dropdown"> |
| 211 |
<i class="ellipsis vertical icon"></i> |
| 212 |
<div class="menu"> |
| 213 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> |
| 214 |
<div class="mainwp-plugin-deactivate item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></div> |
| 215 |
<?php } ?> |
| 216 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { ?> |
| 217 |
<a href="#" class="mainwp-plugin-delete item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Delete', 'mainwp' ); // phpcs:ignore WordPress.Security.EscapeOutput ?></a> |
| 218 |
<?php } ?> |
| 219 |
<a href="#" history-view="widget-plugins" class="mainwp-show-history item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'History', 'mainwp' ); ?></a> |
| 220 |
</div> |
| 221 |
</div> |
| 222 |
|
| 223 |
</div> |
| 224 |
<div class="middle aligned content"> |
| 225 |
<?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); // phpcs:ignore WordPress.Security.EscapeOutput ?> |
| 226 |
<a href="<?php echo esc_url( admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( dirname( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ) ) ); ?>" target="_blank" class="open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $actived_plugins[ $i ]['name'] ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"> |
| 227 |
<?php echo esc_html( $plugin_title ); ?> |
| 228 |
</a> |
| 229 |
</div> |
| 230 |
<div class="mainwp-row-actions-working"> |
| 231 |
<i class="notched circle loading icon"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> |
| 232 |
</div> |
| 233 |
</div> |
| 234 |
<?php } ?> |
| 235 |
</div> |
| 236 |
<?php |
| 237 |
/** |
| 238 |
* Action: mainwp_after_active_plugins_list |
| 239 |
* |
| 240 |
* Fires after the active plugins list in the Plugins widget on the Individual site overview page. |
| 241 |
* |
| 242 |
* @param object $website Object containing the child site info. |
| 243 |
* @param array $actived_plugins Array containing all active plugins data. |
| 244 |
* |
| 245 |
* @since 4.1 |
| 246 |
*/ |
| 247 |
do_action( 'mainwp_after_active_plugins_list', $website, $actived_plugins ); |
| 248 |
?> |
| 249 |
</div> |
| 250 |
<div id="mainwp-widget-inactive-plugins" class="ui tab" data-tab="inactive_plugins"> |
| 251 |
<?php |
| 252 |
/** |
| 253 |
* Action: mainwp_before_inactive_plugins_list |
| 254 |
* |
| 255 |
* Fires before the inactive plugins list in the Plugins widget on the Individual site overview page. |
| 256 |
* |
| 257 |
* @param object $website Object containing the child site info. |
| 258 |
* @param array $inactive_plugins Array containing all active plugins data. |
| 259 |
* |
| 260 |
* @since 4.1 |
| 261 |
*/ |
| 262 |
do_action( 'mainwp_before_inactive_plugins_list', $website, $inactive_plugins ); |
| 263 |
?> |
| 264 |
<div class="ui middle aligned divided list"> |
| 265 |
<?php |
| 266 |
$_count = count( $inactive_plugins ); |
| 267 |
for ( $i = 0; $i < $_count; $i++ ) { |
| 268 |
$slug = $inactive_plugins[ $i ]['slug']; |
| 269 |
$plugin_directory = dirname( $slug ); |
| 270 |
$plugin_name = $inactive_plugins[ $i ]['name']; |
| 271 |
$plugin_title = $plugin_name . ' ' . $inactive_plugins[ $i ]['version']; |
| 272 |
?> |
| 273 |
<div class="item <?php echo esc_html( sanitize_text_field( dirname( $slug ) ) ); ?> row-manage-item" plugin-title="<?php echo esc_attr( $plugin_title ); ?>" plugin-name="<?php echo esc_attr( $plugin_name ); ?>" plugin-slug="<?php echo esc_attr( $slug ); ?>"> |
| 274 |
<input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_plugins[ $i ]['slug'] ) ); ?>"/> |
| 275 |
<input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> |
| 276 |
<div class="right floated content pluginsAction"> |
| 277 |
<div class="ui right pointing dropdown"> |
| 278 |
<i class="ellipsis vertical icon"></i> |
| 279 |
<div class="menu"> |
| 280 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> |
| 281 |
<a href="#" class="mainwp-plugin-activate item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Activate', 'mainwp' );// phpcs:ignore WordPress.Security.EscapeOutput ?></a> |
| 282 |
<?php } ?> |
| 283 |
<?php if ( \mainwp_current_user_can( 'dashboard', 'delete_plugins' ) ) { ?> |
| 284 |
<a href="#" class="mainwp-plugin-delete item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Delete', 'mainwp' ); // phpcs:ignore WordPress.Security.EscapeOutput ?></a> |
| 285 |
<?php } ?> |
| 286 |
<a href="#" history-view="widget-plugins" class="mainwp-show-history item <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'History', 'mainwp' ); ?></a> |
| 287 |
</div> |
| 288 |
</div> |
| 289 |
</div> |
| 290 |
<div class="middle aligned content"> |
| 291 |
<?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); // phpcs:ignore WordPress.Security.EscapeOutput ?> |
| 292 |
<a href="<?php echo esc_url( admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( dirname( $inactive_plugins[ $i ]['slug'] ) ) ); ?>" target="_blank" class="open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"> |
| 293 |
<?php echo esc_html( $plugin_title ); ?> |
| 294 |
</a> |
| 295 |
</div> |
| 296 |
<div class="mainwp-row-actions-working"> |
| 297 |
<i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> |
| 298 |
</div> |
| 299 |
</div> |
| 300 |
<?php } ?> |
| 301 |
</div> |
| 302 |
<?php |
| 303 |
/** |
| 304 |
* Action: mainwp_after_inactive_plugins_list |
| 305 |
* |
| 306 |
* Fires after the inactive plugins list in the Plugins widget on the Individual site overview page. |
| 307 |
* |
| 308 |
* @param object $website Object containing the child site info. |
| 309 |
* @param array $inactive_plugins Array containing all active plugins data. |
| 310 |
* |
| 311 |
* @since 4.1 |
| 312 |
*/ |
| 313 |
do_action( 'mainwp_after_inactive_plugins_list', $website, $inactive_plugins ); |
| 314 |
?> |
| 315 |
</div> |
| 316 |
</div> |
| 317 |
<div class="ui two column grid mainwp-widget-footer"> |
| 318 |
<div class="left aligned middle aligned column"></div> |
| 319 |
<div class="right aligned middle aligned column"> |
| 320 |
<a href="admin.php?page=PluginsManage" class="ui mini basic button"><?php esc_html_e( 'Manage Plugins', 'mainwp' ); ?></a> |
| 321 |
</div> |
| 322 |
</div> |
| 323 |
<?php |
| 324 |
/** |
| 325 |
* Action: mainwp_plugins_widget_bottom |
| 326 |
* |
| 327 |
* Fires at the bottom of the Plugins widget on the Individual site overview page. |
| 328 |
* |
| 329 |
* @param object $website Object containing the child site info. |
| 330 |
* @param array $allPlugins Array containing all detected plugins data. |
| 331 |
* |
| 332 |
* @since 4.1 |
| 333 |
*/ |
| 334 |
do_action( 'mainwp_plugins_widget_bottom', $website, $allPlugins ); |
| 335 |
MainWP_Updates::render_plugin_details_modal(); |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Method activate_plugin() |
| 340 |
* |
| 341 |
* Fire off Action activate & display result |
| 342 |
*/ |
| 343 |
public static function activate_plugin() { |
| 344 |
static::action( 'activate' ); |
| 345 |
die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been activated!', 'mainwp' ) ) ) ); |
| 346 |
} |
| 347 |
|
| 348 |
/** |
| 349 |
* Method deactivate_plugin() |
| 350 |
* |
| 351 |
* Fire off action deactivate & display result |
| 352 |
*/ |
| 353 |
public static function deactivate_plugin() { |
| 354 |
static::action( 'deactivate' ); |
| 355 |
die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been deactivated!', 'mainwp' ) ) ) ); |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* Method delete_plugin() |
| 360 |
* |
| 361 |
* Fire off action delete & display result |
| 362 |
*/ |
| 363 |
public static function delete_plugin() { |
| 364 |
static::action( 'delete' ); |
| 365 |
die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been permanently deleted!', 'mainwp' ) ) ) ); |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Method action() |
| 370 |
* |
| 371 |
* Initiate try catch for chosen Action |
| 372 |
* |
| 373 |
* @param mixed $action Plugin Action. |
| 374 |
* |
| 375 |
* @throws \MainWP_Exception Error message. |
| 376 |
* |
| 377 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 378 |
* @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() |
| 379 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 380 |
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() |
| 381 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 382 |
*/ |
| 383 |
public static function action( $action ) { |
| 384 |
$plugin = isset( $_POST['plugin'] ) ? wp_unslash( $_POST['plugin'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 385 |
$plugin = urldecode( $plugin ); |
| 386 |
$websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 387 |
|
| 388 |
if ( empty( $plugin ) || empty( $websiteId ) ) { |
| 389 |
die( wp_json_encode( array( 'error' => esc_html__( 'Plugin or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) ); |
| 390 |
} |
| 391 |
|
| 392 |
$website = MainWP_DB::instance()->get_website_by_id( $websiteId ); |
| 393 |
if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { |
| 394 |
die( wp_json_encode( array( 'error' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ); |
| 395 |
} |
| 396 |
|
| 397 |
if ( MainWP_System_Utility::is_suspended_site( $website ) ) { |
| 398 |
die( |
| 399 |
wp_json_encode( |
| 400 |
array( |
| 401 |
'error' => esc_html__( 'Suspended site.', 'mainwp' ), |
| 402 |
'errorCode' => 'SUSPENDED_SITE', |
| 403 |
) |
| 404 |
) |
| 405 |
); |
| 406 |
} |
| 407 |
|
| 408 |
try { |
| 409 |
|
| 410 |
/** |
| 411 |
* Action: mainwp_before_plugin_action |
| 412 |
* |
| 413 |
* Fires before plugin activate/deactivate/delete actions. |
| 414 |
* |
| 415 |
* @since 4.1 |
| 416 |
*/ |
| 417 |
do_action( 'mainwp_before_plugin_action', $action, $plugin, $website ); |
| 418 |
|
| 419 |
$information = MainWP_Connect::fetch_url_authed( |
| 420 |
$website, |
| 421 |
'plugin_action', |
| 422 |
array( |
| 423 |
'action' => $action, |
| 424 |
'plugin' => $plugin, |
| 425 |
) |
| 426 |
); |
| 427 |
|
| 428 |
/** |
| 429 |
* Action: mainwp_after_plugin_action |
| 430 |
* |
| 431 |
* Fires after plugin activate/deactivate/delete actions. |
| 432 |
* |
| 433 |
* @since 4.1 |
| 434 |
*/ |
| 435 |
do_action( 'mainwp_after_plugin_action', $information, $action, $plugin, $website ); |
| 436 |
|
| 437 |
} catch ( MainWP_Exception $e ) { |
| 438 |
die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e, true ) ) ) ); // escaped. |
| 439 |
} |
| 440 |
|
| 441 |
if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) { |
| 442 |
die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) ); |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
|