PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
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
mainwp / modules / logs / connectors / class-connector-site.php

class-connector-site.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at modules/logs/connectors/class-connector-site.php

372 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module Logs Site connector class.
4 *
5 * @package MainWP\Dashboard
6 * @version 4.5.1
7 */
8
9 namespace MainWP\Dashboard\Module\Log;
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Class Connector_Site
15 */
16 class Connector_Site extends Log_Connector {
17
18 /**
19 * Connector name.
20 *
21 * @var string Connector slug.
22 */
23 public $name = 'site';
24
25 /**
26 * Connector name.
27 *
28 * @var array Actions registered for this connector.
29 **/
30 public $actions = array(
31 'mainwp_site_added', // site::added.
32 'mainwp_site_updated', // site::updated.
33 'mainwp_site_sync', // site::synced.
34 'mainwp_site_deleted', // site::deleted.
35 'mainwp_site_reconnected', // site::reconnected.
36 'mainwp_site_suspended', // site::updated suspended value.
37 'mainwp_site_tag_action',
38 'mainwp_site_go_to_wpadmin',
39 );
40
41 /**
42 * Return translated connector label.
43 *
44 * @return string Translated connector label.
45 */
46 public function get_label() {
47 return esc_html__( 'Sites', 'mainwp' );
48 }
49
50 /**
51 * Return translated action labels.
52 *
53 * @return array Action label translations.
54 */
55 public function get_action_labels() {
56 return array(
57 'added' => esc_html__( 'Added', 'mainwp' ),
58 'updated' => esc_html__( 'Updated', 'mainwp' ),
59 'sync' => esc_html__( 'Sync Data', 'mainwp' ),
60 'deleted' => esc_html__( 'Deleted', 'mainwp' ),
61 'suspend' => esc_html__( 'Suspend', 'mainwp' ),
62 'unsuspend' => esc_html__( 'Unsuspend', 'mainwp' ),
63 'reconnect' => esc_html__( 'Reconnected', 'mainwp' ),
64 'opensite' => esc_html__( 'Go to WP Admin', 'mainwp' ),
65 );
66 }
67
68 /**
69 * Return translated context labels.
70 *
71 * @return array Context label translations.
72 */
73 public function get_context_labels() {
74 return array(
75 'sites' => esc_html__( 'Sites', 'mainwp' ),
76 );
77 }
78
79 /**
80 * Log site added process.
81 *
82 * @action transition_post_status.
83 *
84 * @param object $website Website object data.
85 *
86 * @return bool Return TRUE.
87 */
88 public function callback_mainwp_site_added( $website ) {
89 if ( empty( $website ) || ! is_object( $website ) || empty( $website->id ) ) {
90 return false;
91 }
92 $state = 1;
93 $this->log(
94 '%1$s',
95 array(
96 'item' => esc_html__( 'Added', 'mainwp' ),
97 ),
98 $website->id,
99 'sites',
100 'added',
101 $state
102 );
103 return true;
104 }
105
106 /**
107 * Log site sync process.
108 *
109 * @param object $website Website object data.
110 * @param array $information Sync array data.
111 * @param bool $success Sync success or failed.
112 * @param string $sync_error Sync error data (options).
113 *
114 * @return bool Return TRUE.
115 */
116 public function callback_mainwp_site_sync( $website, $information, $success, $sync_error = '' ) {
117 unset( $information );
118 if ( empty( $website ) ) {
119 return false;
120 }
121
122 $action = 'sync';
123 $state = null;
124 if ( $success ) {
125 $message = '%1$s';
126 $state = 1;
127 } else {
128 $message = '%1$s';
129 $state = 0;
130 }
131
132 $args = array(
133 'item' => esc_html__( 'Sync Data', 'mainwp' ),
134 );
135
136 if ( ! empty( $sync_error ) ) {
137 $info = array(
138 'sync_error' => $sync_error,
139 );
140 $args['extra_info'] = wp_json_encode( $info );
141 }
142
143 $this->log(
144 $message,
145 $args,
146 $website->id,
147 'sites',
148 $action,
149 $state
150 );
151
152 return true;
153 }
154
155
156 /**
157 * Log site sync process.
158 *
159 * @action transition_post_status.
160 *
161 * @param object $website Website object data.
162 *
163 * @return bool Return TRUE.
164 */
165 public function callback_mainwp_site_deleted( $website ) {
166 $state = 1;
167 $this->log(
168 '%1$s',
169 array(
170 'item' => esc_html__( 'Deleted', 'mainwp' ),
171 ),
172 $website->id,
173 'sites',
174 'deleted',
175 $state
176 );
177 return true;
178 }
179
180 /**
181 * Log site sync process.
182 *
183 * @action transition_post_status.
184 *
185 * @param object $website Website object data.
186 * @param bool $success success or not.
187 * @param string $error reconnect error.
188 *
189 * @return bool Return TRUE.
190 */
191 public function callback_mainwp_site_reconnected( $website, $success = true, $error = '' ) {
192 $message = '%1$s';
193
194 $args = array(
195 'item' => esc_html__( 'Reconnect', 'mainwp' ),
196 );
197
198 if ( ! empty( $error ) ) {
199 $other = array(
200 'error' => $error,
201 );
202 $args['extra_info'] = wp_json_encode( $other );
203 }
204
205 $state = $success ? 1 : 0;
206 $this->log(
207 $message,
208 $args,
209 $website->id,
210 'sites',
211 'reconnect',
212 $state
213 );
214 return true;
215 }
216
217
218 /**
219 * Log site updated process.
220 *
221 * @action transition_post_status.
222 *
223 * @param object $website Website object data.
224 *
225 * @return bool Return TRUE.
226 */
227 public function callback_mainwp_site_updated( $website ) {
228 $state = 1;
229 $this->log(
230 '%1$s',
231 array(
232 'item' => esc_html__( 'Updated', 'mainwp' ),
233 ),
234 $website->id,
235 'sites',
236 'updated',
237 $state
238 );
239 return true;
240 }
241
242 /**
243 * Log site updated suspended process.
244 *
245 * @action mainwp_site_suspended.
246 *
247 * @param object $website Website object data.
248 * @param int $suspended suspended value.
249 *
250 * @return bool Return TRUE.
251 */
252 public function callback_mainwp_site_suspended( $website, $suspended ) {
253
254 $action = $suspended ? 'suspend' : 'unsuspend';
255
256 if ( $suspended ) {
257 $message = '%1$s';
258 $args = array(
259 'item' => esc_html__( 'Suspend', 'mainwp' ),
260 );
261 } else {
262 $message = '%1$s';
263 $args = array(
264 'item' => esc_html__( 'Unsuspend', 'mainwp' ),
265 );
266 }
267
268 $args['siteurl'] = $website->url;
269 $args['site_name'] = $website->name;
270
271 $state = 1;
272 $this->log(
273 $message,
274 $args,
275 $website->id,
276 'sites',
277 $action,
278 $state
279 );
280 return true;
281 }
282
283
284 /**
285 * Log Tag actions.
286 *
287 * @action mainwp_site_tag_action.
288 *
289 * @param object $tag tag object data.
290 * @param string $action tag action.
291 * @param array $data other data array (option).
292 *
293 * @return bool Return TRUE.
294 */
295 public function callback_mainwp_site_tag_action( $tag, $action, $data = array() ) {
296
297 if ( empty( $tag ) || ! is_string( $action ) || ! in_array( $action, array( 'created', 'updated', 'deleted' ), true ) ) {
298 return false;
299 }
300
301 $args = array(
302 'name' => $tag->name,
303 );
304
305 if ( 'created' === $action || 'deleted' === $action ) {
306 $message = '%1$s';
307 } elseif ( 'updated' === $action ) {
308 $message = '%1$s';
309 $args = array(
310 'name' => $tag->name,
311 'old_name' => is_array( $data ) && isset( $data['old_name'] ) ? $data['old_name'] : '',
312 );
313 } else {
314 return fase;
315 }
316
317 $state = 1;
318
319 $this->log(
320 $message,
321 $args,
322 0,
323 'tags',
324 $action,
325 $state
326 );
327 return true;
328 }
329
330 /**
331 * Go to wp admin actions.
332 *
333 * @param mixed $website The site.
334 * @param mixed $location Location.
335 * @param mixed $params Other params.
336 *
337 * @return void.
338 */
339 public function callback_mainwp_site_go_to_wpadmin( $website, $location, $params = array() ) { //phpcs:ignore -- NOSONAR - unuse $location.
340
341 if ( empty( $website ) || ! is_object( $website ) || empty( $website->id ) ) {
342 return;
343 }
344
345 $user = wp_get_current_user();
346
347 if ( empty( $user ) ) {
348 return;
349 }
350
351 if ( ! is_array( $params ) ) {
352 $params = array();
353 }
354
355 $message = '%1$s';
356
357 $args = array(
358 'item' => esc_html__( 'Go to WP Admin', 'mainwp' ),
359 );
360
361 $action = 'opensite';
362
363 $this->log(
364 $message,
365 $args,
366 $website->id,
367 'sites',
368 $action
369 );
370 }
371 }
372