PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.6.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.6.0.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
mainwp / widgets / widget-mainwp-updates-overview.php

widget-mainwp-updates-overview.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.6.0.1, at widgets/widget-mainwp-updates-overview.php

1,187 lines 44.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Updates Overview Widget
4 *
5 * Grab Child Sites update status & build widget.
6 *
7 * @package MainWP/Updates_Overview
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_Updates_Overview
14 *
15 * @package MainWP\Dashboard
16 */
17 class MainWP_Updates_Overview {
18
19 /**
20 * Method get_class_name()
21 *
22 * Get Class Name
23 *
24 * @return string __CLASS__ Class Name.
25 */
26 public static function get_class_name() {
27 return __CLASS__;
28 }
29
30 /**
31 * Method init()
32 *
33 * Add plugins api filter.
34 */
35 public static function init() {
36 add_filter( 'plugins_api', array( __CLASS__, 'plugins_api' ), 10, 3 );
37 }
38
39 /**
40 * Method plugins_api()
41 *
42 * Grab Child Sites update status & build widget.
43 *
44 * @param mixed $default_value Default.
45 * @param mixed $action Action.
46 * @param mixed $args Slug.
47 *
48 * @return mixed $default|$res
49 */
50 public static function plugins_api( $default_value, $action, $args ) {
51 if ( property_exists( $args, 'slug' ) && ( 'mainwp' === $args->slug ) ) {
52 return $default_value;
53 }
54
55 $url = 'http://api.wordpress.org/plugins/info/1.0/';
56 $ssl = wp_http_supports( array( 'ssl' ) );
57 if ( $ssl ) {
58 $url = set_url_scheme( $url, 'https' );
59 }
60
61 $args = array(
62 'timeout' => 15,
63 'body' => array(
64 'action' => $action,
65 'request' => serialize( $args ), // phpcs:ignore -- WP.org API params.
66 ),
67 );
68 $request = wp_remote_post( $url, $args );
69
70 if ( is_wp_error( $request ) ) {
71 $url = isset( $_REQUEST['url'] ) ? esc_url_raw( wp_unslash( $_REQUEST['url'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
72 $name = isset( $_REQUEST['name'] ) ? wp_unslash( $_REQUEST['name'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
73 $res = new \WP_Error( 'plugins_api_failed', esc_html__( '<h3>No plugin information found.</h3> This may be a premium plugin and no other details are available from WordPress.', 'mainwp' ) . ' ' . ( empty( $url ) ? esc_html__( 'Please visit the plugin website for more information.', 'mainwp' ) : esc_html__( 'Please visit the plugin website for more information: ', 'mainwp' ) . '<a href="' . esc_html( rawurldecode( $url ) ) . '" target="_blank">' . esc_html( rawurldecode( $name ) ) . '</a>' ), $request->get_error_message() );
74
75 return $res;
76 }
77
78 return $default_value;
79 }
80
81 /**
82 * Method get_name()
83 *
84 * Define Widget Title.
85 */
86 public static function get_name() {
87 return esc_html__( 'Update Overview', 'mainwp' );
88 }
89
90 /**
91 * Method render()
92 *
93 * Check if $_GET['dashboard'] then run render_sites().
94 */
95 public static function render() {
96 self::render_sites();
97 }
98
99 /**
100 * Method render_sites()
101 *
102 * Grab available Child Sites updates a build Widget.
103 *
104 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
105 * @uses \MainWP\Dashboard\MainWP_DB_Common::get_last_sync_status()
106 * @uses \MainWP\Dashboard\MainWP_DB::query()
107 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
108 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
109 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()::fetch_object()
110 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
111 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
112 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
113 */
114 public static function render_sites() { // phpcs:ignore -- current complexity required to achieve desired results. Pull request solutions appreciated.
115
116 $globalView = true;
117
118 /**
119 * Current user global.
120 *
121 * @global string
122 */
123 global $current_user;
124
125 $current_wpid = MainWP_System_Utility::get_current_wpid();
126
127 if ( $current_wpid ) {
128 $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid, false, array( 'premium_upgrades', 'plugins_outdate_dismissed', 'themes_outdate_dismissed', 'plugins_outdate_info', 'themes_outdate_info', 'favi_icon' ) );
129 $globalView = false;
130 } else {
131 $staging_enabled = is_plugin_active( 'mainwp-staging-extension/mainwp-staging-extension.php' ) || is_plugin_active( 'mainwp-timecapsule-extension/mainwp-timecapsule-extension.php' );
132 // To support staging extension.
133 $is_staging = 'no';
134 if ( $staging_enabled ) {
135 $staging_updates_view = get_user_option( 'mainwp_staging_options_updates_view', $current_user->ID );
136 if ( 'staging' === $staging_updates_view ) {
137 $is_staging = 'yes';
138 }
139 }
140 // end support.
141
142 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, array( 'premium_upgrades', 'plugins_outdate_dismissed', 'themes_outdate_dismissed', 'plugins_outdate_info', 'themes_outdate_info', 'favi_icon' ), $is_staging );
143 }
144
145 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
146 $websites = MainWP_DB::instance()->query( $sql );
147
148 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
149
150 $decodedDismissedPlugins = ! empty( $userExtension->dismissed_plugins ) ? json_decode( $userExtension->dismissed_plugins, true ) : array();
151 $decodedDismissedThemes = ! empty( $userExtension->dismissed_themes ) ? json_decode( $userExtension->dismissed_themes, true ) : array();
152
153 $total_wp_upgrades = 0;
154 $total_plugin_upgrades = 0;
155 $total_translation_upgrades = 0;
156 $total_theme_upgrades = 0;
157
158 $total_plugins_outdate = 0;
159 $total_themes_outdate = 0;
160
161 $all_wp_updates = array();
162 $all_plugins_updates = array();
163 $all_themes_updates = array();
164 $all_translations_updates = array();
165
166 MainWP_DB::data_seek( $websites, 0 );
167
168 $currentSite = null;
169
170 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
171 if ( ! $globalView ) {
172 $currentSite = $website;
173 }
174
175 $pluginsIgnoredAbandoned_perSites = array();
176 $themesIgnoredAbandoned_perSites = array();
177
178 $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
179 $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
180
181 if ( $website->is_ignoreCoreUpdates ) {
182 $wp_upgrades = array();
183 }
184
185 if ( is_array( $wp_upgrades ) && count( $wp_upgrades ) > 0 ) {
186 ++$total_wp_upgrades;
187 $all_wp_updates[] = array(
188 'id' => $website->id,
189 'name' => $website->name,
190 );
191 }
192
193 $translation_upgrades = ! empty( $website->translation_upgrades ) ? json_decode( $website->translation_upgrades, true ) : array();
194
195 $plugin_upgrades = ! empty( $website->plugin_upgrades ) ? json_decode( $website->plugin_upgrades, true ) : array();
196
197 if ( $website->is_ignorePluginUpdates ) {
198 $plugin_upgrades = array();
199 }
200
201 $theme_upgrades = ! empty( $website->theme_upgrades ) ? json_decode( $website->theme_upgrades, true ) : array();
202 if ( $website->is_ignoreThemeUpdates ) {
203 $theme_upgrades = array();
204 }
205
206 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
207 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
208
209 if ( is_array( $decodedPremiumUpgrades ) ) {
210 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
211 $premiumUpgrade['premium'] = true;
212
213 if ( 'plugin' === $premiumUpgrade['type'] ) {
214 if ( ! is_array( $plugin_upgrades ) ) {
215 $plugin_upgrades = array();
216 }
217 if ( ! $website->is_ignorePluginUpdates ) {
218
219 $premiumUpgrade = array_filter( $premiumUpgrade );
220 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
221 $plugin_upgrades[ $crrSlug ] = array();
222 }
223
224 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
225 }
226 } elseif ( 'theme' === $premiumUpgrade['type'] ) {
227 if ( ! is_array( $theme_upgrades ) ) {
228 $theme_upgrades = array();
229 }
230 if ( ! $website->is_ignoreThemeUpdates ) {
231 $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
232 }
233 }
234 }
235 }
236
237 if ( is_array( $translation_upgrades ) ) {
238
239 $total_translation_upgrades += count( $translation_upgrades );
240
241 if ( count( $translation_upgrades ) > 0 ) {
242 foreach ( $translation_upgrades as $trans_upgrade ) {
243 $slug = $trans_upgrade['slug'];
244 $all_translations_updates[] = array(
245 'id' => $website->id,
246 'name' => $website->name,
247 'translation_slug' => $slug,
248 );
249 }
250 }
251 }
252
253 if ( is_array( $plugin_upgrades ) ) {
254 $ignored_plugins = ! empty( $website->ignored_plugins ) ? json_decode( $website->ignored_plugins, true ) : array();
255 if ( is_array( $ignored_plugins ) ) {
256 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
257 }
258
259 $ignored_plugins = ! empty( $userExtension->ignored_plugins ) ? json_decode( $userExtension->ignored_plugins, true ) : array();
260 if ( is_array( $ignored_plugins ) ) {
261 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
262 }
263
264 $total_plugin_upgrades += count( $plugin_upgrades );
265
266 if ( count( $plugin_upgrades ) > 0 ) {
267 foreach ( $plugin_upgrades as $slug => $value ) {
268 $all_plugins_updates[] = array(
269 'id' => $website->id,
270 'name' => $website->name,
271 'plugin_slug' => $slug,
272 );
273 }
274 }
275 }
276
277 if ( is_array( $theme_upgrades ) ) {
278 $ignored_themes = ! empty( $website->ignored_themes ) ? json_decode( $website->ignored_themes, true ) : array();
279 if ( is_array( $ignored_themes ) ) {
280 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
281 }
282
283 $ignored_themes = ! empty( $userExtension->ignored_themes ) ? json_decode( $userExtension->ignored_themes, true ) : array();
284 if ( is_array( $ignored_themes ) ) {
285 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
286 }
287
288 $total_theme_upgrades += count( $theme_upgrades );
289
290 if ( count( $theme_upgrades ) > 0 ) {
291 foreach ( $theme_upgrades as $slug => $value ) {
292 $all_themes_updates[] = array(
293 'id' => $website->id,
294 'name' => $website->name,
295 'theme_slug' => $slug,
296 );
297 }
298 }
299 }
300
301 $pluginsIgnoredAbandoned_perSites = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' );
302 $pluginsIgnoredAbandoned_perSites = ! empty( $pluginsIgnoredAbandoned_perSites ) ? json_decode( $pluginsIgnoredAbandoned_perSites, true ) : array();
303 if ( is_array( $pluginsIgnoredAbandoned_perSites ) ) {
304 $pluginsIgnoredAbandoned_perSites = array_filter( $pluginsIgnoredAbandoned_perSites );
305 }
306
307 $themesIgnoredAbandoned_perSites = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' );
308 $themesIgnoredAbandoned_perSites = ! empty( $themesIgnoredAbandoned_perSites ) ? json_decode( $themesIgnoredAbandoned_perSites, true ) : array();
309 if ( is_array( $themesIgnoredAbandoned_perSites ) ) {
310 $themesIgnoredAbandoned_perSites = array_filter( $themesIgnoredAbandoned_perSites );
311 }
312
313 $plugins_outdate = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_info' );
314 $plugins_outdate = ! empty( $plugins_outdate ) ? json_decode( $plugins_outdate, true ) : array();
315
316 $themes_outdate = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_info' );
317 $themes_outdate = ! empty( $themes_outdate ) ? json_decode( $themes_outdate, true ) : array();
318
319 if ( is_array( $plugins_outdate ) ) {
320 if ( is_array( $pluginsIgnoredAbandoned_perSites ) ) {
321 $plugins_outdate = array_diff_key( $plugins_outdate, $pluginsIgnoredAbandoned_perSites );
322 }
323
324 if ( is_array( $decodedDismissedPlugins ) ) {
325 $plugins_outdate = array_diff_key( $plugins_outdate, $decodedDismissedPlugins );
326 }
327
328 $total_plugins_outdate += count( $plugins_outdate );
329 }
330
331 if ( is_array( $themes_outdate ) ) {
332 if ( is_array( $themesIgnoredAbandoned_perSites ) ) {
333 $themes_outdate = array_diff_key( $themes_outdate, $themesIgnoredAbandoned_perSites );
334 }
335
336 if ( is_array( $decodedDismissedThemes ) ) {
337 $themes_outdate = array_diff_key( $themes_outdate, $decodedDismissedThemes );
338 }
339
340 $total_themes_outdate += count( $themes_outdate );
341 }
342 }
343
344 // WP Upgrades part.
345 $total_upgrades = $total_wp_upgrades + $total_plugin_upgrades + $total_theme_upgrades;
346
347 // to fix incorrect total updates.
348 if ( $mainwp_show_language_updates ) {
349 $total_upgrades += $total_translation_upgrades;
350 }
351
352 $trustedPlugins = ! empty( $userExtension->trusted_plugins ) ? json_decode( $userExtension->trusted_plugins, true ) : array();
353 if ( ! is_array( $trustedPlugins ) ) {
354 $trustedPlugins = array();
355 }
356 $trustedThemes = ! empty( $userExtension->trusted_themes ) ? json_decode( $userExtension->trusted_themes, true ) : array();
357 if ( ! is_array( $trustedThemes ) ) {
358 $trustedThemes = array();
359 }
360
361 /**
362 * Filter: mainwp_limit_updates_all
363 *
364 * Limits the number of updates that will be processed in a single run on Update Everything action.
365 *
366 * @since 4.0
367 */
368 $limit_updates_all = apply_filters( 'mainwp_limit_updates_all', 0 );
369
370 if ( ! $globalView ) {
371 $last_dtsSync = $currentSite->dtsSync;
372 } else {
373 $result = MainWP_DB_Common::instance()->get_last_sync_status();
374 $sync_status = $result['sync_status'];
375 $last_sync = $result['last_sync'];
376 $last_dtsSync = $result['last_sync'];
377
378 if ( 'all_synced' === $sync_status ) {
379 $last_dtsSync = get_option( 'mainwp_last_synced_all_sites', $last_sync );
380 }
381 }
382
383 $lastSyncMsg = '';
384 if ( $last_dtsSync ) {
385 $lastSyncMsg = esc_html__( 'Last successfully completed synchronization: ', 'mainwp' ) . MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $last_dtsSync ) );
386 }
387
388 $user_can_update_translation = mainwp_current_user_have_right( 'dashboard', 'update_translations' );
389 $user_can_update_wordpress = mainwp_current_user_have_right( 'dashboard', 'update_wordpress' );
390 $user_can_update_themes = mainwp_current_user_have_right( 'dashboard', 'update_themes' );
391 $user_can_update_plugins = mainwp_current_user_have_right( 'dashboard', 'update_plugins' );
392
393 $can_total_update = ( $user_can_update_wordpress && $user_can_update_plugins && $user_can_update_themes && $user_can_update_translation ) ? true : false;
394
395 self::render_total_update( $total_upgrades, $lastSyncMsg, $can_total_update, $limit_updates_all );
396 echo '<div class="mainwp-scrolly-overflow">';
397 self::render_wordpress_update( $user_can_update_wordpress, $total_wp_upgrades, $globalView, $current_wpid );
398 self::render_plugins_update( $user_can_update_plugins, $total_plugin_upgrades, $globalView, $current_wpid );
399 self::render_themes_update( $user_can_update_themes, $total_theme_upgrades, $globalView, $current_wpid );
400 if ( 1 === (int) $mainwp_show_language_updates ) {
401 self::render_language_update( $user_can_update_translation, $total_translation_upgrades, $globalView, $current_wpid );
402 }
403 self::render_abandoned_plugins( $total_plugins_outdate, $globalView, $current_wpid );
404 self::render_abandoned_themes( $total_themes_outdate, $globalView, $current_wpid );
405
406 self::render_global_update(
407 $user_can_update_wordpress,
408 $total_wp_upgrades,
409 $all_wp_updates,
410 $user_can_update_plugins,
411 $total_plugin_upgrades,
412 $all_plugins_updates,
413 $user_can_update_themes,
414 $total_theme_upgrades,
415 $all_themes_updates,
416 $mainwp_show_language_updates,
417 $user_can_update_translation,
418 $total_translation_upgrades,
419 $all_translations_updates
420 );
421 self::render_bottom( $websites, $globalView );
422 echo '</div>';
423 }
424
425 /**
426 * Render total update.
427 *
428 * @param int $total_upgrades number of update.
429 * @param string $lastSyncMsg last sync info.
430 * @param bool true|false $can_total_update permission to update all.
431 * @param int $limit_updates_all limit number of update per request, 0 is no limit.
432 */
433 public static function render_total_update( $total_upgrades, $lastSyncMsg, $can_total_update, $limit_updates_all ) {
434 $current_wpid = MainWP_System_Utility::get_current_wpid();
435 $globalView = true;
436 if ( $current_wpid ) {
437 $globalView = false;
438 }
439 ?>
440 <div class="ui grid mainwp-widget-header">
441 <div class="sixteen wide column">
442 <h3 class="ui header handle-drag">
443 <?php
444 /**
445 * Filter: mainwp_updates_overview_widget_title
446 *
447 * Filters the Updates Overview widget title text.
448 *
449 * @since 4.1
450 */
451 echo esc_html( apply_filters( 'mainwp_updates_overview_widget_title', esc_html__( 'Updates Overview', 'mainwp' ) ) );
452 ?>
453 <div class="sub header"><?php echo $lastSyncMsg; // phpcs:ignore WordPress.Security.EscapeOutput ?></div>
454 </h3>
455 </div>
456 </div>
457
458 <input type="hidden" name="updatesoverview_limit_updates_all" id="updatesoverview_limit_updates_all" value="<?php echo intval( $limit_updates_all ); ?>">
459 <?php
460 /**
461 * Action: mainwp_updates_overview_before_total_updates
462 *
463 * Fires before the total updates section in the Updates Overview widget.
464 *
465 * @since 4.1
466 */
467 do_action( 'mainwp_updates_overview_before_total_updates' );
468 ?>
469 <div class="ui stackable grid">
470 <div class="eight wide middle aligned column">
471 <div class="ui large statistic horizontal">
472 <div class="value">
473 <?php echo intval( $total_upgrades ); ?>
474 </div>
475 <div class="label">
476 <?php esc_html_e( 'Total Updates', 'mainwp' ); ?>
477 </div>
478 </div>
479 </div>
480
481 <div class="eight wide middle aligned right aligned column">
482 <?php
483 /**
484 * Filter: mainwp_update_everything_button_text
485 *
486 * Filters the Update Everything button text.
487 *
488 * @since 4.1
489 */
490
491 $is_demo = MainWP_Demo_Handle::is_demo_mode();
492 ?>
493 <?php if ( $can_total_update ) : ?>
494 <?php
495 if ( ! get_option( 'mainwp_hide_update_everything', false ) ) :
496 if ( $is_demo ) {
497 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" class="ui big button green fluid disabled" disabled="disabled">' . esc_html( apply_filters( 'mainwp_update_everything_button_text', esc_html__( 'Update Everything', 'mainwp' ) ) ) . '</a>' );
498 } else {
499 ?>
500 <a href="#" <?php echo empty( $total_upgrades ) ? 'disabled' : 'onClick="return updatesoverview_global_upgrade_all( \'all\' );"'; ?> class="ui big button fluid green" id="mainwp-update-everything-button" data-tooltip="<?php $globalView ? esc_attr_e( 'Clicking this button will update all Plugins, Themes, WP Core files and translations on ALL your websites.', 'mainwp' ) : esc_attr_e( 'Clicking this button will update all Plugins, Themes, WP Core files and translations on this website.', 'mainwp' ); ?>" data-inverted="" data-position="top center"><?php echo esc_html( apply_filters( 'mainwp_update_everything_button_text', esc_html__( 'Update Everything', 'mainwp' ) ) ); ?></a>
501 <?php } ?>
502 <?php endif; ?>
503 <?php endif; ?>
504 </div>
505 </div>
506 <?php
507 /**
508 * Action: mainwp_updates_overview_after_total_updates
509 *
510 * Fires after the total updates section in the Updates Overview widget.
511 *
512 * @since 4.1
513 */
514 do_action( 'mainwp_updates_overview_after_total_updates' );
515 }
516
517 /**
518 * Render WordPress update details.
519 *
520 * @param bool $user_can_update_wordpress Permission to update WordPress.
521 * @param int $total_wp_upgrades Total number of WordPress update.
522 * @param bool $globalView Global view or not.
523 * @param int $current_wpid Current site ID.
524 *
525 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
526 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
527 */
528 public static function render_wordpress_update( $user_can_update_wordpress, $total_wp_upgrades, $globalView, $current_wpid ) {
529 ?>
530 <div class="ui hidden divider"></div>
531 <div class="ui horizontal divider">
532 <?php
533 /**
534 * Filter: mainwp_updates_overview_update_details_divider
535 *
536 * Filters the Update Details divider text in the Updates Overview widget.
537 *
538 * @since 4.1
539 */
540 echo esc_html( apply_filters( 'mainwp_updates_overview_update_details_divider', esc_html__( 'Update Details', 'mainwp' ) ) );
541 ?>
542 </div>
543 <div class="ui hidden divider"></div>
544 <?php
545 /**
546 * Action: mainwp_updates_overview_before_update_details
547 *
548 * Fires at the top of the Update Details section in the Updates Overview widget.
549 *
550 * @since 4.1
551 */
552 do_action( 'mainwp_updates_overview_before_update_details' );
553
554 /**
555 * Action: mainwp_updates_overview_before_wordpress_updates
556 *
557 * Fires before the WordPress updates section in the Updates Overview widget.
558 *
559 * @since 4.1
560 */
561 do_action( 'mainwp_updates_overview_before_wordpress_updates' );
562
563 $is_demo = MainWP_Demo_Handle::is_demo_mode();
564 ?>
565 <div class="ui grid">
566 <div class="two column row">
567 <div class="column">
568 <div class="ui horizontal statistic">
569 <div class="value">
570 <?php echo intval( $total_wp_upgrades ); ?>
571 </div>
572 <div class="label">
573 <?php esc_html_e( 'WordPress Updates', 'mainwp' ); ?>
574 </div>
575 </div>
576 </div>
577 <div class="right aligned column">
578 <?php
579 if ( $user_can_update_wordpress ) :
580 $wpcore_update_disabled_by = '';
581 if ( $globalView ) {
582 $detail_wp_up = 'admin.php?page=UpdatesManage&tab=wordpress-updates';
583 } else {
584 $detail_wp_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=wordpress-updates';
585 $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $current_wpid );
586 }
587 ?>
588 <?php if ( 0 < $total_wp_upgrades ) : ?>
589 <?php MainWP_Updates::set_continue_update_html_selector( 'wpcore_global_upgrade_all' ); ?>
590 <a href="<?php echo esc_url( $detail_wp_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
591 <?php
592 if ( ! empty( $wpcore_update_disabled_by ) ) {
593 ?>
594 <span data-tooltip="<?php echo esc_html( $wpcore_update_disabled_by ); ?>" data-inverted="" data-position="left center"><a href="javascript:void(0)" class="ui button basic green disabled mainwp-update-all-button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a></span>
595 <?php
596 } elseif ( $is_demo ) {
597 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" class="ui green basic button disabled mainwp-update-all-button" disabled="disabled">' . esc_html__( 'Update All', 'mainwp' ) . '</a>' );
598 } else {
599 ?>
600 <a href="#" onClick="return updatesoverview_global_upgrade_all('wp');" class="ui green basic button mainwp-update-all-button <?php MainWP_Updates::get_continue_update_selector(); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-tooltip="<?php esc_html_e( 'Clicking this button will update WP Core files on All your websites.', 'mainwp' ); ?>" data-inverted="" data-position="top center"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
601 <?php
602 }
603 ?>
604 <?php else : ?>
605 <a href="<?php echo esc_url( $detail_wp_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
606 <a href="#" class="ui disabled green basic button mainwp-update-all-button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
607 <?php endif; ?>
608 <?php endif; ?>
609 </div>
610 </div>
611 </div>
612 <?php
613 /**
614 * Action: mainwp_updates_overview_after_wordpress_updates
615 *
616 * Fires after the WordPress updates section in the Updates Overview widget.
617 *
618 * @since 4.1
619 */
620 do_action( 'mainwp_updates_overview_after_wordpress_updates' );
621 }
622
623 /**
624 * Render Plugins update detail.
625 *
626 * @param bool true|false $user_can_update_plugins permission to update.
627 * @param int $total_plugin_upgrades total number of update.
628 * @param bool true|false $globalView global view or not.
629 * @param int $current_wpid current site id.
630 *
631 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
632 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
633 */
634 public static function render_plugins_update( $user_can_update_plugins, $total_plugin_upgrades, $globalView, $current_wpid ) {
635 /**
636 * Action: mainwp_updates_overview_before_plugin_updates
637 *
638 * Fires before the Plugin updates section in the Updates Overview widget.
639 *
640 * @since 4.1
641 */
642 do_action( 'mainwp_updates_overview_before_plugin_updates' );
643 $is_demo = MainWP_Demo_Handle::is_demo_mode();
644 ?>
645 <div class="ui grid">
646 <div class="two column row">
647 <div class="column">
648 <div class="ui horizontal statistic">
649 <div class="value">
650 <?php echo intval( $total_plugin_upgrades ); ?>
651 </div>
652 <div class="label">
653 <?php esc_html_e( 'Plugin Updates', 'mainwp' ); ?>
654 </div>
655 </div>
656 </div>
657 <div class="right aligned column">
658 <?php
659 if ( $user_can_update_plugins ) {
660 MainWP_Updates::set_continue_update_html_selector( 'plugins_global_upgrade_all' );
661 if ( $globalView ) {
662 $detail_plugins_up = 'admin.php?page=UpdatesManage&tab=plugins-updates';
663 $update_all_tooltip = esc_html__( 'Clicking this button will update all Plugins on All your websites.', 'mainwp' );
664 } else {
665 $detail_plugins_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=plugins-updates';
666 $update_all_tooltip = esc_html__( 'Clicking this button will update all Plugins on the website.', 'mainwp' );
667 }
668
669 if ( empty( $total_plugin_upgrades ) ) {
670 ?>
671 <a href="<?php echo esc_url( $detail_plugins_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
672 <a href="#" class="ui disabled green basic button mainwp-update-all-button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
673 <?php
674 } else {
675 ?>
676 <a href="<?php echo esc_url( $detail_plugins_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
677 <?php
678 if ( $is_demo ) {
679 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" class="ui basic green button mainwp-update-all-button disabled" disabled="disabled">' . esc_html__( 'Update All', 'mainwp' ) . '</a>' );
680 } else {
681 ?>
682 <a href="#" onClick="return updatesoverview_global_upgrade_all('plugin');" class="ui basic green mainwp-update-all-button button <?php MainWP_Updates::get_continue_update_selector(); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-tooltip="<?php echo esc_attr( $update_all_tooltip ); ?>" data-inverted="" data-position="top center"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
683 <?php
684 }
685 }
686 }
687 ?>
688 </div>
689 </div>
690 </div>
691 <?php
692 /**
693 * Action: mainwp_updates_overview_after_plugin_updates
694 *
695 * Fires after the Plugin updates section in the Updates Overview widget.
696 *
697 * @since 4.1
698 */
699 do_action( 'mainwp_updates_overview_after_plugin_updates' );
700 }
701
702 /**
703 * Render Themes update detail.
704 *
705 * @param bool true|false $user_can_update_themes permission to update.
706 * @param int $total_theme_upgrades total number of update.
707 * @param bool true|false $globalView global view or not.
708 * @param int $current_wpid current site id.
709 *
710 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
711 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
712 */
713 public static function render_themes_update( $user_can_update_themes, $total_theme_upgrades, $globalView, $current_wpid ) {
714 /**
715 * Action: mainwp_updates_overview_before_theme_updates
716 *
717 * Fires before the Theme updates section in the Updates Overview widget.
718 *
719 * @since 4.1
720 */
721 do_action( 'mainwp_updates_overview_before_theme_updates' );
722 $is_demo = MainWP_Demo_Handle::is_demo_mode();
723 ?>
724 <div class="ui grid">
725 <div class="two column row">
726 <div class="column">
727 <div class="ui horizontal statistic">
728 <div class="value">
729 <?php echo intval( $total_theme_upgrades ); ?>
730 </div>
731 <div class="label">
732 <?php esc_html_e( 'Theme Updates', 'mainwp' ); ?>
733 </div>
734 </div>
735 </div>
736 <div class="right aligned column">
737 <?php
738 if ( $user_can_update_themes ) {
739 MainWP_Updates::set_continue_update_html_selector( 'themes_global_upgrade_all' );
740 if ( $globalView ) {
741 $detail_themes_up = 'admin.php?page=UpdatesManage&tab=themes-updates';
742 } else {
743 $detail_themes_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=themes-updates';
744 }
745 if ( empty( $total_theme_upgrades ) ) {
746 ?>
747 <a href="<?php echo esc_url( $detail_themes_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
748 <a href="#" class="ui disabled green basic mainwp-update-all-button button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
749 <?php
750 } else {
751 ?>
752 <a href="<?php echo esc_url( $detail_themes_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
753 <?php
754 if ( $is_demo ) {
755 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" class="ui basic green button mainwp-update-all-button disabled" disabled="disabled">' . esc_html__( 'Update All', 'mainwp' ) . '</a>' );
756 } else {
757 ?>
758 <a href="#" onClick="return updatesoverview_global_upgrade_all('theme');" class="ui basic green mainwp-update-all-button button <?php MainWP_Updates::get_continue_update_selector(); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-tooltip="<?php esc_html_e( 'Clicking this button will update all Themes on All your websites.', 'mainwp' ); ?>" data-inverted="" data-position="top center"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
759 <?php
760 }
761 }
762 }
763 ?>
764 </div>
765 </div>
766 </div>
767 <?php
768 /**
769 * Action: mainwp_updates_overview_after_theme_updates
770 *
771 * Fires after the Theme updates section in the Updates Overview widget.
772 *
773 * @since 4.1
774 */
775 do_action( 'mainwp_updates_overview_after_theme_updates' );
776 }
777 /**
778 * Render language update details.
779 *
780 * @param bool $user_can_update_translation Permission to update.
781 * @param int $total_translation_upgrades Total number of update.
782 * @param bool $globalView Global view or not.
783 * @param int $current_wpid Current site id.
784 *
785 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
786 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
787 */
788 public static function render_language_update( $user_can_update_translation, $total_translation_upgrades, $globalView, $current_wpid ) {
789 /**
790 * Action: mainwp_updates_overview_before_translation_updates
791 *
792 * Fires before the Translation updates section in the Updates Overview widget.
793 *
794 * @since 4.1
795 */
796 do_action( 'mainwp_updates_overview_before_translation_updates' );
797 $is_demo = MainWP_Demo_Handle::is_demo_mode();
798 ?>
799 <div class="ui grid">
800 <div class="two column row">
801 <div class="column">
802 <div class="ui horizontal statistic">
803 <div class="value">
804 <?php echo intval( $total_translation_upgrades ); ?>
805 </div>
806 <div class="label">
807 <?php esc_html_e( 'Translation Updates', 'mainwp' ); ?>
808 </div>
809 </div>
810 </div>
811 <div class="right aligned column">
812 <?php
813 if ( $user_can_update_translation ) {
814 MainWP_Updates::set_continue_update_html_selector( 'translations_global_upgrade_all' );
815 if ( $globalView ) {
816 $detail_trans_up = 'admin.php?page=UpdatesManage&tab=translations-updates';
817 } else {
818 $detail_trans_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=translations-updates';
819 }
820 if ( empty( $total_translation_upgrades ) ) {
821 ?>
822 <a href="<?php echo esc_url( $detail_trans_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
823 <a href="#" class="ui disabled green basic mainwp-update-all-button button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
824 <?php
825 } else {
826 ?>
827 <a href="<?php echo esc_url( $detail_trans_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
828 <?php
829 if ( $is_demo ) {
830 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<a href="javascript:void(0)" class="ui basic green button mainwp-update-all-button disabled" disabled="disabled">' . esc_html__( 'Update All', 'mainwp' ) . '</a>' );
831 } else {
832 ?>
833 <a href="#" onClick="return updatesoverview_global_upgrade_all('translation');" class="ui basic green mainwp-update-all-button button <?php MainWP_Updates::get_continue_update_selector(); // phpcs:ignore WordPress.Security.EscapeOutput ?>" data-tooltip="<?php esc_html_e( 'Clicking this button will update all Translations on All your websites.', 'mainwp' ); ?>" data-inverted="" data-position="top center"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
834 <?php
835 }
836 }
837 }
838 ?>
839 </div>
840 </div>
841 </div>
842 <?php
843 /**
844 * Action: mainwp_updates_overview_after_translation_updates
845 *
846 * Fires after the Translation updates section in the Updates Overview widget.
847 *
848 * @since 4.1
849 */
850 do_action( 'mainwp_updates_overview_after_translation_updates' );
851
852 /**
853 * Action: mainwp_updates_overview_after_update_details
854 *
855 * Fires at the bottom of the Update Details section in the Updates Overview widget.
856 *
857 * @since 4.1
858 */
859 do_action( 'mainwp_updates_overview_after_update_details' );
860 }
861
862 /**
863 * Render abandoned plugins detail.
864 *
865 * @param int $total_plugins_outdate total number of update.
866 * @param bool $globalView global view or not.
867 * @param int $current_wpid current site id.
868 */
869 public static function render_abandoned_plugins( $total_plugins_outdate, $globalView, $current_wpid ) {
870 ?>
871 <div class="ui hidden divider"></div>
872 <div class="ui horizontal divider">
873 <?php
874 /**
875 * Filter: mainwp_updates_overview_abandoned_plugins_themes_divider
876 *
877 * Filters the Abandoned Plugins & Themes divider text in the Updates Overview widget.
878 *
879 * @since 4.1
880 */
881 echo esc_html( apply_filters( 'mainwp_updates_overview_abandoned_plugins_themes_divider', esc_html__( 'Abandoned Plugins & Themes', 'mainwp' ) ) );
882 ?>
883 </div>
884 <div class="ui hidden divider"></div>
885 <?php
886 /**
887 * Action: mainwp_updates_overview_before_abandoned_plugins_themes
888 *
889 * Fires at the top of the Abandoned Plugins & Themes section in the Updates Overview widget.
890 *
891 * @since 4.1
892 */
893 do_action( 'mainwp_updates_overview_before_abandoned_plugins_themes' );
894 ?>
895 <div class="ui grid">
896 <div class="two column row">
897 <div class="column">
898 <div class="ui horizontal statistic">
899 <?php
900 if ( $globalView ) {
901 $detail_aban_plugins = 'admin.php?page=UpdatesManage&tab=abandoned-plugins';
902 } else {
903 $detail_aban_plugins = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=abandoned-plugins';
904 }
905 ?>
906 <div class="value">
907 <?php echo intval( $total_plugins_outdate ); ?>
908 </div>
909 <div class="label">
910 <?php esc_html_e( 'Abandoned Plugins', 'mainwp' ); ?>
911 </div>
912 </div>
913 </div>
914 <div class="right aligned column">
915 <a href="<?php echo esc_url( $detail_aban_plugins ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
916 </div>
917 </div>
918 </div>
919 <?php
920 }
921
922 /**
923 * Render abandoned themes detail.
924 *
925 * @param int $total_themes_outdate Total number of update.
926 * @param bool $globalView global View or not.
927 * @param int $current_wpid Current site ID.
928 */
929 public static function render_abandoned_themes( $total_themes_outdate, $globalView, $current_wpid ) {
930 ?>
931 <div class="ui grid">
932 <div class="two column row">
933 <div class="column">
934 <div class="ui horizontal statistic">
935 <?php
936 if ( $globalView ) {
937 $detail_aban_themes = 'admin.php?page=UpdatesManage&tab=abandoned-themes';
938 } else {
939 $detail_aban_themes = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=abandoned-themes';
940 }
941 ?>
942 <div class="value">
943 <?php echo intval( $total_themes_outdate ); ?>
944 </div>
945 <div class="label">
946 <?php esc_html_e( 'Abandoned Themes', 'mainwp' ); ?>
947 </div>
948 </div>
949 </div>
950 <div class="right aligned column">
951 <a href="<?php echo esc_url( $detail_aban_themes ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
952 </div>
953 </div>
954 </div>
955 <?php
956 /**
957 * Action: mainwp_updates_overview_after_abandoned_plugins_themes
958 *
959 * Fires at the bottom of the Abandoned Plugins & Themes section in the Updates Overview widget.
960 *
961 * @since 4.1
962 */
963 do_action( 'mainwp_updates_overview_after_abandoned_plugins_themes' );
964 }
965
966 /**
967 * Method render_global_update()
968 *
969 * Render global updates.
970 *
971 * @param bool $user_can_update_wordpress Permission to update WordPress.
972 * @param int $total_wp_upgrades Total WordPress update.
973 * @param array $all_wp_updates All WordPress update list.
974 *
975 * @param bool $user_can_update_plugins permission to update plugings.
976 * @param int $total_plugin_upgrades total WordPress update.
977 * @param array $all_plugins_updates all WordPress update list.
978 *
979 * @param bool $user_can_update_themes permission to update themes.
980 * @param int $total_theme_upgrades total themes update.
981 * @param mixed $all_themes_updates all themes update list.
982 *
983 * @param mixed $mainwp_show_language_updates MainWP Language Updates.
984 * @param bool $user_can_update_translation permission to update languages.
985 * @param int $total_translation_upgrades total WordPress update.
986 * @param mixed $all_translations_updates all transations update list.
987 */
988 public static function render_global_update(
989 $user_can_update_wordpress,
990 $total_wp_upgrades,
991 $all_wp_updates,
992 $user_can_update_plugins,
993 $total_plugin_upgrades,
994 $all_plugins_updates,
995 $user_can_update_themes,
996 $total_theme_upgrades,
997 $all_themes_updates,
998 $mainwp_show_language_updates,
999 $user_can_update_translation,
1000 $total_translation_upgrades,
1001 $all_translations_updates
1002 ) {
1003 ?>
1004 <div style="display: none">
1005
1006 <div id="wp_upgrades">
1007 <?php
1008 if ( $user_can_update_wordpress && $total_wp_upgrades > 0 ) {
1009 foreach ( $all_wp_updates as $item ) {
1010 ?>
1011 <div updated="0" site_id="<?php echo intval( $item['id'] ); ?>" site_name="<?php echo esc_attr( $item['name'] ); ?>" ></div>
1012 <?php
1013 }
1014 }
1015 ?>
1016 </div>
1017
1018 <div id="wp_plugin_upgrades">
1019 <?php
1020 if ( $user_can_update_plugins && $total_plugin_upgrades > 0 ) {
1021 foreach ( $all_plugins_updates as $item ) {
1022 ?>
1023 <div updated="0" site_id="<?php echo intval( $item['id'] ); ?>" site_name="<?php echo esc_attr( $item['name'] ); ?>" plugin_slug="<?php echo esc_attr( $item['plugin_slug'] ); ?>" ></div>
1024 <?php
1025 }
1026 }
1027 ?>
1028 </div>
1029 <div id="wp_theme_upgrades">
1030
1031 <?php
1032 if ( $user_can_update_themes && $total_theme_upgrades > 0 ) {
1033 foreach ( $all_themes_updates as $item ) {
1034 ?>
1035 <div updated="0" site_id="<?php echo intval( $item['id'] ); ?>" site_name="<?php echo esc_attr( $item['name'] ); ?>" theme_slug="<?php echo esc_attr( $item['theme_slug'] ); ?>" ></div>
1036 <?php
1037 }
1038 }
1039 ?>
1040
1041 </div>
1042 <?php if ( 1 === (int) $mainwp_show_language_updates ) : ?>
1043 <div id="wp_translation_upgrades">
1044
1045 <?php
1046 if ( $user_can_update_translation && $total_translation_upgrades > 0 ) {
1047 foreach ( $all_translations_updates as $item ) {
1048 ?>
1049 <div updated="0" site_id="<?php echo intval( $item['id'] ); ?>" site_name="<?php echo esc_attr( $item['name'] ); ?>" translation_slug="<?php echo esc_attr( $item['translation_slug'] ); ?>" ></div>
1050 <?php
1051 }
1052 }
1053 ?>
1054 </div>
1055 <?php endif; ?>
1056 </div>
1057 <?php
1058 }
1059
1060 /**
1061 * Render bottom of widget.
1062 *
1063 * @param object $websites Object containing child sites info.
1064 * @param bool $globalView Whether it's global or individual site view.
1065 *
1066 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1067 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
1068 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1069 */
1070 public static function render_bottom( $websites, $globalView ) {
1071
1072 MainWP_DB::data_seek( $websites, 0 );
1073
1074 $site_ids = array();
1075 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1076 $site_ids[] = $website->id;
1077 }
1078
1079 /**
1080 * Action: mainwp_updatesoverview_widget_bottom
1081 *
1082 * Fires at the bottom of the Updates Overview widgets.
1083 *
1084 * @param array $side_ids Array of sites IDs.
1085 * @param bool $globalView Whether it's global or individual site view.
1086 *
1087 * @since 4.0
1088 */
1089 do_action( 'mainwp_updatesoverview_widget_bottom', $site_ids, $globalView );
1090 ?>
1091 <div class="ui modal" id="updatesoverview-backup-box" tabindex="0">
1092 <div class="header"><?php esc_html_e( 'Backup Check', 'mainwp' ); ?></div>
1093 <div class="scrolling content mainwp-modal-content"></div>
1094 <div class="actions mainwp-modal-actions">
1095 <input id="updatesoverview-backup-all" type="button" name="Backup All" value="<?php esc_html_e( 'Backup All', 'mainwp' ); ?>" class="button-primary"/>
1096 <a id="updatesoverview-backup-now" href="#" target="_blank" style="display: none" class="button-primary button"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></a>&nbsp;
1097 <input id="updatesoverview-backup-ignore" type="button" name="Ignore" value="<?php esc_html_e( 'Ignore', 'mainwp' ); ?>" class="button"/>
1098 </div>
1099 </div>
1100
1101 <?php
1102 MainWP_DB::free_result( $websites );
1103 }
1104
1105 /**
1106 * Method dismiss_sync_errors()
1107 *
1108 * @param bool $dismiss true|false.
1109 *
1110 * @return bool true
1111 */
1112 public static function dismiss_sync_errors( $dismiss = true ) {
1113 global $current_user;
1114 update_user_option( $current_user->ID, 'mainwp_syncerrors_dismissed', $dismiss );
1115
1116 return true;
1117 }
1118
1119 /**
1120 * Method checkbackups()
1121 *
1122 * Check if Child Site needs to be backed up before updates.
1123 *
1124 * @return mixed $output
1125 *
1126 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::is_archive()
1127 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1128 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
1129 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_primary_backup()
1130 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir()
1131 */
1132 public static function check_backups() {
1133 if ( empty( $_POST['sites'] ) || ! is_array( $_POST['sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1134 return true;
1135 }
1136
1137 $primaryBackup = MainWP_System_Utility::get_primary_backup();
1138 $global_backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
1139
1140 $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
1141 if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
1142 $mainwp_backup_before_upgrade_days = 7;
1143 }
1144
1145 $output = array();
1146 if ( isset( $_POST['sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1147 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) as $siteId ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1148 $website = MainWP_DB::instance()->get_website_by_id( $siteId );
1149 if ( ( 0 === (int) $website->backup_before_upgrade ) || ( ( 2 === (int) $website->backup_before_upgrade ) && empty( $global_backup_before_upgrade ) ) ) {
1150 continue;
1151 }
1152
1153 if ( ! empty( $primaryBackup ) ) {
1154 $lastBackup = MainWP_DB::instance()->get_website_option( $website, 'primary_lasttime_backup' );
1155
1156 if ( -1 !== $lastBackup ) { // installed backup plugin.
1157 $output['sites'][ $siteId ] = ( $lastBackup < ( time() - ( $mainwp_backup_before_upgrade_days * 24 * 60 * 60 ) ) ? false : true );
1158 }
1159 $output['primary_backup'] = $primaryBackup;
1160 } else {
1161 $dir = MainWP_System_Utility::get_mainwp_specific_dir( $siteId );
1162 // Check if backup ok.
1163 $lastBackup = - 1;
1164 if ( file_exists( $dir ) ) {
1165 $dh = opendir( $dir );
1166 if ( $dh ) {
1167 while ( false !== ( $file = readdir( $dh ) ) ) {
1168 if ( '.' !== $file && '..' !== $file ) {
1169 $theFile = $dir . $file;
1170 if ( MainWP_Backup_Handler::is_archive( $file ) && ! MainWP_Backup_Handler::is_sql_archive( $file ) && ( filemtime( $theFile ) > $lastBackup ) ) {
1171 $lastBackup = filemtime( $theFile );
1172 }
1173 }
1174 }
1175 closedir( $dh );
1176 }
1177 }
1178
1179 $output['sites'][ $siteId ] = ( $lastBackup < ( time() - ( $mainwp_backup_before_upgrade_days * 24 * 60 * 60 ) ) ? false : true );
1180 }
1181 }
1182 }
1183
1184 return $output;
1185 }
1186 }
1187