PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.2.1 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 All 155 releases
← All changes | class/class-mainwp-actions-handler.php +125 -109 5.0 → 6.2.1 View file →
@@ -6,127 +6,143 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Actions_Handler
12 17 */
13 -class MainWP_Actions_Handler {
18 +class MainWP_Actions_Handler { //phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
14 19
15 - /**
16 - * Private static variable to hold the single instance of the class.
17 - *
18 - * @static
19 - *
20 - * @var mixed Default null
21 - */
22 - private static $instance = null;
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;
23 28
24 - /**
25 - * Method instance()
26 - *
27 - * Create a public static instance.
28 - *
29 - * @static
30 - * @return MainWP_Actions_Handler
31 - */
32 - public static function instance() {
33 - if ( null === self::$instance ) {
34 - self::$instance = new self();
35 - }
36 - return self::$instance;
37 - }
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 + }
38 43
39 - /**
40 - * Action mainwp_post_action.
41 - *
42 - * @param object $website website data.
43 - * @param string $pAction post action.
44 - * @param array $information post action information.
45 - * @param int|false $postId post id.
46 - * @param string $type post|page.
47 - */
48 - public function do_action_mainwp_post_action( $website, $pAction, $information, $postId, $type = '' ) {
49 - if ( is_array( $information ) && isset( $information['status'] ) && ( 'SUCCESS' === $information['status'] ) ) {
50 - $data = isset( $information['other_data']['post_action_data'] ) ? $information['other_data']['post_action_data'] : array();
51 - /**
52 - * Fires immediately after post action.
53 - *
54 - * @since 4.5.1.1
55 - */
56 - do_action( 'mainwp_post_action', $website, $pAction, $data, $postId, $type );
57 - }
58 - }
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 + }
59 64
60 - /**
61 - * Action mainwp_install_actions.
62 - *
63 - * @param array $websites websites.
64 - * @param string $pAction install action.
65 - * @param mixed $output result.
66 - * @param string $type action type.
67 - * @param mixed $post_data post data (option).
68 - * @param bool $upload true|false: install by upload (option).
69 - */
70 - public function do_action_mainwp_install_actions( $websites, $pAction, $output, $type, $post_data = array(), $upload = false ) {
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 ) {
71 77
72 - if ( ! in_array( $pAction, array( 'install', 'updated' ), true ) ) {
73 - return false;
74 - }
78 + if ( ! in_array( $pAction, array( 'install', 'updated' ), true ) ) {
79 + return;
80 + }
75 81
76 - $website = is_array( $websites ) ? current( $websites ) : $websites;
77 - if ( empty( $website ) ) {
78 - return;
79 - }
82 + $website = is_array( $websites ) ? current( $websites ) : $websites;
83 + if ( empty( $website ) ) {
84 + return;
85 + }
80 86
81 - if ( ! is_array( $post_data ) ) {
82 - $post_data = array();
83 - }
87 + if ( ! is_array( $post_data ) ) {
88 + $post_data = array();
89 + }
84 90
85 - $data = array();
86 - if ( is_array( $output ) ) {
87 - $data = $output;
88 - } elseif ( is_object( $output ) ) {
89 - if ( ! empty( $output->other_data ) && is_array( $output->other_data ) ) {
90 - if ( isset( $output->other_data[ $website->id ]['install_items'] ) ) {
91 - $data['install_items'] = $output->other_data[ $website->id ]['install_items'];
92 - }
93 - }
94 - }
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 + }
95 99
96 - /**
97 - * Fires immediately after install action.
98 - *
99 - * @since 4.5.1.1
100 - */
101 - do_action( 'mainwp_install_update_actions', $website, $pAction, $data, $type, $post_data, $upload );
102 - }
100 + if ( 'updated' === $pAction && $is_auto_update ) {
101 + MainWP_Updates_Report_Manager::save_update_info( $website, $data, $type );
102 + }
103 103
104 - /**
105 - *
106 - * Handle @action mainwp_fetch_url_authed.
107 - *
108 - * @param object $website website.
109 - * @param array $information information result data.
110 - * @param string $action action.
111 - * @param array $params params input array.
112 - * @param array $others others input array.
113 - *
114 - * @since 4.5.1.1
115 - */
116 - public function hook_mainwp_fetch_url_authed( $website, $information, $action, $params, $others ) {
117 - if ( 'plugin_action' === $action ) {
118 - $plugin_act = isset( $params['action'] ) ? $params['action'] : '';
119 - if ( in_array( $plugin_act, array( 'activate', 'deactivate', 'delete' ) ) && isset( $information['other_data']['plugin_action_data'] ) ) {
120 - do_action( 'mainwp_install_plugin_action', $website, $plugin_act, $params, $information['other_data']['plugin_action_data'], $others );
121 - }
122 - } elseif ( 'theme_action' === $action ) {
123 - $theme_act = isset( $params['action'] ) ? $params['action'] : '';
124 - if ( 'activate' === $theme_act && isset( $information['other_data']['theme_deactivate_data'] ) ) {
125 - do_action( 'mainwp_install_theme_action', $website, 'deactivate', $params, $information['other_data']['theme_deactivate_data'], $others );
126 - }
127 - if ( in_array( $theme_act, array( 'activate', 'delete' ) ) && isset( $information['other_data']['theme_action_data'] ) ) {
128 - do_action( 'mainwp_install_theme_action', $website, $theme_act, $params, $information['other_data']['theme_action_data'], $others );
129 - }
130 - }
131 - }
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 + }
132 148 }