PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1.6
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1.6
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 6.1.6, at class/class-mainwp-actions-handler.php

144 lines 5.2 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 */
75 public function do_action_mainwp_install_actions( $websites, $pAction, $output, $type, $post_data = array(), $upload = false ) {
76
77 if ( ! in_array( $pAction, array( 'install', 'updated' ), true ) ) {
78 return;
79 }
80
81 $website = is_array( $websites ) ? current( $websites ) : $websites;
82 if ( empty( $website ) ) {
83 return;
84 }
85
86 if ( ! is_array( $post_data ) ) {
87 $post_data = array();
88 }
89
90 $data = array();
91 if ( is_array( $output ) ) {
92 $data = $output;
93 } elseif ( is_object( $output ) ) {
94 if ( ! empty( $output->other_data ) && is_array( $output->other_data ) && isset( $output->other_data[ $website->id ]['install_items'] ) ) {
95 $data['install_items'] = $output->other_data[ $website->id ]['install_items'];
96 }
97 }
98
99 /**
100 * Fires immediately after install action.
101 *
102 * @since 4.5.1.1
103 */
104 do_action( 'mainwp_install_update_actions', $website, $pAction, $data, $type, $post_data, $upload );
105 }
106
107 /**
108 *
109 * Handle @action mainwp_fetch_url_authed.
110 *
111 * @param object $website website.
112 * @param array $information information result data.
113 * @param string $action action.
114 * @param array $params params input array.
115 * @param array $others others input array.
116 *
117 * @since 4.5.1.1
118 */
119 public function hook_mainwp_fetch_url_authed( $website, $information, $action, $params, $others ) { // phpcs:ignore -- NOSONAR -complex method.
120 if ( 'plugin_action' === $action ) {
121 $plugin_act = isset( $params['action'] ) ? $params['action'] : '';
122
123 if ( 'delete' === $plugin_act && ! empty( $information['other_data']['duration_bulk'] ) ) {
124 $params['duration_bulk'] = $information['other_data']['duration_bulk'];
125 }
126
127 if ( 'delete' === $plugin_act && ! empty( $information['other_data']['plugin_deactivated_data'] ) ) {
128 do_action( 'mainwp_install_plugin_action', $website, 'deactivate', $params, $information['other_data']['plugin_deactivated_data'], $others );
129 }
130 if ( in_array( $plugin_act, array( 'activate', 'deactivate', 'delete' ) ) && isset( $information['other_data']['plugin_action_data'] ) ) {
131 do_action( 'mainwp_install_plugin_action', $website, $plugin_act, $params, $information['other_data']['plugin_action_data'], $others );
132 }
133 } elseif ( 'theme_action' === $action ) {
134 $theme_act = isset( $params['action'] ) ? $params['action'] : '';
135 if ( 'activate' === $theme_act && isset( $information['other_data']['theme_deactivate_data'] ) ) {
136 do_action( 'mainwp_install_theme_action', $website, 'deactivate', $params, $information['other_data']['theme_deactivate_data'], $others );
137 }
138 if ( in_array( $theme_act, array( 'activate', 'delete' ) ) && isset( $information['other_data']['theme_action_data'] ) ) {
139 do_action( 'mainwp_install_theme_action', $website, $theme_act, $params, $information['other_data']['theme_action_data'], $others );
140 }
141 }
142 }
143 }
144