PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
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 5.2.1 All 155 releases
← All changes | class/class-mainwp-common-functions.php +124 -11 5.1 → 6.2.1 View file →
@@ -6,8 +6,13 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Common_Functions
12 17 *
13 18 * @package MainWP\Dashboard
@@ -32,9 +37,9 @@
32 37 * Method get_class_name()
33 38 *
34 39 * Get Class Name.
35 40 *
36 - * @return object
41 + * @return string
37 42 */
38 43 public static function get_class_name() {
39 44 return __CLASS__;
40 45 }
@@ -44,9 +49,9 @@
44 49 *
45 50 * Create public static instance.
46 51 *
47 52 * @static
48 - * @return MainWP_DB_Common
53 + * @return MainWP_Common_Functions
49 54 */
50 55 public static function instance() {
51 56 if ( null === static::$instance ) {
52 57 static::$instance = new self();
@@ -77,10 +82,21 @@
77 82 * @uses \MainWP\Dashboard\MainWP_DB::instance()::get_website_options_array()
78 83 */
79 84 public function get_available_update_siteids() { // phpcs:ignore -- NOSONAR - complex function. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
80 85 $site_ids = array();
81 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() );
82 86
87 + $params = array(
88 + 'view' => 'updates_view',
89 + 'others_fields' => array( 'premium_upgrades' ),
90 + );
91 +
92 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user_by_params( $params ) );
93 +
94 + $decodedIgnoredCores = ! empty( $this->userExtension->ignored_wp_upgrades ) ? json_decode( $this->userExtension->ignored_wp_upgrades, true ) : array();
95 + if ( ! is_array( $decodedIgnoredCores ) ) {
96 + $decodedIgnoredCores = array();
97 + }
98 +
83 99 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
84 100 $hasSyncErrors = ( '' !== $website->sync_errors );
85 101 $cnt = 0;
86 102 if ( 1 === (int) $website->offline_check_result && ! $hasSyncErrors ) {
@@ -87,12 +103,12 @@
87 103 $total_wp_upgrades = 0;
88 104 $total_plugin_upgrades = 0;
89 105 $total_theme_upgrades = 0;
90 106
91 - $site_options = MainWP_DB::instance()->get_website_options_array( $website, array( 'wp_upgrades', 'premium_upgrades' ) );
92 - $wp_upgrades = isset( $site_options['wp_upgrades'] ) && ! empty( $site_options['wp_upgrades'] ) ? json_decode( $site_options['wp_upgrades'], true ) : array();
107 + $wp_upgrades = isset( $website->wp_upgrades ) && ! empty( $website->wp_upgrades ) ? json_decode( $website->wp_upgrades, true ) : array();
108 + $ignored_core_upgrades = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array();
93 109
94 - if ( $website->is_ignoreCoreUpdates ) {
110 + if ( $website->is_ignoreCoreUpdates || $this->is_ignored_updates( $wp_upgrades, $ignored_core_upgrades, 'core' ) || $this->is_ignored_updates( $wp_upgrades, $decodedIgnoredCores, 'core' ) ) {
95 111 $wp_upgrades = array();
96 112 }
97 113
98 114 if ( is_array( $wp_upgrades ) && ! empty( $wp_upgrades ) ) {
@@ -108,9 +124,9 @@
108 124 if ( $website->is_ignoreThemeUpdates ) {
109 125 $theme_upgrades = array();
110 126 }
111 127
112 - $decodedPremiumUpgrades = isset( $site_options['premium_upgrades'] ) ? json_decode( $site_options['premium_upgrades'], true ) : array();
128 + $decodedPremiumUpgrades = ! empty( $website->premium_upgrades ) ? json_decode( $website->premium_upgrades, true ) : array();
113 129
114 130 if ( is_array( $decodedPremiumUpgrades ) ) {
115 131 foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) {
116 132 $premiumUpgrade['premium'] = true;
@@ -135,14 +151,14 @@
135 151
136 152 if ( is_array( $plugin_upgrades ) ) {
137 153 $ignored_plugins = json_decode( $website->ignored_plugins, true );
138 154 if ( is_array( $ignored_plugins ) ) {
139 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
155 + $plugin_upgrades = $this->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
140 156 }
141 157
142 158 $ignored_plugins = json_decode( $this->userExtension->ignored_plugins, true );
143 159 if ( is_array( $ignored_plugins ) ) {
144 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
160 + $plugin_upgrades = $this->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
145 161 }
146 162
147 163 $total_plugin_upgrades += count( $plugin_upgrades );
148 164 }
@@ -149,14 +165,14 @@
149 165
150 166 if ( is_array( $theme_upgrades ) ) {
151 167 $ignored_themes = json_decode( $website->ignored_themes, true );
152 168 if ( is_array( $ignored_themes ) ) {
153 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
169 + $theme_upgrades = $this->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
154 170 }
155 171
156 172 $ignored_themes = json_decode( $this->userExtension->ignored_themes, true );
157 173 if ( is_array( $ignored_themes ) ) {
158 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
174 + $theme_upgrades = $this->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
159 175 }
160 176
161 177 $total_theme_upgrades += count( $theme_upgrades );
162 178 }
@@ -169,6 +185,103 @@
169 185 }
170 186 }
171 187
172 188 return $site_ids;
189 + }
190 +
191 + /**
192 + * Method get_not_ignored_updates_themesplugins().
193 + *
194 + * To compatible with new ignored update info.
195 + *
196 + * @since 5.2.
197 + *
198 + * @param array $updates Update info.
199 + * @param array $ignored Ignored update info.
200 + * @param int $count_ignored Count ignored updates.
201 + *
202 + * @return array $updates Not ignored updates info.
203 + */
204 + public function get_not_ignored_updates_themesplugins( $updates, $ignored, &$count_ignored = 0 ) { //phpcs:ignore -- NOSONAR - complexity.
205 + if ( ! is_array( $updates ) || ! is_array( $ignored ) ) {
206 + return $updates;
207 + }
208 + $new_updates = array();
209 + foreach ( $updates as $slug => $info ) {
210 + if ( isset( $ignored[ $slug ] ) ) {
211 + if ( is_string( $ignored[ $slug ] ) ) {
212 + ++$count_ignored;
213 + // old ignored info.
214 + continue; // ignored update.
215 + } elseif ( is_array( $ignored[ $slug ] ) && ! empty( $ignored[ $slug ]['ignored_versions'] ) ) {
216 + $ignored_vers = is_array( $ignored[ $slug ]['ignored_versions'] ) ? $ignored[ $slug ]['ignored_versions'] : array();
217 + $new_version = is_array( $info ) && isset( $info['update']['new_version'] ) ? $info['update']['new_version'] : '';
218 + if ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) {
219 + ++$count_ignored;
220 + continue; // ignored update.
221 + }
222 + }
223 + }
224 + $new_updates[ $slug ] = $info;
225 + }
226 + return $new_updates;
227 + }
228 +
229 +
230 + /**
231 + * Method is_ignored_updates().
232 + *
233 + * To compatible with new ignored update info.
234 + *
235 + * @since 5.2.
236 + *
237 + * @param array $item Update info of theme or plugin.
238 + * @param array $ignored Ignored update info.
239 + * @param string $type theme/plugin/core.
240 + * @param int $count_ignored Count ignored.
241 +
242 + * @return bool Ignored updates.
243 + */
244 + public function is_ignored_updates( $item, $ignored, $type = 'plugin', &$count_ignored = 0 ) { //phpcs:ignore -- NOSONAR complex function.
245 +
246 + if ( ! is_array( $item ) || ! is_array( $ignored ) ) {
247 + return false;
248 + }
249 +
250 + if ( in_array( $type, array( 'plugin', 'theme' ) ) ) {
251 + $item_slug = isset( $item['update'] ) && is_array( $item['update'] ) && isset( $item['update'][ $type ] ) ? $item['update'][ $type ] : '';
252 + $new_version = isset( $item['update']['new_version'] ) ? $item['update']['new_version'] : '';
253 +
254 + if ( empty( $item_slug ) && ! empty( $item['slug'] ) ) {
255 + $item_slug = $item['slug']; // for data of plugin/theme of site.
256 + }
257 + if ( empty( $new_version ) && ! empty( $item['new_version'] ) ) {
258 + $new_version = $item['new_version']; // for data of plugin/theme of site.
259 + }
260 +
261 + if ( isset( $ignored[ $item_slug ] ) ) {
262 + if ( is_string( $ignored[ $item_slug ] ) ) { // old ignore info.
263 + ++$count_ignored;
264 + return true; // ignored update.
265 + } elseif ( is_array( $ignored[ $item_slug ] ) && ! empty( $ignored[ $item_slug ]['ignored_versions'] ) ) {
266 + $ignored_vers = is_array( $ignored[ $item_slug ]['ignored_versions'] ) ? $ignored[ $item_slug ]['ignored_versions'] : array();
267 + if ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) {
268 + ++$count_ignored;
269 + return true; // ignored update.
270 + }
271 + }
272 + }
273 + return false;
274 + } elseif ( 'core' === $type ) {
275 + $ignored_vers = isset( $ignored['ignored_versions'] ) && is_array( $ignored['ignored_versions'] ) ? $ignored['ignored_versions'] : array();
276 + $new_version = isset( $item['new'] ) ? $item['new'] : '';
277 + if ( empty( $new_version ) ) {
278 + $new_version = isset( $item['new_version'] ) ? $item['new_version'] : ''; // to support some info.
279 + }
280 + if ( ! empty( $new_version ) && ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) ) {
281 + ++$count_ignored;
282 + return true; // ignored update.
283 + }
284 + }
285 + return false;
173 286 }
174 287 }