PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-actions-handler.php

class-mainwp-actions-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies trunk, at class/class-mainwp-actions-handler.php

149 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle Dashboard Hooks Actions.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Actions_Handler
17 */
18 class MainWP_Actions_Handler { //phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
19
20 /**
21 * Private static variable to hold the single instance of the class.
22 *
23 * @static
24 *
25 * @var mixed Default null
26 */
27 private static $instance = null;
28
29 /**
30 * Method instance()
31 *
32 * Create a public static instance.
33 *
34 * @static
35 * @return MainWP_Actions_Handler
36 */
37 public static function instance() {
38 if ( null === static::$instance ) {
39 static::$instance = new self();
40 }
41 return static::$instance;
42 }
43
44 /**
45 * Action mainwp_post_action.
46 *
47 * @param object $website website data.
48 * @param string $pAction post action.
49 * @param array $information post action information.
50 * @param int|false $postId post id.
51 * @param string $type post|page.
52 */
53 public function do_action_mainwp_post_action( $website, $pAction, $information, $postId, $type = '' ) {
54 if ( is_array( $information ) && isset( $information['status'] ) && ( 'SUCCESS' === $information['status'] ) ) {
55 $data = isset( $information['other_data']['post_action_data'] ) ? $information['other_data']['post_action_data'] : array();
56 /**
57 * Fires immediately after post action.
58 *
59 * @since 4.5.1.1
60 */
61 do_action( 'mainwp_post_action', $website, $pAction, $data, $postId, $type );
62 }
63 }
64
65 /**
66 * Action mainwp_install_actions.
67 *
68 * @param array $websites websites.
69 * @param string $pAction install action.
70 * @param mixed $output result.
71 * @param string $type action type.
72 * @param mixed $post_data post data (option).
73 * @param bool $upload true|false: install by upload (option).
74 * @param bool $is_auto_update true|false: is auto update (option).
75 */
76 public function do_action_mainwp_install_actions( $websites, $pAction, $output, $type, $post_data = array(), $upload = false, $is_auto_update = false ) {
77
78 if ( ! in_array( $pAction, array( 'install', 'updated' ), true ) ) {
79 return;
80 }
81
82 $website = is_array( $websites ) ? current( $websites ) : $websites;
83 if ( empty( $website ) ) {
84 return;
85 }
86
87 if ( ! is_array( $post_data ) ) {
88 $post_data = array();
89 }
90
91 $data = array();
92 if ( is_array( $output ) ) {
93 $data = $output;
94 } elseif ( is_object( $output ) ) {
95 if ( ! empty( $output->other_data ) && is_array( $output->other_data ) && isset( $output->other_data[ $website->id ]['install_items'] ) ) {
96 $data['install_items'] = $output->other_data[ $website->id ]['install_items'];
97 }
98 }
99
100 if ( 'updated' === $pAction && $is_auto_update ) {
101 MainWP_Updates_Report_Manager::save_update_info( $website, $data, $type );
102 }
103
104 /**
105 * Fires immediately after install action.
106 *
107 * @since 4.5.1.1
108 */
109 do_action( 'mainwp_install_update_actions', $website, $pAction, $data, $type, $post_data, $upload, $is_auto_update );
110 }
111
112 /**
113 *
114 * Handle @action mainwp_fetch_url_authed.
115 *
116 * @param object $website website.
117 * @param array $information information result data.
118 * @param string $action action.
119 * @param array $params params input array.
120 * @param array $others others input array.
121 *
122 * @since 4.5.1.1
123 */
124 public function hook_mainwp_fetch_url_authed( $website, $information, $action, $params, $others ) { // phpcs:ignore -- NOSONAR -complex method.
125 if ( 'plugin_action' === $action ) {
126 $plugin_act = isset( $params['action'] ) ? $params['action'] : '';
127
128 if ( 'delete' === $plugin_act && ! empty( $information['other_data']['duration_bulk'] ) ) {
129 $params['duration_bulk'] = $information['other_data']['duration_bulk'];
130 }
131
132 if ( 'delete' === $plugin_act && ! empty( $information['other_data']['plugin_deactivated_data'] ) ) {
133 do_action( 'mainwp_install_plugin_action', $website, 'deactivate', $params, $information['other_data']['plugin_deactivated_data'], $others );
134 }
135 if ( in_array( $plugin_act, array( 'activate', 'deactivate', 'delete' ) ) && isset( $information['other_data']['plugin_action_data'] ) ) {
136 do_action( 'mainwp_install_plugin_action', $website, $plugin_act, $params, $information['other_data']['plugin_action_data'], $others );
137 }
138 } elseif ( 'theme_action' === $action ) {
139 $theme_act = isset( $params['action'] ) ? $params['action'] : '';
140 if ( 'activate' === $theme_act && isset( $information['other_data']['theme_deactivate_data'] ) ) {
141 do_action( 'mainwp_install_theme_action', $website, 'deactivate', $params, $information['other_data']['theme_deactivate_data'], $others );
142 }
143 if ( in_array( $theme_act, array( 'activate', 'delete' ) ) && isset( $information['other_data']['theme_action_data'] ) ) {
144 do_action( 'mainwp_install_theme_action', $website, $theme_act, $params, $information['other_data']['theme_action_data'], $others );
145 }
146 }
147 }
148 }
149