PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.4.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-common-handler.php

class-mainwp-common-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.4.1, at class/class-mainwp-common-handler.php

168 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Common Handler
4 *
5 * This class handles the common functions.
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_Common_Handler
14 *
15 * @package MainWP\Dashboard
16 */
17 class MainWP_Common_Handler {
18
19 /**
20 * Protected static variable to hold the single instance of the class.
21 *
22 * @var mixed Default null
23 */
24 private static $instance = null;
25
26 /**
27 * Method instance()
28 *
29 * Create public static instance.
30 *
31 * @static
32 * @return self::$instance
33 */
34 public static function instance() {
35 if ( null == self::$instance ) {
36 self::$instance = new self();
37 }
38 return self::$instance;
39 }
40
41 /**
42 * Method sites_available_updates_count()
43 *
44 * Handle get sites available updates count.
45 *
46 * @return object $response An object that contains the return data and status of the API request.
47 */
48 public function sites_available_updates_count() { // phpcs:ignore -- complex function.
49 $is_staging = 'no';
50 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, array( 'premium_upgrades', 'favi_icon' ), $is_staging );
51
52 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
53 $websites = MainWP_DB::instance()->query( $sql );
54
55 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
56
57 $total_wp_upgrades = 0;
58 $total_plugin_upgrades = 0;
59 $total_translation_upgrades = 0;
60 $total_theme_upgrades = 0;
61
62 MainWP_DB::data_seek( $websites, 0 );
63
64 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
65 $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
66 $wp_upgrades = ( '' != $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
67
68 if ( $website->is_ignoreCoreUpdates ) {
69 $wp_upgrades = array();
70 }
71
72 if ( is_array( $wp_upgrades ) && count( $wp_upgrades ) > 0 ) {
73 $total_wp_upgrades ++;
74 }
75
76 $translation_upgrades = json_decode( $website->translation_upgrades, true );
77
78 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
79 if ( $website->is_ignorePluginUpdates ) {
80 $plugin_upgrades = array();
81 }
82
83 $theme_upgrades = json_decode( $website->theme_upgrades, true );
84 if ( $website->is_ignoreThemeUpdates ) {
85 $theme_upgrades = array();
86 }
87
88 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
89 $decodedPremiumUpgrades = ( '' != $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
90
91 if ( is_array( $decodedPremiumUpgrades ) ) {
92 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
93 $premiumUpgrade['premium'] = true;
94
95 if ( 'plugin' == $premiumUpgrade['type'] ) {
96 if ( ! is_array( $plugin_upgrades ) ) {
97 $plugin_upgrades = array();
98 }
99 if ( ! $website->is_ignorePluginUpdates ) {
100
101 $premiumUpgrade = array_filter( $premiumUpgrade );
102 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
103 $plugin_upgrades[ $crrSlug ] = array();
104 }
105
106 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
107 }
108 } elseif ( 'theme' == $premiumUpgrade['type'] ) {
109 if ( ! is_array( $theme_upgrades ) ) {
110 $theme_upgrades = array();
111 }
112 if ( ! $website->is_ignoreThemeUpdates ) {
113 $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
114 }
115 }
116 }
117 }
118
119 if ( is_array( $translation_upgrades ) ) {
120 $total_translation_upgrades += count( $translation_upgrades );
121 }
122
123 if ( is_array( $plugin_upgrades ) ) {
124 $ignored_plugins = json_decode( $website->ignored_plugins, true );
125 if ( is_array( $ignored_plugins ) ) {
126 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
127 }
128
129 $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
130 if ( is_array( $ignored_plugins ) ) {
131 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
132 }
133
134 $total_plugin_upgrades += count( $plugin_upgrades );
135 }
136
137 if ( is_array( $theme_upgrades ) ) {
138 $ignored_themes = json_decode( $website->ignored_themes, true );
139 if ( is_array( $ignored_themes ) ) {
140 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
141 }
142
143 $ignored_themes = json_decode( $userExtension->ignored_themes, true );
144 if ( is_array( $ignored_themes ) ) {
145 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
146 }
147
148 $total_theme_upgrades += count( $theme_upgrades );
149 }
150 }
151
152 // WP Upgrades part.
153 $total_upgrades = $total_wp_upgrades + $total_plugin_upgrades + $total_theme_upgrades;
154
155 // to fix incorrect total updates.
156 if ( $mainwp_show_language_updates ) {
157 $total_upgrades += $total_translation_upgrades;
158 }
159
160 MainWP_DB::free_result( $websites );
161
162 return $total_upgrades;
163 }
164
165 }
166
167 // End of class.
168