| @@ -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(); |
| @@ -160,14 +165,14 @@ | ||
| 160 | 165 | |
| 161 | 166 | if ( is_array( $theme_upgrades ) ) { |
| 162 | 167 | $ignored_themes = json_decode( $website->ignored_themes, true ); |
| 163 | 168 | if ( is_array( $ignored_themes ) ) { |
| 164 | - $theme_upgrades = self::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 169 | + $theme_upgrades = $this->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 165 | 170 | } |
| 166 | 171 | |
| 167 | 172 | $ignored_themes = json_decode( $this->userExtension->ignored_themes, true ); |
| 168 | 173 | if ( is_array( $ignored_themes ) ) { |
| 169 | - $theme_upgrades = self::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 174 | + $theme_upgrades = $this->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 170 | 175 | } |
| 171 | 176 | |
| 172 | 177 | $total_theme_upgrades += count( $theme_upgrades ); |
| 173 | 178 | } |
| @@ -191,12 +196,13 @@ | ||
| 191 | 196 | * @since 5.2. |
| 192 | 197 | * |
| 193 | 198 | * @param array $updates Update info. |
| 194 | 199 | * @param array $ignored Ignored update info. |
| 200 | + * @param int $count_ignored Count ignored updates. | |
| 195 | 201 | * |
| 196 | 202 | * @return array $updates Not ignored updates info. |
| 197 | 203 | */ |
| 198 | - public function get_not_ignored_updates_themesplugins( $updates, $ignored ) { //phpcs:ignore -- NOSONAR - complexity. | |
| 204 | + public function get_not_ignored_updates_themesplugins( $updates, $ignored, &$count_ignored = 0 ) { //phpcs:ignore -- NOSONAR - complexity. | |
| 199 | 205 | if ( ! is_array( $updates ) || ! is_array( $ignored ) ) { |
| 200 | 206 | return $updates; |
| 201 | 207 | } |
| 202 | 208 | $new_updates = array(); |
| @@ -202,8 +208,9 @@ | ||
| 202 | 208 | $new_updates = array(); |
| 203 | 209 | foreach ( $updates as $slug => $info ) { |
| 204 | 210 | if ( isset( $ignored[ $slug ] ) ) { |
| 205 | 211 | if ( is_string( $ignored[ $slug ] ) ) { |
| 212 | + ++$count_ignored; | |
| 206 | 213 | // old ignored info. |
| 207 | 214 | continue; // ignored update. |
| 208 | 215 | } elseif ( is_array( $ignored[ $slug ] ) && ! empty( $ignored[ $slug ]['ignored_versions'] ) ) { |
| 209 | 216 | $ignored_vers = is_array( $ignored[ $slug ]['ignored_versions'] ) ? $ignored[ $slug ]['ignored_versions'] : array(); |
| @@ -208,8 +215,9 @@ | ||
| 208 | 215 | } elseif ( is_array( $ignored[ $slug ] ) && ! empty( $ignored[ $slug ]['ignored_versions'] ) ) { |
| 209 | 216 | $ignored_vers = is_array( $ignored[ $slug ]['ignored_versions'] ) ? $ignored[ $slug ]['ignored_versions'] : array(); |
| 210 | 217 | $new_version = is_array( $info ) && isset( $info['update']['new_version'] ) ? $info['update']['new_version'] : ''; |
| 211 | 218 | if ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) { |
| 219 | + ++$count_ignored; | |
| 212 | 220 | continue; // ignored update. |
| 213 | 221 | } |
| 214 | 222 | } |
| 215 | 223 | } |
| @@ -227,19 +235,20 @@ | ||
| 227 | 235 | * @since 5.2. |
| 228 | 236 | * |
| 229 | 237 | * @param array $item Update info of theme or plugin. |
| 230 | 238 | * @param array $ignored Ignored update info. |
| 231 | - * @param string $type theme/plugin/plugintheme/core. | |
| 239 | + * @param string $type theme/plugin/core. | |
| 240 | + * @param int $count_ignored Count ignored. | |
| 232 | 241 | |
| 233 | 242 | * @return bool Ignored updates. |
| 234 | 243 | */ |
| 235 | - public function is_ignored_updates( $item, $ignored, $type = 'plugintheme' ) { //phpcs:ignore -- NOSONAR complex function. | |
| 244 | + public function is_ignored_updates( $item, $ignored, $type = 'plugin', &$count_ignored = 0 ) { //phpcs:ignore -- NOSONAR complex function. | |
| 236 | 245 | |
| 237 | 246 | if ( ! is_array( $item ) || ! is_array( $ignored ) ) { |
| 238 | 247 | return false; |
| 239 | 248 | } |
| 240 | 249 | |
| 241 | - if ( in_array( $type, array( 'plugin', 'theme', 'plugintheme' ) ) ) { | |
| 250 | + if ( in_array( $type, array( 'plugin', 'theme' ) ) ) { | |
| 242 | 251 | $item_slug = isset( $item['update'] ) && is_array( $item['update'] ) && isset( $item['update'][ $type ] ) ? $item['update'][ $type ] : ''; |
| 243 | 252 | $new_version = isset( $item['update']['new_version'] ) ? $item['update']['new_version'] : ''; |
| 244 | 253 | |
| 245 | 254 | if ( empty( $item_slug ) && ! empty( $item['slug'] ) ) { |
| @@ -250,12 +259,14 @@ | ||
| 250 | 259 | } |
| 251 | 260 | |
| 252 | 261 | if ( isset( $ignored[ $item_slug ] ) ) { |
| 253 | 262 | if ( is_string( $ignored[ $item_slug ] ) ) { // old ignore info. |
| 263 | + ++$count_ignored; | |
| 254 | 264 | return true; // ignored update. |
| 255 | 265 | } elseif ( is_array( $ignored[ $item_slug ] ) && ! empty( $ignored[ $item_slug ]['ignored_versions'] ) ) { |
| 256 | 266 | $ignored_vers = is_array( $ignored[ $item_slug ]['ignored_versions'] ) ? $ignored[ $item_slug ]['ignored_versions'] : array(); |
| 257 | 267 | if ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) { |
| 268 | + ++$count_ignored; | |
| 258 | 269 | return true; // ignored update. |
| 259 | 270 | } |
| 260 | 271 | } |
| 261 | 272 | } |
| @@ -266,8 +277,9 @@ | ||
| 266 | 277 | if ( empty( $new_version ) ) { |
| 267 | 278 | $new_version = isset( $item['new_version'] ) ? $item['new_version'] : ''; // to support some info. |
| 268 | 279 | } |
| 269 | 280 | if ( ! empty( $new_version ) && ( in_array( 'all_versions', $ignored_vers ) || in_array( $new_version, $ignored_vers ) ) ) { |
| 281 | + ++$count_ignored; | |
| 270 | 282 | return true; // ignored update. |
| 271 | 283 | } |
| 272 | 284 | } |
| 273 | 285 | return false; |