PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.2.2
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 / pages / page-mainwp-updates-handler.php

page-mainwp-updates-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.2, at pages/page-mainwp-updates-handler.php

1,284 lines 58.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Updates Handler.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Updates_Handler
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Updates_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16
17 /**
18 * Get Class Name
19 *
20 * @return string __CLASS__
21 */
22 public static function get_class_name() {
23 return __CLASS__;
24 }
25
26 /**
27 * Method upgrade_site()
28 *
29 * Check Child Site ID & Update.
30 *
31 * @param int $id Child site ID.
32 *
33 * @return string
34 * @throws MainWP_Exception Error messages.
35 *
36 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
37 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
38 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
39 * @uses \MainWP\Dashboard\MainWP_Exception
40 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
41 */
42 public static function upgrade_site( $id ) { // phpcs:ignore -- NOSONAR - complex.
43 if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) {
44
45 $website = MainWP_DB::instance()->get_website_by_id( $id );
46
47 if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
48 throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
49 }
50
51 $information = static::upgrade_website( $website );
52
53 if ( is_array( $information ) ) {
54 if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) {
55 MainWP_DB::instance()->update_website_option( $website, 'wp_upgrades', wp_json_encode( array() ) );
56 do_action( 'mainwp_after_upgrade_wp_success', $website, $information );
57 return '<i class="green check icon"></i>';
58 } elseif ( isset( $information['upgrade'] ) ) {
59 $errorMsg = '';
60 if ( 'LOCALIZATION' === $information['upgrade'] ) {
61 $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No update found for the set locale.', 'mainwp' );
62 } elseif ( 'NORESPONSE' === $information['upgrade'] ) {
63 $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No response from the child site server.', 'mainwp' );
64 }
65 throw new MainWP_Exception( 'WPERROR', $errorMsg ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
66 } elseif ( isset( $information['error'] ) ) {
67 throw new MainWP_Exception( 'WPERROR', esc_html( $information['error'] ) );
68 } else {
69 throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ) );
70 }
71 }
72 }
73
74 throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) );
75 }
76
77 /**
78 * Method upgrade_website()
79 *
80 * Update WP for site.
81 *
82 * @param object $website Child site object.
83 *
84 * @return mixed|false update result or false.
85 * @throws MainWP_Exception Error message.
86 *
87 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
88 */
89 public static function upgrade_website( $website ) { // phpcs:ignore -- NOSONAR - complex.
90 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
91
92 $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $website );
93 if ( ! empty( $wpcore_update_disabled_by ) ) {
94 throw new MainWP_Exception( 'ERROR', $wpcore_update_disabled_by ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
95 }
96 /**
97 * Action: mainwp_before_wp_update
98 *
99 * Fires before WP update.
100 *
101 * @since 4.1
102 */
103 do_action( 'mainwp_before_wp_update', $website );
104
105 $information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' );
106
107 // logging feature.
108 $error = '';
109 $success = false;
110
111 if ( is_array( $information ) ) {
112 if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) {
113 $success = true;
114 } elseif ( isset( $information['upgrade'] ) ) {
115 if ( 'LOCALIZATION' === $information['upgrade'] ) {
116 $error = esc_html__( 'No update found for the set locale.', 'mainwp' );
117 } elseif ( 'NORESPONSE' === $information['upgrade'] ) {
118 $error = esc_html__( 'No response from the child site server.', 'mainwp' );
119 }
120 } elseif ( isset( $information['error'] ) ) {
121 $error = esc_html( $information['error'] );
122 } else {
123 $error = esc_html__( 'Invalid response from child site.', 'mainwp' );
124 }
125 }
126
127 $output_array = array(
128 'old_version' => isset( $information['old_version'] ) ? $information['old_version'] : '',
129 'version' => isset( $information['version'] ) ? $information['version'] : '',
130 'success' => $success ? 1 : 0,
131 'error' => $error,
132 );
133 mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' );
134
135 /**
136 * Action: mainwp_after_wp_update
137 *
138 * Fires after WP update.
139 *
140 * @since 4.1
141 */
142 do_action( 'mainwp_after_wp_update', $information, $website );
143
144 return $information;
145 }
146 return false;
147 }
148
149 /**
150 * Add a plugin or theme to the ignor list.
151 *
152 * @param mixed $type plugin|theme.
153 * @param mixed $slug Plugin or Theme Slug.
154 * @param mixed $name Plugin or Theme Name.
155 * @param mixed $id Child Site ID.
156 * @param string $ver version ignore.
157 *
158 * @return string success.
159 *
160 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
161 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
162 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
163 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
164 */
165 public static function ignore_plugin_theme( $type, $slug, $name, $id, $ver = '' ) { // phpcs:ignore -- NOSONAR - complex.
166 if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) {
167 $website = MainWP_DB::instance()->get_website_by_id( $id );
168 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
169 $slug = urldecode( $slug );
170 if ( 'plugin' === $type ) {
171 $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
172 /**
173 * Action: mainwp_before_plugin_ignore
174 *
175 * Fires before plugin ignore.
176 *
177 * @since 4.1
178 */
179 do_action( 'mainwp_before_plugin_ignore', $decodedIgnoredPlugins, $website );
180
181 $ignored_info = is_array( $decodedIgnoredPlugins ) && isset( $decodedIgnoredPlugins[ $slug ] ) ? $decodedIgnoredPlugins[ $slug ] : array();
182 if ( ! is_array( $ignored_info ) ) {
183 $ignored_info = array();
184 }
185
186 $ignored_info['Name'] = urldecode( $name );
187
188 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
189 if ( ! is_array( $ignored_vers ) ) {
190 $ignored_vers = array();
191 }
192 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
193 $ignored_vers = array( 'all_versions' );
194 } else {
195 $ver = urldecode( $ver );
196 if ( ! in_array( $ver, $ignored_vers ) ) {
197 $ignored_vers[] = $ver;
198 }
199 }
200 $ignored_info['ignored_versions'] = $ignored_vers;
201
202 $decodedIgnoredPlugins[ $slug ] = $ignored_info;
203
204 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) );
205
206 /**
207 * Action: mainwp_after_plugin_ignore
208 *
209 * Fires after plugin ignore.
210 *
211 * @since 4.1
212 */
213 do_action( 'mainwp_after_plugin_ignore', $decodedIgnoredPlugins, $website );
214
215 } elseif ( 'theme' === $type ) {
216 $decodedIgnoredThemes = json_decode( $website->ignored_themes, true );
217
218 /**
219 * Action: mainwp_before_theme_ignore
220 *
221 * Fires before theme ignore.
222 *
223 * @since 4.1
224 */
225 do_action( 'mainwp_before_theme_ignore', $decodedIgnoredThemes, $website );
226
227 $ignored_info = is_array( $decodedIgnoredThemes ) && isset( $decodedIgnoredThemes[ $slug ] ) ? $decodedIgnoredThemes[ $slug ] : array();
228 if ( ! is_array( $ignored_info ) ) {
229 $ignored_info = array();
230 }
231 $ignored_info['Name'] = urldecode( $name );
232
233 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
234 if ( ! is_array( $ignored_vers ) ) {
235 $ignored_vers = array();
236 }
237 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
238 $ignored_vers = array( 'all_versions' );
239 } else {
240 $ver = urldecode( $ver );
241 if ( ! in_array( $ver, $ignored_vers ) ) {
242 $ignored_vers[] = $ver;
243 }
244 }
245 $ignored_info['ignored_versions'] = $ignored_vers;
246
247 $decodedIgnoredThemes[ $slug ] = $ignored_info;
248 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) );
249 /**
250 * Action: mainwp_after_theme_ignore
251 *
252 * Fires after theme ignore.
253 *
254 * @since 4.1
255 */
256 do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes );
257 }
258 }
259 }
260 return 'success';
261 }
262
263
264 /**
265 * Remove a plugin or theme from the ignore list.
266 *
267 * @param mixed $type plugin|theme.
268 * @param mixed $slug Plugin or Theme slug.
269 * @param mixed $id Plugin or Theme name.
270 * @param string $ver Plugin or Theme version.
271 *
272 * @return string success.
273 *
274 * @uses \MainWP\Dashboard\MainWP_DB::query()
275 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
276 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
277 * @uses \MainWP\Dashboard\MainWP_DB::update_website_values()
278 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
279 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
280 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
281 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
282 */
283 public static function unignore_plugin_theme( $type, $slug, $id, $ver ) { // phpcs:ignore -- NOSONAR - complex.
284 if ( ! empty( $id ) ) {
285
286 /**
287 * Action: mainwp_before_plugin_theme_unignore
288 *
289 * Fires after plugin/theme unignore.
290 *
291 * @since 4.1
292 */
293 do_action( 'mainwp_before_plugin_theme_unignore', $type, $slug, $id );
294
295 if ( '_ALL_' === $id ) {
296 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
297 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
298 if ( 'plugin' === $type ) {
299
300 /**
301 * Action: mainwp_before_plugin_unignore
302 *
303 * Fires before plugin unignore.
304 *
305 * @since 4.1
306 */
307 do_action( 'mainwp_before_plugin_unignore', array(), $website );
308
309 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( array() ) ) );
310
311 /**
312 * Action: mainwp_after_plugin_unignore
313 *
314 * Fires after plugin unignore.
315 *
316 * @since 4.1
317 */
318 do_action( 'mainwp_after_plugin_unignore', array(), $website );
319
320 } elseif ( 'theme' === $type ) {
321 /**
322 * Action: mainwp_before_theme_unignore
323 *
324 * Fires before theme unignore.
325 *
326 * @since 4.1
327 */
328 do_action( 'mainwp_before_theme_unignore', array(), $website );
329 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( array() ) ) );
330
331 /**
332 * Action: mainwp_after_theme_unignore
333 *
334 * Fires after theme unignore.
335 *
336 * @since 4.1
337 */
338 do_action( 'mainwp_after_theme_unignore', array(), $website );
339 }
340 }
341 MainWP_DB::free_result( $websites );
342 } elseif ( MainWP_Utility::ctype_digit( $id ) ) {
343 $website = MainWP_DB::instance()->get_website_by_id( $id );
344 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
345 $slug = urldecode( $slug );
346 if ( 'plugin' === $type ) {
347 $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true );
348 if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) {
349 /**
350 * Action: mainwp_before_plugin_unignore
351 *
352 * Fires before plugin unignore.
353 *
354 * @since 4.1
355 */
356 do_action( 'mainwp_before_plugin_unignore', $decodedIgnoredPlugins, $website );
357
358 if ( is_string( $decodedIgnoredPlugins[ $slug ] ) ) { // old ignored info.
359 unset( $decodedIgnoredPlugins[ $slug ] );
360 } elseif ( is_array( $decodedIgnoredPlugins[ $slug ] ) ) {
361 $ignored_info = $decodedIgnoredPlugins[ $slug ];
362 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
363
364 if ( ! is_array( $ignored_vers ) ) {
365 $ignored_vers = array();
366 }
367
368 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
369 unset( $decodedIgnoredPlugins[ $slug ] );
370 } else {
371 $ver = urldecode( $ver );
372 if ( in_array( $ver, $ignored_vers ) ) {
373 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
374 }
375 $ignored_info['ignored_versions'] = $ignored_vers;
376 if ( empty( $ignored_vers ) ) {
377 unset( $decodedIgnoredPlugins[ $slug ] );
378 } else {
379 $decodedIgnoredPlugins[ $slug ] = $ignored_info;
380 }
381 }
382 }
383 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) );
384 /**
385 * Action: mainwp_after_plugin_unignore
386 *
387 * Fires after plugin unignore.
388 *
389 * @since 4.1
390 */
391 do_action( 'mainwp_after_plugin_unignore', $decodedIgnoredPlugins, $website );
392 }
393 } elseif ( 'theme' === $type ) {
394 $decodedIgnoredThemes = json_decode( $website->ignored_themes, true );
395 if ( isset( $decodedIgnoredThemes[ $slug ] ) ) {
396
397 /**
398 * Action: mainwp_before_theme_unignore
399 *
400 * Fires before theme unignore.
401 *
402 * @since 4.1
403 */
404 do_action( 'mainwp_before_theme_unignore', $decodedIgnoredThemes, $website );
405
406 if ( is_string( $decodedIgnoredThemes[ $slug ] ) ) { // old ignored info.
407 unset( $decodedIgnoredThemes[ $slug ] );
408 } elseif ( is_array( $decodedIgnoredThemes[ $slug ] ) ) {
409 $ignored_info = $decodedIgnoredThemes[ $slug ];
410 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
411
412 if ( ! is_array( $ignored_vers ) ) {
413 $ignored_vers = array();
414 }
415
416 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
417 unset( $decodedIgnoredThemes[ $slug ] );
418 } else {
419 $ver = urldecode( $ver );
420 if ( in_array( $ver, $ignored_vers ) ) {
421 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
422 }
423 $ignored_info['ignored_versions'] = $ignored_vers;
424 if ( empty( $ignored_vers ) ) {
425 unset( $decodedIgnoredThemes[ $slug ] );
426 } else {
427 $decodedIgnoredThemes[ $slug ] = $ignored_info;
428 }
429 }
430 }
431
432 MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) );
433
434 /**
435 * Action: mainwp_after_theme_unignore
436 *
437 * Fires after theme unignore.
438 *
439 * @since 4.1
440 */
441 do_action( 'mainwp_after_theme_unignore', $decodedIgnoredThemes, $website );
442 }
443 }
444 }
445 }
446 }
447
448 return 'success';
449 }
450
451
452 /**
453 * Remove WP from the ignore list.
454 *
455 * @param mixed $id Plugin or Theme name.
456 * @param string $ver Plugin or Theme version.
457 *
458 * @return string success.
459 */
460 public static function unignore_core_updates( $id, $ver ) { // phpcs:ignore -- NOSONAR - complex.
461 if ( ! empty( $id ) ) {
462
463 if ( '_ALL_' === $id ) {
464 $params = array(
465 'view' => 'updates_view',
466 'others_fields' => array( 'premium_upgrades' ),
467 );
468 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user_by_params( $params ) );
469 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
470
471 /**
472 * Action: mainwp_before_core_unignore
473 *
474 * Fires before plugin unignore.
475 *
476 * @since 5.2
477 */
478 do_action( 'mainwp_before_core_unignore', '_ALL_', $website );
479
480 MainWP_DB::instance()->update_website_option( $website->id, 'ignored_wp_upgrades', wp_json_encode( array() ) );
481 /**
482 * Action: mainwp_after_core_unignore
483 *
484 * Fires after plugin unignore.
485 *
486 * @since 5.2
487 */
488 do_action( 'mainwp_before_core_unignore', '_ALL_', $website );
489
490 }
491 MainWP_DB::free_result( $websites );
492 return 'success';
493 } elseif ( MainWP_Utility::ctype_digit( $id ) ) {
494 $website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'ignored_wp_upgrades' ) );
495 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
496 $ignored_info = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
497
498 if ( ! is_array( $ignored_info ) ) {
499 $ignored_info = array();
500 }
501 /**
502 * Action: mainwp_before_core_unignore
503 *
504 * Fires before plugin unignore.
505 *
506 * @since 5.2
507 */
508 do_action( 'mainwp_before_core_unignore', $ignored_info, $website );
509
510 $ignored_vers = isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
511
512 if ( ! is_array( $ignored_vers ) ) {
513 $ignored_vers = array();
514 }
515
516 if ( empty( $ver ) || 'all_versions' === $ver ) { // unignore all.
517 $ignored_vers = array();
518 } elseif ( in_array( $ver, $ignored_vers ) ) {
519 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
520 }
521 $ignored_info['ignored_versions'] = $ignored_vers;
522 MainWP_DB::instance()->update_website_option( $website->id, 'ignored_wp_upgrades', wp_json_encode( $ignored_info ) );
523 /**
524 * Action: mainwp_after_core_unignore
525 *
526 * Fires after plugin unignore.
527 *
528 * @since 5.2
529 */
530 do_action( 'mainwp_after_core_unignore', $ignored_info, $website );
531 return 'success';
532 }
533 }
534 }
535 return 'failed';
536 }
537
538 /**
539 * Unignore Plugins or Themes.
540 *
541 * @param string $slug _ALL_|empty.
542 * @param string $ver version info.
543 *
544 * @return string success.
545 *
546 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
547 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
548 */
549 public static function unignore_global_cores( $slug, $ver ) { // phpcs:ignore -- NOSONAR - complex.
550 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
551 if ( '_ALL_' === $slug ) {
552 $decodedIgnoredCores = array();
553 } else {
554 $decodedIgnoredCores = json_decode( $userExtension->ignored_plugins, true );
555 if ( ! is_array( $decodedIgnoredCores ) ) {
556 $decodedIgnoredCores = array();
557 }
558 if ( 'all_versions' === $ver ) {
559 $decodedIgnoredCores = array();
560 } else {
561 $ignored_vers = is_array( $decodedIgnoredCores ) && isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array();
562 if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) {
563 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
564 if ( empty( $ignored_vers ) ) {
565 $decodedIgnoredCores = array();
566 } else {
567 $decodedIgnoredCores['ignored_versions'] = $ignored_vers;
568 }
569 }
570 }
571 }
572 MainWP_DB_Common::instance()->update_user_extension(
573 array(
574 'userid' => null,
575 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ),
576 )
577 );
578
579 return 'success';
580 }
581
582 /**
583 * Method ignore_plugins_themes()
584 *
585 * Ignore Plugins or Themes.
586 *
587 * @param string $type Plugin or theme.
588 * @param string $slug Plugin or tempheme slug.
589 * @param string $name Plugin or theme name.
590 * @param string $ver Plugin or theme version.
591 *
592 * @return string 'success'.
593 *
594 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
595 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
596 */
597 public static function ignore_plugins_themes( $type, $slug, $name, $ver = '' ) { //phpcs:ignore -- NOSONAR complex function.
598 $slug = urldecode( $slug );
599 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
600 if ( 'plugin' === $type ) {
601 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
602 if ( ! is_array( $decodedIgnoredPlugins ) ) {
603 $decodedIgnoredPlugins = array();
604 }
605
606 $ignored_info = is_array( $decodedIgnoredPlugins ) && isset( $decodedIgnoredPlugins[ $slug ] ) ? $decodedIgnoredPlugins[ $slug ] : array();
607 if ( ! is_array( $ignored_info ) ) {
608 $ignored_info = array();
609 }
610
611 $ignored_info['Name'] = urldecode( $name );
612
613 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
614 if ( ! is_array( $ignored_vers ) ) {
615 $ignored_vers = array();
616 }
617
618 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
619 $ignored_vers = array( 'all_versions' );
620 } else {
621 $ver = urldecode( $ver );
622 if ( ! in_array( $ver, $ignored_vers ) ) {
623 $ignored_vers[] = $ver;
624 }
625 }
626
627 $ignored_info['ignored_versions'] = $ignored_vers;
628 $decodedIgnoredPlugins[ $slug ] = $ignored_info;
629
630 MainWP_DB_Common::instance()->update_user_extension(
631 array(
632 'userid' => null,
633 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ),
634 )
635 );
636 } elseif ( 'theme' === $type ) {
637 $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true );
638 if ( ! is_array( $decodedIgnoredThemes ) ) {
639 $decodedIgnoredThemes = array();
640 }
641
642 $ignored_info = is_array( $decodedIgnoredThemes ) && isset( $decodedIgnoredThemes[ $slug ] ) ? $decodedIgnoredThemes[ $slug ] : array();
643 if ( ! is_array( $ignored_info ) ) {
644 $ignored_info = array();
645 }
646
647 $ignored_info['Name'] = urldecode( $name );
648
649 $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array();
650 if ( ! is_array( $ignored_vers ) ) {
651 $ignored_vers = array();
652 }
653 if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all.
654 $ignored_vers = array( 'all_versions' );
655 } else {
656 $ver = urldecode( $ver );
657 if ( ! in_array( $ver, $ignored_vers ) ) {
658 $ignored_vers[] = $ver;
659 }
660 }
661 $ignored_info['ignored_versions'] = $ignored_vers;
662 $decodedIgnoredThemes[ $slug ] = $ignored_info;
663
664 MainWP_DB_Common::instance()->update_user_extension(
665 array(
666 'userid' => null,
667 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ),
668 )
669 );
670 }
671
672 return 'success';
673 }
674
675 /**
676 * Unignore Plugins or Themes.
677 *
678 * @param mixed $type plugin|themes.
679 * @param mixed $slug Plugin or Themes slug.
680 * @param string $ver Plugin or Themes version.
681 *
682 * @return string success.
683 *
684 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
685 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
686 */
687 public static function unignore_global_plugins_themes( $type, $slug, $ver ) { // phpcs:ignore -- NOSONAR - complex.
688 $slug = urldecode( $slug );
689 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
690 if ( 'plugin' === $type ) {
691 if ( '_ALL_' === $slug ) {
692 $decodedIgnoredPlugins = array();
693 } else {
694 $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true );
695 if ( ! is_array( $decodedIgnoredPlugins ) ) {
696 $decodedIgnoredPlugins = array();
697 }
698 if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) {
699 if ( 'all_versions' === $ver ) {
700 unset( $decodedIgnoredPlugins[ $slug ] );
701 } else {
702 $ignored_vers = is_array( $decodedIgnoredPlugins[ $slug ] ) && isset( $decodedIgnoredPlugins[ $slug ]['ignored_versions'] ) ? $decodedIgnoredPlugins[ $slug ]['ignored_versions'] : array();
703 if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) {
704 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
705 if ( empty( $ignored_vers ) ) {
706 unset( $decodedIgnoredPlugins[ $slug ] );
707 } else {
708 $decodedIgnoredPlugins[ $slug ]['ignored_versions'] = $ignored_vers;
709 }
710 }
711 }
712 }
713 }
714 MainWP_DB_Common::instance()->update_user_extension(
715 array(
716 'userid' => null,
717 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ),
718 )
719 );
720 } elseif ( 'theme' === $type ) {
721 if ( '_ALL_' === $slug ) {
722 $decodedIgnoredThemes = array();
723 } else {
724 $decodedIgnoredThemes = json_decode( $userExtension->ignored_plugins, true );
725 if ( ! is_array( $decodedIgnoredThemes ) ) {
726 $decodedIgnoredThemes = array();
727 }
728 if ( isset( $decodedIgnoredThemes[ $slug ] ) ) {
729 if ( 'all_versions' === $ver ) {
730 unset( $decodedIgnoredThemes[ $slug ] );
731 } else {
732 $ignored_vers = is_array( $decodedIgnoredThemes[ $slug ] ) && isset( $decodedIgnoredThemes[ $slug ]['ignored_versions'] ) ? $decodedIgnoredThemes[ $slug ]['ignored_versions'] : array();
733 if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) {
734 $ignored_vers = array_diff( $ignored_vers, array( $ver ) );
735 if ( empty( $ignored_vers ) ) {
736 unset( $decodedIgnoredThemes[ $slug ] );
737 } else {
738 $decodedIgnoredThemes[ $slug ]['ignored_versions'] = $ignored_vers;
739 }
740 }
741 }
742 }
743 }
744 MainWP_DB_Common::instance()->update_user_extension(
745 array(
746 'userid' => null,
747 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ),
748 )
749 );
750 }
751
752 return 'success';
753 }
754
755
756 /**
757 * Unignor abandoned plugins or themes.
758 *
759 * @param mixed $type plugin|themes.
760 * @param mixed $slug Plugin or Themes slug.
761 * @param mixed $id Child Site ID.
762 *
763 * @return string success.
764 *
765 * @uses \MainWP\Dashboard\MainWP_DB::query()
766 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
767 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
768 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
769 * @uses \MainWP\Dashboard\MainWP_DB::update_website_option()
770 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
771 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
772 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
773 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
774 */
775 public static function unignore_abandoned_plugin_theme( $type, $slug, $id ) { // phpcs:ignore -- NOSONAR - complex.
776 if ( isset( $id ) ) {
777 if ( '_ALL_' === $id ) {
778 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
779 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
780 if ( 'plugin' === $type ) {
781 MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( array() ) );
782 } elseif ( 'theme' === $type ) {
783 MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( array() ) );
784 }
785 }
786 MainWP_DB::free_result( $websites );
787 } elseif ( MainWP_Utility::ctype_digit( $id ) ) {
788 $website = MainWP_DB::instance()->get_website_by_id( $id );
789 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
790 $slug = urldecode( $slug );
791 if ( 'plugin' === $type ) {
792 $decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
793 $decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array();
794
795 if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) {
796 unset( $decodedIgnoredPlugins[ $slug ] );
797 MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedIgnoredPlugins ) );
798 }
799 } elseif ( 'theme' === $type ) {
800 $decodedIgnoredThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' );
801 $decodedIgnoredThemes = ! empty( $decodedIgnoredThemes ) ? json_decode( $decodedIgnoredThemes, true ) : array();
802
803 if ( isset( $decodedIgnoredThemes[ $slug ] ) ) {
804 unset( $decodedIgnoredThemes[ $slug ] );
805 MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedIgnoredThemes ) );
806 }
807 }
808 }
809 }
810 }
811
812 return 'success';
813 }
814
815
816 /**
817 * Unignore abandoned plugins or themes.
818 *
819 * @param mixed $type plugin|theme.
820 * @param mixed $slug Plugin or Themes slug.
821 *
822 * @return string success.
823 *
824 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
825 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
826 */
827 public static function unignore_abandoned_plugins_themes( $type, $slug ) { // phpcs:ignore -- NOSONAR - complex.
828 $slug = urldecode( $slug );
829 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
830 if ( 'plugin' === $type ) {
831 if ( '_ALL_' === $slug ) {
832 $decodedIgnoredPlugins = array();
833 } else {
834 $decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true );
835 if ( ! is_array( $decodedIgnoredPlugins ) ) {
836 $decodedIgnoredPlugins = array();
837 }
838 if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) {
839 unset( $decodedIgnoredPlugins[ $slug ] );
840 }
841 }
842 MainWP_DB_Common::instance()->update_user_extension(
843 array(
844 'userid' => null,
845 'dismissed_plugins' => wp_json_encode( $decodedIgnoredPlugins ),
846 )
847 );
848 } elseif ( 'theme' === $type ) {
849 if ( '_ALL_' === $slug ) {
850 $decodedIgnoredThemes = array();
851 } else {
852 $decodedIgnoredThemes = json_decode( $userExtension->dismissed_themes, true );
853 if ( ! is_array( $decodedIgnoredThemes ) ) {
854 $decodedIgnoredThemes = array();
855 }
856 if ( isset( $decodedIgnoredThemes[ $slug ] ) ) {
857 unset( $decodedIgnoredThemes[ $slug ] );
858 }
859 }
860 MainWP_DB_Common::instance()->update_user_extension(
861 array(
862 'userid' => null,
863 'dismissed_themes' => wp_json_encode( $decodedIgnoredThemes ),
864 )
865 );
866 }
867
868 return 'success';
869 }
870
871 /**
872 * Dismis Plugin or Theme.
873 *
874 * @param mixed $type plugin|theme.
875 * @param mixed $slug Plugin or Theme slug.
876 * @param mixed $name Plugin or Theme name.
877 * @param mixed $id Child Site ID.
878 *
879 * @return string success.
880 *
881 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
882 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
883 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
884 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
885 */
886 public static function dismiss_plugin_theme( $type, $slug, $name, $id ) { // phpcs:ignore -- NOSONAR - complex.
887 if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) {
888 $website = MainWP_DB::instance()->get_website_by_id( $id );
889 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
890 $slug = urldecode( $slug );
891 if ( 'plugin' === $type ) {
892 $decodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
893 $decodedDismissedPlugins = ! empty( $decodedDismissedPlugins ) ? json_decode( $decodedDismissedPlugins, true ) : array();
894
895 if ( ! isset( $decodedDismissedPlugins[ $slug ] ) ) {
896 $decodedDismissedPlugins[ $slug ] = urldecode( $name );
897 MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedDismissedPlugins ) );
898 }
899 } elseif ( 'theme' === $type ) {
900 $decodedDismissedThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' );
901 $decodedDismissedThemes = ! empty( $decodedDismissedThemes ) ? json_decode( $decodedDismissedThemes, true ) : array();
902
903 if ( ! isset( $decodedDismissedThemes[ $slug ] ) ) {
904 $decodedDismissedThemes[ $slug ] = urldecode( $name );
905 MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedDismissedThemes ) );
906 }
907 }
908 }
909 }
910
911 return 'success';
912 }
913
914 /**
915 * Dismiss plugins or themes.
916 *
917 * @param mixed $type plugin|theme.
918 * @param mixed $slug Plugin or Theme slug.
919 * @param mixed $name Plugin or Theme name.
920 *
921 * @return string success.
922 *
923 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
924 * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension()
925 */
926 public static function dismiss_plugins_themes( $type, $slug, $name ) {
927 $slug = urldecode( $slug );
928 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
929 if ( 'plugin' === $type ) {
930 $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true );
931 if ( ! is_array( $decodedDismissedPlugins ) ) {
932 $decodedDismissedPlugins = array();
933 }
934 $decodedDismissedPlugins[ $slug ] = urldecode( $name );
935 MainWP_DB_Common::instance()->update_user_extension(
936 array(
937 'userid' => null,
938 'dismissed_plugins' => wp_json_encode( $decodedDismissedPlugins ),
939 )
940 );
941 } elseif ( 'theme' === $type ) {
942 $decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true );
943 if ( ! is_array( $decodedDismissedThemes ) ) {
944 $decodedDismissedThemes = array();
945 }
946 $decodedDismissedThemes[ $slug ] = urldecode( $name );
947 MainWP_DB_Common::instance()->update_user_extension(
948 array(
949 'userid' => null,
950 'dismissed_themes' => wp_json_encode( $decodedDismissedThemes ),
951 )
952 );
953 }
954
955 return 'success';
956 }
957
958 /**
959 * Method upgrade_plugin_theme_translation()
960 *
961 * Upgrade plugin or theme translations.
962 *
963 * @param int $id Child site ID.
964 * @param string $type Plugin or theme.
965 * @param array $list_items List of theme or plugin names seperated by comma.
966 *
967 * @return array
968 * @throws MainWP_Exception Error messages.
969 *
970 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
971 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
972 * @uses \MainWP\Dashboard\MainWP_Exception
973 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
974 */
975 public static function upgrade_plugin_theme_translation( $id, $type, $list_items ) { // phpcs:ignore -- NOSONAR - complex method.
976 if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) {
977 $website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'premium_upgrades', 'rollback_updates_data' ) ); // to fix loading premium_upgrades.
978 if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
979 throw new MainWP_Exception( 'ERROR', esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' );
980 }
981
982 $result = static::update_plugin_theme_translation( $website, $type, $list_items );
983 if ( is_array( $result ) ) {
984
985 $return_results = array();
986
987 // logging feature.
988 $_type = '';
989 if ( 'plugin' === $type || 'theme' === $type ) {
990 $_type = $type;
991 } elseif ( 'translation' === $type ) {
992 $_type = 'trans';
993 }
994
995 $undefined = true;
996
997 if ( isset( $result['upgrades_error'] ) ) {
998 foreach ( $result['upgrades_error'] as $k => $v ) {
999 $return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v );
1000 }
1001 }
1002
1003 if ( ! empty( $_type ) && isset( $result['other_data'] ) ) { // ok.
1004 $output_array = $result['other_data']; // updated_data: plugins,themes,trans.
1005 mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, $_type );
1006 if ( is_array( $output_array ) ) {
1007 $updated_data = isset( $output_array['updated_data'] ) ? $output_array['updated_data'] : array();
1008 if ( is_array( $updated_data ) ) {
1009
1010 $saved_roll_items = ! empty( $website->rollback_updates_data ) ? json_decode( $website->rollback_updates_data, true ) : array();
1011 if ( ! is_array( $saved_roll_items ) ) {
1012 $saved_roll_items = array();
1013 }
1014
1015 $update = false;
1016 foreach ( $updated_data as $item ) {
1017 $version = isset( $item['version'] ) ? $item['version'] : '';
1018 if ( ! empty( $item ) && isset( $item['slug'] ) && ! empty( $item['rollback'] ) ) {
1019 $msg = MainWP_Updates_Helper::get_roll_msg( $item );
1020 $return_results['result_error'][ rawurlencode( $item['slug'] ) ] = '[Roll]' . esc_html( $msg );
1021
1022 $name = isset( $item['name'] ) ? $item['name'] : '';
1023 $old_version = isset( $item['old_version'] ) ? $item['old_version'] : '';
1024
1025 if ( ! empty( $version ) ) {
1026 if ( ! isset( $saved_roll_items[ $_type ] ) ) {
1027 $saved_roll_items[ $_type ] = array();
1028 }
1029
1030 $saved_item = array(
1031 'name' => $name,
1032 'old_version' => $old_version,
1033 'version' => $version,
1034 'created' => time(),
1035 );
1036
1037 if ( ! empty( $item['error'] ) ) {
1038 $saved_item['error'] = $item['error'];
1039 }
1040
1041 $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] = $saved_item;
1042 $update = true;
1043 }
1044 } elseif ( ! empty( $item ) && ! empty( $item['slug'] ) && ! empty( $item['success'] ) ) {
1045 if ( ! empty( $version ) && isset( $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] ) ) {
1046 unset( $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] );
1047 $update = true;
1048 }
1049 }
1050 }
1051 if ( $update ) {
1052 MainWP_DB::instance()->update_website_option( $website, 'rollback_updates_data', wp_json_encode( $saved_roll_items ) );
1053 }
1054 }
1055 }
1056 }
1057
1058 if ( isset( $result['upgrades'] ) ) {
1059 if ( isset( $result['upgrades'] ) ) {
1060 foreach ( $result['upgrades'] as $k => $v ) {
1061 if ( ! empty( $v ) ) { // updated success.
1062 $return_results['result'][ rawurlencode( $k ) ] = $v;
1063 }
1064 }
1065 }
1066
1067 if ( 'plugin' === $type ) {
1068 if ( ! empty( $website->plugin_upgrades ) ) {
1069 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1070 if ( is_array( $plugin_upgrades ) ) {
1071 $updated = false;
1072 if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) {
1073 foreach ( $return_results['result'] as $k => $v ) {
1074 $k = rawurldecode( $k );
1075 if ( isset( $plugin_upgrades[ $k ] ) ) {
1076 unset( $plugin_upgrades[ $k ] ); // updated.
1077 $updated = true;
1078 }
1079 }
1080 }
1081 if ( $updated ) {
1082 MainWP_DB::instance()->update_website_values( $id, array( 'plugin_upgrades' => wp_json_encode( $plugin_upgrades ) ) );
1083 }
1084 }
1085 }
1086
1087 if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) {
1088 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1089 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1090 if ( is_array( $decodedPremiumUpgrades ) && ! empty( $decodedPremiumUpgrades ) ) {
1091 $updated = false;
1092 foreach ( $return_results['result'] as $k => $v ) {
1093 $k = rawurldecode( $k );
1094 if ( isset( $decodedPremiumUpgrades[ $k ] ) ) {
1095 unset( $decodedPremiumUpgrades[ $k ] ); // updated.
1096 $updated = true;
1097 }
1098 }
1099 if ( $updated ) {
1100 MainWP_DB::instance()->update_website_option( $website, 'premium_upgrades', wp_json_encode( $decodedPremiumUpgrades ) );
1101 }
1102 }
1103 }
1104 }
1105 return $return_results;
1106 } elseif ( isset( $result['error'] ) ) {
1107 throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) );
1108 } elseif ( isset( $result['notices'] ) ) {
1109 $noti = $result['notices'];
1110 if ( ! empty( $noti ) && is_string( $noti ) ) {
1111 throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
1112 }
1113 }
1114
1115 if ( $undefined ) {
1116 throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) );
1117 }
1118 }
1119 }
1120 throw new MainWP_Exception( 'ERROR', esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) );
1121 }
1122
1123 /**
1124 * Method update_plugin_theme_translation()
1125 *
1126 * Upgrade plugin or theme translations.
1127 *
1128 * @param int $website Child site object.
1129 * @param string $type Plugin or theme.
1130 * @param array $list_items List of theme or plugin names seperated by comma.
1131 *
1132 * @return array|false update result or false.
1133 * @throws \MainWP_Exception Error message.
1134 *
1135 * @uses \MainWP\Dashboard\MainWP_System_Utility
1136 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
1137 */
1138 public static function update_plugin_theme_translation( $website, $type, $list_items ) {
1139 if ( MainWP_System_Utility::can_edit_website( $website ) ) {
1140 /**
1141 * Action: mainwp_before_plugin_theme_translation_update
1142 *
1143 * Fires before plugin/theme/translation update actions.
1144 *
1145 * @since 4.1
1146 */
1147 do_action( 'mainwp_before_plugin_theme_translation_update', $type, $list_items, $website );
1148
1149 $information = MainWP_Connect::fetch_url_authed(
1150 $website,
1151 ( 'translation' === $type ? 'upgradetranslation' : 'upgradeplugintheme' ),
1152 array(
1153 'type' => $type,
1154 'list' => urldecode( $list_items ),
1155 ),
1156 true
1157 );
1158 /**
1159 * Action: mainwp_after_plugin_theme_translation_update
1160 *
1161 * Fires before plugin/theme/translation update actions.
1162 *
1163 * @since 4.1
1164 */
1165 do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, $list_items, $website );
1166
1167 return $information;
1168 }
1169 return false;
1170 }
1171
1172 /**
1173 * Get plugin or theme slugs.
1174 *
1175 * @param int $id Child Site ID.
1176 * @param string $type plugin|theme.
1177 *
1178 * @return array List of plugins or themes.
1179 *
1180 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
1181 * @uses \MainWP\Dashboard\MainWP_DB::query()
1182 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1183 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
1184 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1185 */
1186 public static function get_plugin_theme_slugs( $id, $type ) { // phpcs:ignore -- NOSONAR - complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1187
1188 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
1189 $sql = MainWP_DB::instance()->get_sql_website_by_id( $id );
1190 $websites = MainWP_DB::instance()->query( $sql );
1191 $website = MainWP_DB::fetch_object( $websites );
1192
1193 $slugs = array();
1194 if ( 'plugin' === $type ) {
1195 if ( $website->is_ignorePluginUpdates ) {
1196 return '';
1197 }
1198
1199 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
1200 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1201 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1202
1203 if ( is_array( $decodedPremiumUpgrades ) ) {
1204 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1205 $premiumUpgrade['premium'] = true;
1206
1207 if ( 'plugin' === $premiumUpgrade['type'] ) {
1208 if ( ! is_array( $plugin_upgrades ) ) {
1209 $plugin_upgrades = array();
1210 }
1211 $premiumUpgrade = array_filter( $premiumUpgrade );
1212 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
1213 }
1214 }
1215 }
1216
1217 $ignored_plugins = json_decode( $website->ignored_plugins, true );
1218 if ( is_array( $ignored_plugins ) ) {
1219 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1220
1221 }
1222
1223 $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
1224 if ( is_array( $ignored_plugins ) ) {
1225 $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
1226
1227 }
1228
1229 if ( is_array( $plugin_upgrades ) ) {
1230 foreach ( $plugin_upgrades as $slug => $plugin_upgrade ) {
1231 $slugs[] = rawurlencode( $slug );
1232 }
1233 }
1234 } elseif ( 'theme' === $type ) {
1235
1236 if ( $website->is_ignoreThemeUpdates ) {
1237 return '';
1238 }
1239
1240 $theme_upgrades = json_decode( $website->theme_upgrades, true );
1241 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
1242 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
1243
1244 if ( is_array( $decodedPremiumUpgrades ) ) {
1245 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
1246 $premiumUpgrade['premium'] = true;
1247
1248 if ( 'theme' === $premiumUpgrade['type'] ) {
1249 if ( ! is_array( $theme_upgrades ) ) {
1250 $theme_upgrades = array();
1251 }
1252 $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
1253 }
1254 }
1255 }
1256
1257 $ignored_themes = json_decode( $website->ignored_themes, true );
1258 if ( is_array( $ignored_themes ) ) {
1259 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
1260 }
1261
1262 $ignored_themes = json_decode( $userExtension->ignored_themes, true );
1263 if ( is_array( $ignored_themes ) ) {
1264 $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
1265 }
1266
1267 if ( is_array( $theme_upgrades ) ) {
1268 foreach ( $theme_upgrades as $slug => $theme_upgrade ) {
1269 $slugs[] = $slug;
1270 }
1271 }
1272 } elseif ( 'translation' === $type ) {
1273 $translation_upgrades = json_decode( $website->translation_upgrades, true );
1274 if ( is_array( $translation_upgrades ) ) {
1275 foreach ( $translation_upgrades as $translation_upgrade ) {
1276 $slugs[] = $translation_upgrade['slug'];
1277 }
1278 }
1279 }
1280
1281 return implode( ',', $slugs );
1282 }
1283 }
1284