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

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

1,206 lines 44.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 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 = MainWP_System_Utility::get_staging_options_sites_view_for_current_users();
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
404 /**
405 * Action: mainwp_updates_overview_after_update_details
406 *
407 * Fires at the bottom of the Update Details section in the Updates Overview widget.
408 *
409 * @since 4.1
410 */
411 do_action( 'mainwp_updates_overview_after_update_details', $currentSite, $globalView, $userExtension );
412
413 self::render_abandoned_plugins( $total_plugins_outdate, $globalView, $current_wpid );
414 self::render_abandoned_themes( $total_themes_outdate, $globalView, $current_wpid );
415
416 self::render_global_update(
417 $user_can_update_wordpress,
418 $total_wp_upgrades,
419 $all_wp_updates,
420 $user_can_update_plugins,
421 $total_plugin_upgrades,
422 $all_plugins_updates,
423 $user_can_update_themes,
424 $total_theme_upgrades,
425 $all_themes_updates,
426 $mainwp_show_language_updates,
427 $user_can_update_translation,
428 $total_translation_upgrades,
429 $all_translations_updates
430 );
431 self::render_bottom( $websites, $globalView );
432 echo '</div>';
433 echo '<div class="ui stackable grid mainwp-widget-footer">';
434 echo '<div class="eight wide column"></div>';
435 echo '<div class="eight wide column"></div>';
436 echo '</div>';
437 }
438
439 /**
440 * Render total update.
441 *
442 * @param int $total_upgrades number of update.
443 * @param string $lastSyncMsg last sync info.
444 * @param bool true|false $can_total_update permission to update all.
445 * @param int $limit_updates_all limit number of update per request, 0 is no limit.
446 */
447 public static function render_total_update( $total_upgrades, $lastSyncMsg, $can_total_update, $limit_updates_all ) {
448 $current_wpid = MainWP_System_Utility::get_current_wpid();
449 $globalView = true;
450 if ( $current_wpid ) {
451 $globalView = false;
452 }
453 ?>
454 <div class="ui grid mainwp-widget-header">
455 <div class="sixteen wide column">
456 <h3 class="ui header handle-drag">
457 <?php
458 /**
459 * Filter: mainwp_updates_overview_widget_title
460 *
461 * Filters the Updates Overview widget title text.
462 *
463 * @since 4.1
464 */
465 echo esc_html( apply_filters( 'mainwp_updates_overview_widget_title', esc_html__( 'Updates Overview', 'mainwp' ) ) );
466 ?>
467 <div class="sub header"><?php echo $lastSyncMsg; // phpcs:ignore WordPress.Security.EscapeOutput ?></div>
468 </h3>
469 </div>
470 </div>
471
472 <input type="hidden" name="updatesoverview_limit_updates_all" id="updatesoverview_limit_updates_all" value="<?php echo intval( $limit_updates_all ); ?>">
473 <?php
474 /**
475 * Action: mainwp_updates_overview_before_total_updates
476 *
477 * Fires before the total updates section in the Updates Overview widget.
478 *
479 * @since 4.1
480 */
481 do_action( 'mainwp_updates_overview_before_total_updates' );
482 ?>
483 <div class="ui stackable grid">
484
485 <div class="eight wide middle aligned column">
486
487 <div class="ui large statistic horizontal">
488 <div class="value">
489 <?php echo intval( $total_upgrades ); ?>
490 </div>
491 <div class="label">
492 <?php esc_html_e( 'Total Updates', 'mainwp' ); ?>
493 </div>
494 </div>
495 </div>
496
497 <div class="eight wide middle aligned right aligned column">
498 <?php
499 /**
500 * Filter: mainwp_update_everything_button_text
501 *
502 * Filters the Update Everything button text.
503 *
504 * @since 4.1
505 */
506
507 $is_demo = MainWP_Demo_Handle::is_demo_mode();
508 ?>
509 <?php if ( $can_total_update ) : ?>
510 <?php
511 if ( ! get_option( 'mainwp_hide_update_everything', false ) ) :
512 if ( $is_demo ) {
513 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>' );
514 } else {
515 ?>
516 <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>
517 <?php } ?>
518 <?php endif; ?>
519 <?php endif; ?>
520 </div>
521 </div>
522 <?php
523 /**
524 * Action: mainwp_updates_overview_after_total_updates
525 *
526 * Fires after the total updates section in the Updates Overview widget.
527 *
528 * @since 4.1
529 */
530 do_action( 'mainwp_updates_overview_after_total_updates' );
531 }
532
533 /**
534 * Render WordPress update details.
535 *
536 * @param bool $user_can_update_wordpress Permission to update WordPress.
537 * @param int $total_wp_upgrades Total number of WordPress update.
538 * @param bool $globalView Global view or not.
539 * @param int $current_wpid Current site ID.
540 *
541 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
542 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
543 */
544 public static function render_wordpress_update( $user_can_update_wordpress, $total_wp_upgrades, $globalView, $current_wpid ) {
545 ?>
546 <div class="ui hidden divider"></div>
547 <div class="ui horizontal divider">
548 <?php
549 /**
550 * Filter: mainwp_updates_overview_update_details_divider
551 *
552 * Filters the Update Details divider text in the Updates Overview widget.
553 *
554 * @since 4.1
555 */
556 echo esc_html( apply_filters( 'mainwp_updates_overview_update_details_divider', esc_html__( 'Available Updates', 'mainwp' ) ) );
557 ?>
558 </div>
559 <div class="ui hidden divider"></div>
560 <?php
561 /**
562 * Action: mainwp_updates_overview_before_update_details
563 *
564 * Fires at the top of the Update Details section in the Updates Overview widget.
565 *
566 * @since 4.1
567 */
568 do_action( 'mainwp_updates_overview_before_update_details' );
569
570 /**
571 * Action: mainwp_updates_overview_before_wordpress_updates
572 *
573 * Fires before the WordPress updates section in the Updates Overview widget.
574 *
575 * @since 4.1
576 */
577 do_action( 'mainwp_updates_overview_before_wordpress_updates' );
578
579 $is_demo = MainWP_Demo_Handle::is_demo_mode();
580 ?>
581 <div class="ui grid">
582 <div class="two column row">
583
584 <div class="six wide column">
585 <div class="ui horizontal statistic">
586 <div class="value">
587 <?php echo intval( $total_wp_upgrades ); ?>
588 </div>
589 <div class="label">
590 <?php esc_html_e( 'WordPress', 'mainwp' ); ?>
591 </div>
592 </div>
593 </div>
594
595 <div class="ten wide right aligned column">
596 <div class="ui small buttons">
597 <?php
598 if ( $user_can_update_wordpress ) :
599 $wpcore_update_disabled_by = '';
600 if ( $globalView ) {
601 $detail_wp_up = 'admin.php?page=UpdatesManage&tab=wordpress-updates';
602 } else {
603 $detail_wp_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=wordpress-updates';
604 $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $current_wpid );
605 }
606 ?>
607 <?php if ( 0 < $total_wp_upgrades ) : ?>
608 <?php MainWP_Updates::set_continue_update_html_selector( 'wpcore_global_upgrade_all' ); ?>
609 <a href="<?php echo esc_url( $detail_wp_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
610 <?php
611 if ( ! empty( $wpcore_update_disabled_by ) ) {
612 ?>
613 <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>
614 <?php
615 } elseif ( $is_demo ) {
616 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>' );
617 } else {
618 ?>
619 <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>
620 <?php
621 }
622 ?>
623 <?php else : ?>
624
625 <a href="<?php echo esc_url( $detail_wp_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
626 <a href="#" class="ui disabled green basic button mainwp-update-all-button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
627
628 <?php endif; ?>
629 <?php endif; ?>
630 </div>
631 </div>
632 </div>
633 </div>
634 <?php
635 /**
636 * Action: mainwp_updates_overview_after_wordpress_updates
637 *
638 * Fires after the WordPress updates section in the Updates Overview widget.
639 *
640 * @since 4.1
641 */
642 do_action( 'mainwp_updates_overview_after_wordpress_updates' );
643 }
644
645 /**
646 * Render Plugins update detail.
647 *
648 * @param bool true|false $user_can_update_plugins permission to update.
649 * @param int $total_plugin_upgrades total number of update.
650 * @param bool true|false $globalView global view or not.
651 * @param int $current_wpid current site id.
652 *
653 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
654 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
655 */
656 public static function render_plugins_update( $user_can_update_plugins, $total_plugin_upgrades, $globalView, $current_wpid ) {
657 /**
658 * Action: mainwp_updates_overview_before_plugin_updates
659 *
660 * Fires before the Plugin updates section in the Updates Overview widget.
661 *
662 * @since 4.1
663 */
664 do_action( 'mainwp_updates_overview_before_plugin_updates' );
665 $is_demo = MainWP_Demo_Handle::is_demo_mode();
666 ?>
667 <div class="ui grid">
668 <div class="two column row">
669 <div class="six wide column">
670 <div class="ui horizontal statistic">
671 <div class="value">
672 <?php echo intval( $total_plugin_upgrades ); ?>
673 </div>
674 <div class="label">
675 <?php esc_html_e( 'Plugins', 'mainwp' ); ?>
676 </div>
677 </div>
678 </div>
679 <div class="ten wide right aligned column">
680 <div class="ui small buttons">
681 <?php
682 if ( $user_can_update_plugins ) {
683 MainWP_Updates::set_continue_update_html_selector( 'plugins_global_upgrade_all' );
684 if ( $globalView ) {
685 $detail_plugins_up = 'admin.php?page=UpdatesManage&tab=plugins-updates';
686 $update_all_tooltip = esc_html__( 'Clicking this button will update all Plugins on All your websites.', 'mainwp' );
687 } else {
688 $detail_plugins_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=plugins-updates';
689 $update_all_tooltip = esc_html__( 'Clicking this button will update all Plugins on the website.', 'mainwp' );
690 }
691
692 if ( empty( $total_plugin_upgrades ) ) {
693 ?>
694 <a href="<?php echo esc_url( $detail_plugins_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
695 <a href="#" class="ui disabled green basic button mainwp-update-all-button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
696 <?php
697 } else {
698 ?>
699 <a href="<?php echo esc_url( $detail_plugins_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
700 <?php
701 if ( $is_demo ) {
702 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>' );
703 } else {
704 ?>
705 <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>
706 <?php
707 }
708 }
709 }
710 ?>
711 </div>
712 </div>
713 </div>
714 </div>
715 <?php
716 /**
717 * Action: mainwp_updates_overview_after_plugin_updates
718 *
719 * Fires after the Plugin updates section in the Updates Overview widget.
720 *
721 * @since 4.1
722 */
723 do_action( 'mainwp_updates_overview_after_plugin_updates' );
724 }
725
726 /**
727 * Render Themes update detail.
728 *
729 * @param bool true|false $user_can_update_themes permission to update.
730 * @param int $total_theme_upgrades total number of update.
731 * @param bool true|false $globalView global view or not.
732 * @param int $current_wpid current site id.
733 *
734 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
735 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
736 */
737 public static function render_themes_update( $user_can_update_themes, $total_theme_upgrades, $globalView, $current_wpid ) {
738 /**
739 * Action: mainwp_updates_overview_before_theme_updates
740 *
741 * Fires before the Theme updates section in the Updates Overview widget.
742 *
743 * @since 4.1
744 */
745 do_action( 'mainwp_updates_overview_before_theme_updates' );
746 $is_demo = MainWP_Demo_Handle::is_demo_mode();
747 ?>
748 <div class="ui grid">
749 <div class="two column row">
750 <div class="six wide column">
751 <div class="ui horizontal statistic">
752 <div class="value">
753 <?php echo intval( $total_theme_upgrades ); ?>
754 </div>
755 <div class="label">
756 <?php esc_html_e( 'Themes', 'mainwp' ); ?>
757 </div>
758 </div>
759 </div>
760 <div class="ten wide right aligned column">
761 <div class="ui small buttons">
762 <?php
763 if ( $user_can_update_themes ) {
764 MainWP_Updates::set_continue_update_html_selector( 'themes_global_upgrade_all' );
765 if ( $globalView ) {
766 $detail_themes_up = 'admin.php?page=UpdatesManage&tab=themes-updates';
767 } else {
768 $detail_themes_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=themes-updates';
769 }
770 if ( empty( $total_theme_upgrades ) ) {
771 ?>
772 <a href="<?php echo esc_url( $detail_themes_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
773 <a href="#" class="ui disabled green basic mainwp-update-all-button button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
774 <?php
775 } else {
776 ?>
777 <a href="<?php echo esc_url( $detail_themes_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
778 <?php
779 if ( $is_demo ) {
780 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>' );
781 } else {
782 ?>
783 <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>
784 <?php
785 }
786 }
787 }
788 ?>
789 </div>
790 </div>
791 </div>
792 </div>
793 <?php
794 /**
795 * Action: mainwp_updates_overview_after_theme_updates
796 *
797 * Fires after the Theme updates section in the Updates Overview widget.
798 *
799 * @since 4.1
800 */
801 do_action( 'mainwp_updates_overview_after_theme_updates' );
802 }
803 /**
804 * Render language update details.
805 *
806 * @param bool $user_can_update_translation Permission to update.
807 * @param int $total_translation_upgrades Total number of update.
808 * @param bool $globalView Global view or not.
809 * @param int $current_wpid Current site id.
810 *
811 * @uses \MainWP\Dashboard\MainWP_Updates::set_continue_update_html_selector()
812 * @uses \MainWP\Dashboard\MainWP_Updates::get_continue_update_selector()
813 */
814 public static function render_language_update( $user_can_update_translation, $total_translation_upgrades, $globalView, $current_wpid ) {
815 /**
816 * Action: mainwp_updates_overview_before_translation_updates
817 *
818 * Fires before the Translation updates section in the Updates Overview widget.
819 *
820 * @since 4.1
821 */
822 do_action( 'mainwp_updates_overview_before_translation_updates' );
823 $is_demo = MainWP_Demo_Handle::is_demo_mode();
824 ?>
825 <div class="ui grid">
826 <div class="two column row">
827 <div class="six wide column">
828 <div class="ui horizontal statistic">
829 <div class="value">
830 <?php echo intval( $total_translation_upgrades ); ?>
831 </div>
832 <div class="label">
833 <?php esc_html_e( 'Translations', 'mainwp' ); ?>
834 </div>
835 </div>
836 </div>
837 <div class="ten wide right aligned column">
838 <div class="ui small buttons">
839 <?php
840 if ( $user_can_update_translation ) {
841 MainWP_Updates::set_continue_update_html_selector( 'translations_global_upgrade_all' );
842 if ( $globalView ) {
843 $detail_trans_up = 'admin.php?page=UpdatesManage&tab=translations-updates';
844 } else {
845 $detail_trans_up = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=translations-updates';
846 }
847 if ( empty( $total_translation_upgrades ) ) {
848 ?>
849 <a href="<?php echo esc_url( $detail_trans_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
850 <a href="#" class="ui disabled green basic mainwp-update-all-button button"><?php esc_html_e( 'Update All', 'mainwp' ); ?></a>
851 <?php
852 } else {
853 ?>
854 <a href="<?php echo esc_url( $detail_trans_up ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
855 <?php
856 if ( $is_demo ) {
857 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>' );
858 } else {
859 ?>
860 <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>
861 <?php
862 }
863 }
864 }
865 ?>
866 </div>
867 </div>
868 </div>
869 </div>
870 <?php
871 /**
872 * Action: mainwp_updates_overview_after_translation_updates
873 *
874 * Fires after the Translation updates section in the Updates Overview widget.
875 *
876 * @since 4.1
877 */
878 do_action( 'mainwp_updates_overview_after_translation_updates' );
879 }
880
881 /**
882 * Render abandoned plugins detail.
883 *
884 * @param int $total_plugins_outdate total number of update.
885 * @param bool $globalView global view or not.
886 * @param int $current_wpid current site id.
887 */
888 public static function render_abandoned_plugins( $total_plugins_outdate, $globalView, $current_wpid ) {
889 ?>
890 <div class="ui hidden divider"></div>
891 <div class="ui horizontal divider">
892 <?php
893 /**
894 * Filter: mainwp_updates_overview_abandoned_plugins_themes_divider
895 *
896 * Filters the Abandoned Plugins & Themes divider text in the Updates Overview widget.
897 *
898 * @since 4.1
899 */
900 echo esc_html( apply_filters( 'mainwp_updates_overview_abandoned_plugins_themes_divider', esc_html__( 'Abandoned Plugins & Themes', 'mainwp' ) ) );
901 ?>
902 </div>
903 <div class="ui hidden divider"></div>
904 <?php
905 /**
906 * Action: mainwp_updates_overview_before_abandoned_plugins_themes
907 *
908 * Fires at the top of the Abandoned Plugins & Themes section in the Updates Overview widget.
909 *
910 * @since 4.1
911 */
912 do_action( 'mainwp_updates_overview_before_abandoned_plugins_themes' );
913 ?>
914 <div class="ui grid">
915 <div class="two column row">
916 <div class="six wide column">
917 <div class="ui horizontal statistic">
918 <?php
919 if ( $globalView ) {
920 $detail_aban_plugins = 'admin.php?page=UpdatesManage&tab=abandoned-plugins';
921 } else {
922 $detail_aban_plugins = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=abandoned-plugins';
923 }
924 ?>
925 <div class="value">
926 <?php echo intval( $total_plugins_outdate ); ?>
927 </div>
928 <div class="label">
929 <?php esc_html_e( 'Plugins', 'mainwp' ); ?>
930 </div>
931 </div>
932 </div>
933 <div class="ten wide right aligned column">
934 <a href="<?php echo esc_url( $detail_aban_plugins ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
935 </div>
936 </div>
937 </div>
938 <?php
939 }
940
941 /**
942 * Render abandoned themes detail.
943 *
944 * @param int $total_themes_outdate Total number of update.
945 * @param bool $globalView global View or not.
946 * @param int $current_wpid Current site ID.
947 */
948 public static function render_abandoned_themes( $total_themes_outdate, $globalView, $current_wpid ) {
949 ?>
950 <div class="ui grid">
951 <div class="two column row">
952 <div class="six wide column">
953 <div class="ui horizontal statistic">
954 <?php
955 if ( $globalView ) {
956 $detail_aban_themes = 'admin.php?page=UpdatesManage&tab=abandoned-themes';
957 } else {
958 $detail_aban_themes = 'admin.php?page=managesites&updateid=' . $current_wpid . '&tab=abandoned-themes';
959 }
960 ?>
961 <div class="value">
962 <?php echo intval( $total_themes_outdate ); ?>
963 </div>
964 <div class="label">
965 <?php esc_html_e( 'Themes', 'mainwp' ); ?>
966 </div>
967 </div>
968 </div>
969 <div class="ten wide right aligned column">
970 <a href="<?php echo esc_url( $detail_aban_themes ); ?>" class="ui button"><?php esc_html_e( 'See Details', 'mainwp' ); ?></a>
971 </div>
972 </div>
973 </div>
974 <?php
975 /**
976 * Action: mainwp_updates_overview_after_abandoned_plugins_themes
977 *
978 * Fires at the bottom of the Abandoned Plugins & Themes section in the Updates Overview widget.
979 *
980 * @since 4.1
981 */
982 do_action( 'mainwp_updates_overview_after_abandoned_plugins_themes' );
983 }
984
985 /**
986 * Method render_global_update()
987 *
988 * Render global updates.
989 *
990 * @param bool $user_can_update_wordpress Permission to update WordPress.
991 * @param int $total_wp_upgrades Total WordPress update.
992 * @param array $all_wp_updates All WordPress update list.
993 *
994 * @param bool $user_can_update_plugins permission to update plugings.
995 * @param int $total_plugin_upgrades total WordPress update.
996 * @param array $all_plugins_updates all WordPress update list.
997 *
998 * @param bool $user_can_update_themes permission to update themes.
999 * @param int $total_theme_upgrades total themes update.
1000 * @param mixed $all_themes_updates all themes update list.
1001 *
1002 * @param mixed $mainwp_show_language_updates MainWP Language Updates.
1003 * @param bool $user_can_update_translation permission to update languages.
1004 * @param int $total_translation_upgrades total WordPress update.
1005 * @param mixed $all_translations_updates all transations update list.
1006 */
1007 public static function render_global_update(
1008 $user_can_update_wordpress,
1009 $total_wp_upgrades,
1010 $all_wp_updates,
1011 $user_can_update_plugins,
1012 $total_plugin_upgrades,
1013 $all_plugins_updates,
1014 $user_can_update_themes,
1015 $total_theme_upgrades,
1016 $all_themes_updates,
1017 $mainwp_show_language_updates,
1018 $user_can_update_translation,
1019 $total_translation_upgrades,
1020 $all_translations_updates
1021 ) {
1022 ?>
1023 <div style="display: none">
1024
1025 <div id="wp_upgrades">
1026 <?php
1027 if ( $user_can_update_wordpress && $total_wp_upgrades > 0 ) {
1028 foreach ( $all_wp_updates as $item ) {
1029 ?>
1030 <div updated="0" site_id="<?php echo intval( $item['id'] ); ?>" site_name="<?php echo esc_attr( $item['name'] ); ?>" ></div>
1031 <?php
1032 }
1033 }
1034 ?>
1035 </div>
1036
1037 <div id="wp_plugin_upgrades">
1038 <?php
1039 if ( $user_can_update_plugins && $total_plugin_upgrades > 0 ) {
1040 foreach ( $all_plugins_updates as $item ) {
1041 ?>
1042 <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>
1043 <?php
1044 }
1045 }
1046 ?>
1047 </div>
1048 <div id="wp_theme_upgrades">
1049
1050 <?php
1051 if ( $user_can_update_themes && $total_theme_upgrades > 0 ) {
1052 foreach ( $all_themes_updates as $item ) {
1053 ?>
1054 <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>
1055 <?php
1056 }
1057 }
1058 ?>
1059
1060 </div>
1061 <?php if ( 1 === (int) $mainwp_show_language_updates ) : ?>
1062 <div id="wp_translation_upgrades">
1063
1064 <?php
1065 if ( $user_can_update_translation && $total_translation_upgrades > 0 ) {
1066 foreach ( $all_translations_updates as $item ) {
1067 ?>
1068 <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>
1069 <?php
1070 }
1071 }
1072 ?>
1073 </div>
1074 <?php endif; ?>
1075 </div>
1076 <?php
1077 }
1078
1079 /**
1080 * Render bottom of widget.
1081 *
1082 * @param object $websites Object containing child sites info.
1083 * @param bool $globalView Whether it's global or individual site view.
1084 *
1085 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1086 * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
1087 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1088 */
1089 public static function render_bottom( $websites, $globalView ) {
1090
1091 MainWP_DB::data_seek( $websites, 0 );
1092
1093 $site_ids = array();
1094 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1095 $site_ids[] = $website->id;
1096 }
1097
1098 /**
1099 * Action: mainwp_updatesoverview_widget_bottom
1100 *
1101 * Fires at the bottom of the Updates Overview widgets.
1102 *
1103 * @param array $side_ids Array of sites IDs.
1104 * @param bool $globalView Whether it's global or individual site view.
1105 *
1106 * @since 4.0
1107 */
1108 do_action( 'mainwp_updatesoverview_widget_bottom', $site_ids, $globalView );
1109 ?>
1110 <div class="ui modal" id="updatesoverview-backup-box" tabindex="0">
1111 <div class="header"><?php esc_html_e( 'Backup Check', 'mainwp' ); ?></div>
1112 <div class="scrolling content mainwp-modal-content"></div>
1113 <div class="actions mainwp-modal-actions">
1114 <input id="updatesoverview-backup-all" type="button" name="Backup All" value="<?php esc_html_e( 'Backup All', 'mainwp' ); ?>" class="button-primary"/>
1115 <a id="updatesoverview-backup-now" href="#" target="_blank" style="display: none" class="button-primary button"><?php esc_html_e( 'Backup Now', 'mainwp' ); ?></a>&nbsp;
1116 <input id="updatesoverview-backup-ignore" type="button" name="Ignore" value="<?php esc_html_e( 'Ignore', 'mainwp' ); ?>" class="button"/>
1117 </div>
1118 </div>
1119
1120 <?php
1121 MainWP_DB::free_result( $websites );
1122 }
1123
1124 /**
1125 * Method dismiss_sync_errors()
1126 *
1127 * @param bool $dismiss true|false.
1128 *
1129 * @return bool true
1130 */
1131 public static function dismiss_sync_errors( $dismiss = true ) {
1132 global $current_user;
1133 update_user_option( $current_user->ID, 'mainwp_syncerrors_dismissed', $dismiss );
1134
1135 return true;
1136 }
1137
1138 /**
1139 * Method checkbackups()
1140 *
1141 * Check if Child Site needs to be backed up before updates.
1142 *
1143 * @return mixed $output
1144 *
1145 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::is_archive()
1146 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1147 * @uses \MainWP\Dashboard\MainWP_DB::get_website_option()
1148 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_primary_backup()
1149 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir()
1150 */
1151 public static function check_backups() {
1152 if ( empty( $_POST['sites'] ) || ! is_array( $_POST['sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1153 return true;
1154 }
1155
1156 $primaryBackup = MainWP_System_Utility::get_primary_backup();
1157 $global_backup_before_upgrade = get_option( 'mainwp_backup_before_upgrade' );
1158
1159 $mainwp_backup_before_upgrade_days = get_option( 'mainwp_backup_before_upgrade_days' );
1160 if ( empty( $mainwp_backup_before_upgrade_days ) || ! ctype_digit( $mainwp_backup_before_upgrade_days ) ) {
1161 $mainwp_backup_before_upgrade_days = 7;
1162 }
1163
1164 $output = array();
1165 if ( isset( $_POST['sites'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1166 foreach ( array_map( 'sanitize_text_field', wp_unslash( $_POST['sites'] ) ) as $siteId ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1167 $website = MainWP_DB::instance()->get_website_by_id( $siteId );
1168 if ( ( 0 === (int) $website->backup_before_upgrade ) || ( ( 2 === (int) $website->backup_before_upgrade ) && empty( $global_backup_before_upgrade ) ) ) {
1169 continue;
1170 }
1171
1172 if ( ! empty( $primaryBackup ) ) {
1173 $lastBackup = MainWP_DB::instance()->get_website_option( $website, 'primary_lasttime_backup' );
1174
1175 if ( -1 !== $lastBackup ) { // installed backup plugin.
1176 $output['sites'][ $siteId ] = ( $lastBackup < ( time() - ( $mainwp_backup_before_upgrade_days * 24 * 60 * 60 ) ) ? false : true );
1177 }
1178 $output['primary_backup'] = $primaryBackup;
1179 } else {
1180 $dir = MainWP_System_Utility::get_mainwp_specific_dir( $siteId );
1181 // Check if backup ok.
1182 $lastBackup = - 1;
1183 if ( file_exists( $dir ) ) {
1184 $dh = opendir( $dir ); // NOSONAR .
1185 if ( $dh ) {
1186 while ( false !== ( $file = readdir( $dh ) ) ) {
1187 if ( '.' !== $file && '..' !== $file ) {
1188 $theFile = $dir . $file;
1189 if ( MainWP_Backup_Handler::is_archive( $file ) && ! MainWP_Backup_Handler::is_sql_archive( $file ) && ( filemtime( $theFile ) > $lastBackup ) ) {
1190 $lastBackup = filemtime( $theFile );
1191 }
1192 }
1193 }
1194 closedir( $dh );
1195 }
1196 }
1197
1198 $output['sites'][ $siteId ] = ( $lastBackup < ( time() - ( $mainwp_backup_before_upgrade_days * 24 * 60 * 60 ) ) ? false : true );
1199 }
1200 }
1201 }
1202
1203 return $output;
1204 }
1205 }
1206