PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.3
6.3 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 All 157 releases
← All changes | class/class-mainwp-common-handler.php +160 -86 6.2 → 6.3 View file →
@@ -53,9 +53,11 @@
53 53 public function sites_available_updates_count() { // phpcs:ignore -- NOSONAR - complex function.
54 54
55 55 $cache_group = MainWP_Cache_Helper::CGR_UPDATES;
56 56
57 - $cache_key = MainWP_Cache_Helper::get_cache_key( 'updates_count', $cache_group );
57 + // Suffix changed with the shared ignore tally so a count cached before
58 + // ignore writes invalidated this group is not served for the rest of the TTL.
59 + $cache_key = MainWP_Cache_Helper::get_cache_key( 'updates_count_ignored', $cache_group );
58 60
59 61 $cache_values = MainWP_Cache_Helper::instance()->get_cache(
60 62 $cache_key,
61 63 $cache_group
@@ -100,98 +102,22 @@
100 102
101 103 MainWP_DB::data_seek( $websites, 0 );
102 104
103 105 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
104 - $wp_upgrades = ! empty( $website->wp_upgrades ) ? json_decode( $website->wp_upgrades, true ) : array();
105 - $ignored_core_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
106 -
107 - 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' ) ) {
108 - $wp_upgrades = array();
109 - }
110 -
111 - if ( is_array( $wp_upgrades ) && ! empty( $wp_upgrades ) ) {
112 - ++$total_wp_upgrades;
113 - }
114 -
115 - $translation_upgrades = json_decode( $website->translation_upgrades, true );
116 -
117 - if ( ! empty( $website->ignored_trans_updates ) ) {
118 - $translation_upgrades = array();
119 - }
120 -
121 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
122 - if ( $website->is_ignorePluginUpdates ) {
123 - $plugin_upgrades = array();
124 - }
125 -
126 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
127 - if ( $website->is_ignoreThemeUpdates ) {
128 - $theme_upgrades = array();
129 - }
130 -
131 106 $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' );
132 - $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array();
133 -
134 - if ( is_array( $decodedPremiumUpgrades ) ) {
135 - foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
136 - $premiumUpgrade['premium'] = true;
137 -
138 - if ( 'plugin' === $premiumUpgrade['type'] ) {
139 - if ( ! is_array( $plugin_upgrades ) ) {
140 - $plugin_upgrades = array();
141 - }
142 - if ( ! $website->is_ignorePluginUpdates ) {
143 -
144 - $premiumUpgrade = array_filter( $premiumUpgrade );
145 - if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) {
146 - continue;
147 - }
148 -
149 - $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade );
150 - }
151 - } elseif ( 'theme' === $premiumUpgrade['type'] ) {
152 - if ( ! is_array( $theme_upgrades ) ) {
153 - $theme_upgrades = array();
154 - }
155 - if ( ! $website->is_ignoreThemeUpdates ) {
156 - $theme_upgrades[ $crrSlug ] = $premiumUpgrade;
157 - }
158 - }
159 - }
107 + if ( empty( $decodedPremiumUpgrades ) ) {
108 + $decodedPremiumUpgrades = array();
109 + } else {
110 + $decodedPremiumUpgrades = json_decode( $decodedPremiumUpgrades, true );
160 111 }
161 112
162 - if ( is_array( $translation_upgrades ) ) {
163 - $total_translation_upgrades += count( $translation_upgrades );
164 - }
113 + $tally = self::tally_site_available_updates( $website, $userExtension, $decodedIgnoredCores, $decodedPremiumUpgrades );
165 114
166 - if ( is_array( $plugin_upgrades ) ) {
167 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
168 - if ( is_array( $ignored_plugins ) ) {
169 - $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
170 - }
115 + $total_wp_upgrades += $tally['wp'];
116 + $total_plugin_upgrades += $tally['plugins'];
117 + $total_translation_upgrades += $tally['translations'];
118 + $total_theme_upgrades += $tally['themes'];
171 119
172 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
173 - if ( is_array( $ignored_plugins ) ) {
174 - $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
175 - }
176 -
177 - $total_plugin_upgrades += count( $plugin_upgrades );
178 - }
179 -
180 - if ( is_array( $theme_upgrades ) ) {
181 - $ignored_themes = json_decode( $website->ignored_themes, true );
182 - if ( is_array( $ignored_themes ) ) {
183 - $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
184 - }
185 -
186 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
187 - if ( is_array( $ignored_themes ) ) {
188 - $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
189 - }
190 -
191 - $total_theme_upgrades += count( $theme_upgrades );
192 - }
193 -
194 120 if ( $db_updater_count ) {
195 121
196 122 $plugin_db_upgrades = ! empty( $website->plugin_db_upgrades ) ? json_decode( $website->plugin_db_upgrades, true ) : array();
197 123 if ( $website->is_ignorePluginUpdates ) {
@@ -255,8 +181,156 @@
255 181
256 182 return $data;
257 183 }
258 184
185 +
186 + /**
187 + * Count one site's available updates the same way the Available Updates tables do.
188 + *
189 + * Per-site ignore toggles, per-version core ignores, and per-site or global
190 + * plugin/theme ignores are applied before the counts are returned. The filtered
191 + * lists are what the per-item update views aggregate.
192 + *
193 + * @param object $website Child site row.
194 + * @param object $user_extension Current user extension row.
195 + * @param array $global_ignored_cores Decoded global ignored core versions.
196 + * @param array $premium_upgrades Decoded premium upgrades for the site.
197 + *
198 + * @return array {
199 + * @type int $wp Core updates, 0 or 1.
200 + * @type int $plugins Plugin updates after ignore rules.
201 + * @type int $themes Theme updates after ignore rules.
202 + * @type int $translations Translation updates after the site toggle.
203 + * @type array $plugin_upgrades Filtered plugin upgrade list.
204 + * @type array $theme_upgrades Filtered theme upgrade list.
205 + * @type array $translation_upgrades Filtered translation upgrade list.
206 + * }
207 + */
208 + public static function tally_site_available_updates( $website, $user_extension, $global_ignored_cores, $premium_upgrades ) { // phpcs:ignore -- NOSONAR - shared with the updates page tally.
209 +
210 + if ( ! is_array( $global_ignored_cores ) ) {
211 + $global_ignored_cores = array();
212 + }
213 + if ( ! is_array( $premium_upgrades ) ) {
214 + $premium_upgrades = array();
215 + }
216 +
217 + $wp_upgrades = array();
218 + if ( ! empty( $website->wp_upgrades ) ) {
219 + $decoded_wp = json_decode( $website->wp_upgrades, true );
220 + if ( is_array( $decoded_wp ) ) {
221 + $wp_upgrades = $decoded_wp;
222 + }
223 + }
224 +
225 + $ignored_core_upgrades = array();
226 + if ( ! empty( $website->ignored_wp_upgrades ) ) {
227 + $decoded_ignored_cores = json_decode( $website->ignored_wp_upgrades, true );
228 + if ( is_array( $decoded_ignored_cores ) ) {
229 + $ignored_core_upgrades = $decoded_ignored_cores;
230 + }
231 + }
232 +
233 + $common = MainWP_Common_Functions::instance();
234 + if ( $website->is_ignoreCoreUpdates || $common->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) || $common->is_ignored_updates( $wp_upgrades, $global_ignored_cores, 'core' ) ) {
235 + $wp_upgrades = array();
236 + }
237 +
238 + $wp_count = 0;
239 + if ( ! empty( $wp_upgrades ) ) {
240 + $wp_count = 1;
241 + }
242 +
243 + $translation_upgrades = json_decode( $website->translation_upgrades, true );
244 + if ( ! empty( $website->ignored_trans_updates ) ) {
245 + $translation_upgrades = array();
246 + }
247 +
248 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
249 + if ( $website->is_ignorePluginUpdates ) {
250 + $plugin_upgrades = array();
251 + }
252 +
253 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
254 + if ( $website->is_ignoreThemeUpdates ) {
255 + $theme_upgrades = array();
256 + }
257 +
258 + foreach ( $premium_upgrades as $crr_slug => $premium_upgrade ) {
259 + $premium_upgrade['premium'] = true;
260 +
261 + if ( 'plugin' === $premium_upgrade['type'] ) {
262 + if ( ! is_array( $plugin_upgrades ) ) {
263 + $plugin_upgrades = array();
264 + }
265 + if ( ! $website->is_ignorePluginUpdates ) {
266 + $premium_upgrade = array_filter( $premium_upgrade );
267 + if ( ! isset( $plugin_upgrades[ $crr_slug ] ) ) {
268 + continue;
269 + }
270 + $plugin_upgrades[ $crr_slug ] = array_merge( $plugin_upgrades[ $crr_slug ], $premium_upgrade );
271 + }
272 + } elseif ( 'theme' === $premium_upgrade['type'] ) {
273 + if ( ! is_array( $theme_upgrades ) ) {
274 + $theme_upgrades = array();
275 + }
276 + if ( ! $website->is_ignoreThemeUpdates ) {
277 + $theme_upgrades[ $crr_slug ] = $premium_upgrade;
278 + }
279 + }
280 + }
281 +
282 + $translation_count = 0;
283 + if ( is_array( $translation_upgrades ) ) {
284 + $translation_count = count( $translation_upgrades );
285 + } else {
286 + $translation_upgrades = array();
287 + }
288 +
289 + $plugin_count = 0;
290 + if ( is_array( $plugin_upgrades ) && ! $website->is_ignorePluginUpdates ) {
291 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
292 + if ( is_array( $ignored_plugins ) ) {
293 + $plugin_upgrades = $common->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
294 + }
295 +
296 + $ignored_plugins = json_decode( $user_extension->ignored_plugins, true );
297 + if ( is_array( $ignored_plugins ) ) {
298 + $plugin_upgrades = $common->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
299 + }
300 + $plugin_count = count( $plugin_upgrades );
301 + }
302 + if ( ! is_array( $plugin_upgrades ) ) {
303 + $plugin_upgrades = array();
304 + }
305 +
306 + $theme_count = 0;
307 + if ( is_array( $theme_upgrades ) ) {
308 + $ignored_themes = json_decode( $website->ignored_themes, true );
309 + if ( is_array( $ignored_themes ) ) {
310 + $theme_upgrades = $common->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
311 + }
312 +
313 + $ignored_themes = json_decode( $user_extension->ignored_themes, true );
314 + if ( is_array( $ignored_themes ) ) {
315 + $theme_upgrades = $common->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
316 + }
317 + $theme_count = count( $theme_upgrades );
318 + }
319 + if ( ! is_array( $theme_upgrades ) ) {
320 + $theme_upgrades = array();
321 + }
322 +
323 + return array(
324 + 'wp' => $wp_count,
325 + 'plugins' => $plugin_count,
326 + 'themes' => $theme_count,
327 + 'translations' => $translation_count,
328 + 'plugin_upgrades' => $plugin_upgrades,
329 + 'theme_upgrades' => $theme_upgrades,
330 + 'translation_upgrades' => $translation_upgrades,
331 + );
332 + }
259 333
260 334 /**
261 335 * Method get_not_ignored_updates_plugins_db().
262 336 *