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

133 lines 4.0 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 /**
11 * Class MainWP_Actions_Handler
12 */
13 class MainWP_Actions_Handler {
14
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;
23
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 }
38
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 }
59
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 ) {
71
72 if ( ! in_array( $pAction, array( 'install', 'updated' ), true ) ) {
73 return false;
74 }
75
76 $website = is_array( $websites ) ? current( $websites ) : $websites;
77 if ( empty( $website ) ) {
78 return;
79 }
80
81 if ( ! is_array( $post_data ) ) {
82 $post_data = array();
83 }
84
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 }
95
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 }
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 }
132 }
133