PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.0.12
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.0.12
6.2.3 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 All 156 releases
mainwp / widgets / widget-mainwp-updates-overview.php

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

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