PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3.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 5.0.3.1, at class/class-mainwp-common-handler.php

231 lines 7.3 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 * Returns the number of available udpates for sites.
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
51 $db_updater_count = false;
52 $total_plugin_db_upgrades = 0;
53 $supported_db_updater_plugins = array();
54
55 $get_fields = array( 'premium_upgrades', 'favi_icon' );
56 $custom_fields = apply_filters( 'mainwp_available_updates_count_custom_fields_data', array(), 'updates_count' );
57
58 if ( is_array( $custom_fields ) && 1 === count( $custom_fields ) && in_array( 'plugin_db_upgrades', $custom_fields ) ) {
59 $get_fields = array_merge( $get_fields, $custom_fields );
60 $db_updater_count = true;
61 $supported_db_updater_plugins = apply_filters( 'mainwp_database_updater_supported_plugins', array() );
62 }
63
64 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, $get_fields, $is_staging );
65
66 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, $get_fields, $is_staging );
67
68 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
69 $websites = MainWP_DB::instance()->query( $sql );
70
71 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
72
73 $total_wp_upgrades = 0;
74 $total_plugin_upgrades = 0;
75 $total_translation_upgrades = 0;
76 $total_theme_upgrades = 0;
77
78 MainWP_DB::data_seek( $websites, 0 );
79
80 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
81 $wp_upgrades = MainWP_DB::instance()->get_website_option( $website, 'wp_upgrades' );
82 $wp_upgrades = ! empty( $wp_upgrades ) ? json_decode( $wp_upgrades, true ) : array();
83
84 if ( $website->is_ignoreCoreUpdates ) {
85 $wp_upgrades = array();
86 }
87
88 if ( is_array( $wp_upgrades ) && count( $wp_upgrades ) > 0 ) {
89 ++$total_wp_upgrades;
90 }
91
92 $translation_upgrades = json_decode( $website->translation_upgrades, true );
93
94 $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
95 if ( $website->is_ignorePluginUpdates ) {
96 $plugin_upgrades = array();
97 }
98
99 $theme_upgrades = json_decode( $website->theme_upgrades, true );
100 if ( $website->is_ignoreThemeUpdates ) {
101 $theme_upgrades = array();
102 }
103
104 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
105 $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
106
107 if ( is_array( $decodedPremiumUpgrades ) ) {
108 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
109 $premiumUpgrade['premium'] = true;
110
111 if ( 'plugin' === $premiumUpgrade['type'] ) {
112 if ( ! is_array( $plugin_upgrades ) ) {
113 $plugin_upgrades = array();
114 }
115 if ( ! $website->is_ignorePluginUpdates ) {
116
117 $premiumUpgrade = array_filter( $premiumUpgrade );
118 if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
119 $plugin_upgrades[ $crrSlug ] = array();
120 }
121
122 $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
123 }
124 } elseif ( 'theme' === $premiumUpgrade['type'] ) {
125 if ( ! is_array( $theme_upgrades ) ) {
126 $theme_upgrades = array();
127 }
128 if ( ! $website->is_ignoreThemeUpdates ) {
129 $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
130 }
131 }
132 }
133 }
134
135 if ( is_array( $translation_upgrades ) ) {
136 $total_translation_upgrades += count( $translation_upgrades );
137 }
138
139 if ( is_array( $plugin_upgrades ) ) {
140 $ignored_plugins = json_decode( $website->ignored_plugins, true );
141 if ( is_array( $ignored_plugins ) ) {
142 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
143 }
144
145 $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
146 if ( is_array( $ignored_plugins ) ) {
147 $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
148 }
149
150 $total_plugin_upgrades += count( $plugin_upgrades );
151 }
152
153 if ( is_array( $theme_upgrades ) ) {
154 $ignored_themes = json_decode( $website->ignored_themes, true );
155 if ( is_array( $ignored_themes ) ) {
156 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
157 }
158
159 $ignored_themes = json_decode( $userExtension->ignored_themes, true );
160 if ( is_array( $ignored_themes ) ) {
161 $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
162 }
163
164 $total_theme_upgrades += count( $theme_upgrades );
165 }
166
167 if ( $db_updater_count ) {
168
169 $plugin_db_upgrades = ! empty( $website->plugin_db_upgrades ) ? json_decode( $website->plugin_db_upgrades, true ) : array();
170 if ( $website->is_ignorePluginUpdates ) {
171 $plugin_db_upgrades = array();
172 }
173
174 if ( is_array( $plugin_db_upgrades ) && ! $website->is_ignorePluginUpdates ) {
175 $_ignored_plugins = ! empty( $website->ignored_plugins ) ? json_decode( $website->ignored_plugins, true ) : array();
176 if ( is_array( $_ignored_plugins ) ) {
177 $plugin_db_upgrades = array_diff_key( $plugin_db_upgrades, $_ignored_plugins );
178 }
179
180 $_ignored_plugins = ! empty( $userExtension->ignored_plugins ) ? json_decode( $userExtension->ignored_plugins, true ) : array();
181 if ( is_array( $_ignored_plugins ) ) {
182 $plugin_db_upgrades = array_diff_key( $plugin_db_upgrades, $_ignored_plugins );
183 }
184
185 // supported the WC plugin.
186 if ( is_array( $plugin_db_upgrades ) ) {
187 foreach ( $supported_db_updater_plugins as $supp_slug ) {
188 if ( isset( $plugin_db_upgrades[ $supp_slug ] ) ) {
189 ++$total_plugin_db_upgrades;
190 }
191 }
192 }
193 }
194 }
195 }
196
197 // WP Upgrades part.
198 $total_upgrades = $total_wp_upgrades + $total_plugin_upgrades + $total_theme_upgrades;
199
200 // to fix incorrect total updates.
201 if ( $mainwp_show_language_updates ) {
202 $total_upgrades += $total_translation_upgrades;
203 $data = array(
204 'total' => $total_upgrades,
205 'wp' => $total_wp_upgrades,
206 'plugins' => $total_plugin_upgrades,
207 'themes' => $total_theme_upgrades,
208 'translations' => $total_translation_upgrades,
209 );
210 } else {
211 $data = array(
212 'total' => $total_upgrades,
213 'wp' => $total_wp_upgrades,
214 'plugins' => $total_plugin_upgrades,
215 'themes' => $total_theme_upgrades,
216 'translations' => 0,
217 );
218 }
219
220 if ( $db_updater_count ) {
221 $data['db_updater_count'] = $total_plugin_db_upgrades;
222 $data['total'] += $total_plugin_db_upgrades;
223 }
224 MainWP_DB::free_result( $websites );
225
226 return $data;
227 }
228 }
229
230 // End of class.
231