| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Updates Handler. |
| 4 |
* |
| 5 |
* @package MainWP/Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace MainWP\Dashboard; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class MainWP_Updates_Handler |
| 12 |
* |
| 13 |
* @package MainWP\Dashboard |
| 14 |
*/ |
| 15 |
class MainWP_Updates_Handler { |
| 16 |
|
| 17 |
/** |
| 18 |
* Get Class Name |
| 19 |
* |
| 20 |
* @return string __CLASS__ |
| 21 |
*/ |
| 22 |
public static function get_class_name() { |
| 23 |
return __CLASS__; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Method upgrade_site() |
| 28 |
* |
| 29 |
* Check Child Site ID & Update. |
| 30 |
* |
| 31 |
* @param int $id Child site ID. |
| 32 |
* |
| 33 |
* @return string |
| 34 |
* @throws MainWP_Exception Error messages. |
| 35 |
* |
| 36 |
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() |
| 37 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 38 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_option() |
| 39 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 40 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 41 |
*/ |
| 42 |
public static function upgrade_site( $id ) { |
| 43 |
if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { |
| 44 |
|
| 45 |
$website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 46 |
|
| 47 |
if ( MainWP_System_Utility::is_suspended_site( $website ) ) { |
| 48 |
throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 49 |
} |
| 50 |
|
| 51 |
$information = self::upgrade_website( $website ); |
| 52 |
|
| 53 |
if ( is_array( $information ) ) { |
| 54 |
if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { |
| 55 |
MainWP_DB::instance()->update_website_option( $website, 'wp_upgrades', wp_json_encode( array() ) ); |
| 56 |
do_action( 'mainwp_after_upgrade_wp_success', $website, $information ); |
| 57 |
return '<i class="green check icon"></i>'; |
| 58 |
} elseif ( isset( $information['upgrade'] ) ) { |
| 59 |
$errorMsg = ''; |
| 60 |
if ( 'LOCALIZATION' === $information['upgrade'] ) { |
| 61 |
$errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No update found for the set locale.', 'mainwp' ); |
| 62 |
} elseif ( 'NORESPONSE' === $information['upgrade'] ) { |
| 63 |
$errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No response from the child site server.', 'mainwp' ); |
| 64 |
} |
| 65 |
throw new MainWP_Exception( 'WPERROR', $errorMsg ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 66 |
} elseif ( isset( $information['error'] ) ) { |
| 67 |
throw new MainWP_Exception( 'WPERROR', esc_html( $information['error'] ) ); |
| 68 |
} else { |
| 69 |
throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ) ); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Method upgrade_website() |
| 79 |
* |
| 80 |
* Update WP for site. |
| 81 |
* |
| 82 |
* @param object $website Child site object. |
| 83 |
* |
| 84 |
* @return mixed|false update result or false. |
| 85 |
* @throws MainWP_Exception Error message. |
| 86 |
* |
| 87 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 88 |
*/ |
| 89 |
public static function upgrade_website( $website ) { |
| 90 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 91 |
|
| 92 |
$wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $website ); |
| 93 |
if ( ! empty( $wpcore_update_disabled_by ) ) { |
| 94 |
throw new MainWP_Exception( 'ERROR', $wpcore_update_disabled_by ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 95 |
} |
| 96 |
/** |
| 97 |
* Action: mainwp_before_wp_update |
| 98 |
* |
| 99 |
* Fires before WP update. |
| 100 |
* |
| 101 |
* @since 4.1 |
| 102 |
*/ |
| 103 |
do_action( 'mainwp_before_wp_update', $website ); |
| 104 |
|
| 105 |
$information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); |
| 106 |
|
| 107 |
// logging feature. |
| 108 |
$error = ''; |
| 109 |
$success = false; |
| 110 |
|
| 111 |
if ( is_array( $information ) ) { |
| 112 |
if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { |
| 113 |
$success = true; |
| 114 |
} elseif ( isset( $information['upgrade'] ) ) { |
| 115 |
$errorMsg = ''; |
| 116 |
if ( 'LOCALIZATION' === $information['upgrade'] ) { |
| 117 |
$error = esc_html__( 'No update found for the set locale.', 'mainwp' ); |
| 118 |
} elseif ( 'NORESPONSE' === $information['upgrade'] ) { |
| 119 |
$error = esc_html__( 'No response from the child site server.', 'mainwp' ); |
| 120 |
} |
| 121 |
} elseif ( isset( $information['error'] ) ) { |
| 122 |
$error = esc_html( $information['error'] ); |
| 123 |
} else { |
| 124 |
$error = esc_html__( 'Invalid response from child site.', 'mainwp' ); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
$output_array = array( |
| 129 |
'old_version' => isset( $information['old_version'] ) ? $information['old_version'] : '', |
| 130 |
'version' => isset( $information['version'] ) ? $information['version'] : '', |
| 131 |
'success' => $success ? 1 : 0, |
| 132 |
'error' => $error, |
| 133 |
); |
| 134 |
mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); |
| 135 |
|
| 136 |
/** |
| 137 |
* Action: mainwp_after_wp_update |
| 138 |
* |
| 139 |
* Fires after WP update. |
| 140 |
* |
| 141 |
* @since 4.1 |
| 142 |
*/ |
| 143 |
do_action( 'mainwp_after_wp_update', $information, $website ); |
| 144 |
|
| 145 |
return $information; |
| 146 |
} |
| 147 |
return false; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Add a plugin or theme to the ignor list. |
| 152 |
* |
| 153 |
* @param mixed $type plugin|theme. |
| 154 |
* @param mixed $slug Plugin or Theme Slug. |
| 155 |
* @param mixed $name Plugin or Theme Name. |
| 156 |
* @param mixed $id Child Site ID. |
| 157 |
* |
| 158 |
* @return string success. |
| 159 |
* |
| 160 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 161 |
* @uses \MainWP\Dashboard\MainWP_DB::update_website_values() |
| 162 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 163 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 164 |
*/ |
| 165 |
public static function ignore_plugin_theme( $type, $slug, $name, $id ) { |
| 166 |
if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { |
| 167 |
$website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 168 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 169 |
$slug = urldecode( $slug ); |
| 170 |
if ( 'plugin' === $type ) { |
| 171 |
$decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); |
| 172 |
if ( ! isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 173 |
|
| 174 |
/** |
| 175 |
* Action: mainwp_before_plugin_ignore |
| 176 |
* |
| 177 |
* Fires before plugin ignore. |
| 178 |
* |
| 179 |
* @since 4.1 |
| 180 |
*/ |
| 181 |
do_action( 'mainwp_before_plugin_ignore', $decodedIgnoredPlugins, $website ); |
| 182 |
|
| 183 |
$decodedIgnoredPlugins[ $slug ] = urldecode( $name ); |
| 184 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); |
| 185 |
|
| 186 |
/** |
| 187 |
* Action: mainwp_after_plugin_ignore |
| 188 |
* |
| 189 |
* Fires after plugin ignore. |
| 190 |
* |
| 191 |
* @since 4.1 |
| 192 |
*/ |
| 193 |
do_action( 'mainwp_after_plugin_ignore', $decodedIgnoredPlugins, $website ); |
| 194 |
|
| 195 |
} |
| 196 |
} elseif ( 'theme' === $type ) { |
| 197 |
$decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); |
| 198 |
if ( ! isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| 199 |
/** |
| 200 |
* Action: mainwp_before_theme_ignore |
| 201 |
* |
| 202 |
* Fires before theme ignore. |
| 203 |
* |
| 204 |
* @since 4.1 |
| 205 |
*/ |
| 206 |
do_action( 'mainwp_before_theme_ignore', $decodedIgnoredThemes, $website ); |
| 207 |
|
| 208 |
$decodedIgnoredThemes[ $slug ] = urldecode( $name ); |
| 209 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); |
| 210 |
|
| 211 |
/** |
| 212 |
* Action: mainwp_after_theme_ignore |
| 213 |
* |
| 214 |
* Fires after theme ignore. |
| 215 |
* |
| 216 |
* @since 4.1 |
| 217 |
*/ |
| 218 |
do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes ); |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
return 'success'; |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Remove a plugin or theme from the ignore list. |
| 229 |
* |
| 230 |
* @param mixed $type plugin|theme. |
| 231 |
* @param mixed $slug Plugin or Theme slug. |
| 232 |
* @param mixed $id Plugin or Theme name. |
| 233 |
* |
| 234 |
* @return string success. |
| 235 |
* |
| 236 |
* @uses \MainWP\Dashboard\MainWP_DB::query() |
| 237 |
* @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() |
| 238 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 239 |
* @uses \MainWP\Dashboard\MainWP_DB::update_website_values() |
| 240 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_object() |
| 241 |
* @uses \MainWP\Dashboard\MainWP_DB::free_result() |
| 242 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 243 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 244 |
*/ |
| 245 |
public static function unignore_plugin_theme( $type, $slug, $id ) { |
| 246 |
if ( ! empty( $id ) ) { |
| 247 |
|
| 248 |
/** |
| 249 |
* Action: mainwp_before_plugin_theme_unignore |
| 250 |
* |
| 251 |
* Fires after plugin/theme unignore. |
| 252 |
* |
| 253 |
* @since 4.1 |
| 254 |
*/ |
| 255 |
do_action( 'mainwp_before_plugin_theme_unignore', $type, $slug, $id ); |
| 256 |
|
| 257 |
if ( '_ALL_' === $id ) { |
| 258 |
$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); |
| 259 |
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { |
| 260 |
if ( 'plugin' === $type ) { |
| 261 |
|
| 262 |
/** |
| 263 |
* Action: mainwp_before_plugin_unignore |
| 264 |
* |
| 265 |
* Fires before plugin unignore. |
| 266 |
* |
| 267 |
* @since 4.1 |
| 268 |
*/ |
| 269 |
do_action( 'mainwp_before_plugin_unignore', array(), $website ); |
| 270 |
|
| 271 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( array() ) ) ); |
| 272 |
|
| 273 |
/** |
| 274 |
* Action: mainwp_after_plugin_unignore |
| 275 |
* |
| 276 |
* Fires after plugin unignore. |
| 277 |
* |
| 278 |
* @since 4.1 |
| 279 |
*/ |
| 280 |
do_action( 'mainwp_after_plugin_unignore', array(), $website ); |
| 281 |
|
| 282 |
} elseif ( 'theme' === $type ) { |
| 283 |
/** |
| 284 |
* Action: mainwp_before_theme_unignore |
| 285 |
* |
| 286 |
* Fires before theme unignore. |
| 287 |
* |
| 288 |
* @since 4.1 |
| 289 |
*/ |
| 290 |
do_action( 'mainwp_before_theme_unignore', array(), $website ); |
| 291 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( array() ) ) ); |
| 292 |
|
| 293 |
/** |
| 294 |
* Action: mainwp_after_theme_unignore |
| 295 |
* |
| 296 |
* Fires after theme unignore. |
| 297 |
* |
| 298 |
* @since 4.1 |
| 299 |
*/ |
| 300 |
do_action( 'mainwp_after_theme_unignore', array(), $website ); |
| 301 |
} |
| 302 |
} |
| 303 |
MainWP_DB::free_result( $websites ); |
| 304 |
} elseif ( MainWP_Utility::ctype_digit( $id ) ) { |
| 305 |
$website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 306 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 307 |
$slug = urldecode( $slug ); |
| 308 |
if ( 'plugin' === $type ) { |
| 309 |
$decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); |
| 310 |
if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 311 |
|
| 312 |
/** |
| 313 |
* Action: mainwp_before_plugin_unignore |
| 314 |
* |
| 315 |
* Fires before plugin unignore. |
| 316 |
* |
| 317 |
* @since 4.1 |
| 318 |
*/ |
| 319 |
do_action( 'mainwp_before_plugin_unignore', $decodedIgnoredPlugins, $website ); |
| 320 |
|
| 321 |
unset( $decodedIgnoredPlugins[ $slug ] ); |
| 322 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); |
| 323 |
|
| 324 |
/** |
| 325 |
* Action: mainwp_after_plugin_unignore |
| 326 |
* |
| 327 |
* Fires after plugin unignore. |
| 328 |
* |
| 329 |
* @since 4.1 |
| 330 |
*/ |
| 331 |
do_action( 'mainwp_after_plugin_unignore', $decodedIgnoredPlugins, $website ); |
| 332 |
} |
| 333 |
} elseif ( 'theme' === $type ) { |
| 334 |
$decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); |
| 335 |
if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| 336 |
|
| 337 |
/** |
| 338 |
* Action: mainwp_before_theme_unignore |
| 339 |
* |
| 340 |
* Fires before theme unignore. |
| 341 |
* |
| 342 |
* @since 4.1 |
| 343 |
*/ |
| 344 |
do_action( 'mainwp_before_theme_unignore', $decodedIgnoredThemes, $website ); |
| 345 |
|
| 346 |
unset( $decodedIgnoredThemes[ $slug ] ); |
| 347 |
MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); |
| 348 |
|
| 349 |
/** |
| 350 |
* Action: mainwp_after_theme_unignore |
| 351 |
* |
| 352 |
* Fires after theme unignore. |
| 353 |
* |
| 354 |
* @since 4.1 |
| 355 |
*/ |
| 356 |
do_action( 'mainwp_after_theme_unignore', $decodedIgnoredThemes, $website ); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
return 'success'; |
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Method ignore_plugins_themes() |
| 368 |
* |
| 369 |
* Ignore Plugins or Themes. |
| 370 |
* |
| 371 |
* @param string $type Plugin or theme. |
| 372 |
* @param string $slug Plugin or tempheme slug. |
| 373 |
* @param string $name Plugin or theme name. |
| 374 |
* |
| 375 |
* @return string 'success'. |
| 376 |
* |
| 377 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 378 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() |
| 379 |
*/ |
| 380 |
public static function ignore_plugins_themes( $type, $slug, $name ) { |
| 381 |
$slug = urldecode( $slug ); |
| 382 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 383 |
if ( 'plugin' === $type ) { |
| 384 |
$decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); |
| 385 |
if ( ! is_array( $decodedIgnoredPlugins ) ) { |
| 386 |
$decodedIgnoredPlugins = array(); |
| 387 |
} |
| 388 |
$decodedIgnoredPlugins[ $slug ] = urldecode( $name ); |
| 389 |
MainWP_DB_Common::instance()->update_user_extension( |
| 390 |
array( |
| 391 |
'userid' => null, |
| 392 |
'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), |
| 393 |
) |
| 394 |
); |
| 395 |
} elseif ( 'theme' === $type ) { |
| 396 |
$decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true ); |
| 397 |
if ( ! is_array( $decodedIgnoredThemes ) ) { |
| 398 |
$decodedIgnoredThemes = array(); |
| 399 |
} |
| 400 |
$decodedIgnoredThemes[ $slug ] = urldecode( $name ); |
| 401 |
MainWP_DB_Common::instance()->update_user_extension( |
| 402 |
array( |
| 403 |
'userid' => null, |
| 404 |
'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), |
| 405 |
) |
| 406 |
); |
| 407 |
} |
| 408 |
|
| 409 |
return 'success'; |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Unignore Plugins or Themes. |
| 414 |
* |
| 415 |
* @param mixed $type plugin|themes. |
| 416 |
* @param mixed $slug Plugin or Themes slug. |
| 417 |
* |
| 418 |
* @return string success. |
| 419 |
* |
| 420 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 421 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() |
| 422 |
*/ |
| 423 |
public static function unignore_plugins_themes( $type, $slug ) { |
| 424 |
$slug = urldecode( $slug ); |
| 425 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 426 |
if ( 'plugin' === $type ) { |
| 427 |
if ( '_ALL_' === $slug ) { |
| 428 |
$decodedIgnoredPlugins = array(); |
| 429 |
} else { |
| 430 |
$decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); |
| 431 |
if ( ! is_array( $decodedIgnoredPlugins ) ) { |
| 432 |
$decodedIgnoredPlugins = array(); |
| 433 |
} |
| 434 |
if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 435 |
unset( $decodedIgnoredPlugins[ $slug ] ); |
| 436 |
} |
| 437 |
} |
| 438 |
MainWP_DB_Common::instance()->update_user_extension( |
| 439 |
array( |
| 440 |
'userid' => null, |
| 441 |
'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), |
| 442 |
) |
| 443 |
); |
| 444 |
} elseif ( 'theme' === $type ) { |
| 445 |
if ( '_ALL_' === $slug ) { |
| 446 |
$decodedIgnoredThemes = array(); |
| 447 |
} else { |
| 448 |
$decodedIgnoredThemes = json_decode( $userExtension->ignored_plugins, true ); |
| 449 |
if ( ! is_array( $decodedIgnoredThemes ) ) { |
| 450 |
$decodedIgnoredThemes = array(); |
| 451 |
} |
| 452 |
if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| 453 |
unset( $decodedIgnoredThemes[ $slug ] ); |
| 454 |
} |
| 455 |
} |
| 456 |
MainWP_DB_Common::instance()->update_user_extension( |
| 457 |
array( |
| 458 |
'userid' => null, |
| 459 |
'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), |
| 460 |
) |
| 461 |
); |
| 462 |
} |
| 463 |
|
| 464 |
return 'success'; |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
/** |
| 469 |
* Unignor abandoned plugins or themes. |
| 470 |
* |
| 471 |
* @param mixed $type plugin|themes. |
| 472 |
* @param mixed $slug Plugin or Themes slug. |
| 473 |
* @param mixed $id Child Site ID. |
| 474 |
* |
| 475 |
* @return string success. |
| 476 |
* |
| 477 |
* @uses \MainWP\Dashboard\MainWP_DB::query() |
| 478 |
* @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() |
| 479 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 480 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_option() |
| 481 |
* @uses \MainWP\Dashboard\MainWP_DB::update_website_option() |
| 482 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_object() |
| 483 |
* @uses \MainWP\Dashboard\MainWP_DB::free_result() |
| 484 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 485 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 486 |
*/ |
| 487 |
public static function unignore_abandoned_plugin_theme( $type, $slug, $id ) { |
| 488 |
if ( isset( $id ) ) { |
| 489 |
if ( '_ALL_' === $id ) { |
| 490 |
$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); |
| 491 |
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { |
| 492 |
if ( 'plugin' === $type ) { |
| 493 |
MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( array() ) ); |
| 494 |
} elseif ( 'theme' === $type ) { |
| 495 |
MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( array() ) ); |
| 496 |
} |
| 497 |
} |
| 498 |
MainWP_DB::free_result( $websites ); |
| 499 |
} elseif ( MainWP_Utility::ctype_digit( $id ) ) { |
| 500 |
$website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 501 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 502 |
$slug = urldecode( $slug ); |
| 503 |
if ( 'plugin' === $type ) { |
| 504 |
$decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); |
| 505 |
$decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array(); |
| 506 |
|
| 507 |
if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 508 |
unset( $decodedIgnoredPlugins[ $slug ] ); |
| 509 |
MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedIgnoredPlugins ) ); |
| 510 |
} |
| 511 |
} elseif ( 'theme' === $type ) { |
| 512 |
$decodedIgnoredThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); |
| 513 |
$decodedIgnoredThemes = ! empty( $decodedIgnoredThemes ) ? json_decode( $decodedIgnoredThemes, true ) : array(); |
| 514 |
|
| 515 |
if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| 516 |
unset( $decodedIgnoredThemes[ $slug ] ); |
| 517 |
MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedIgnoredThemes ) ); |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
return 'success'; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
/** |
| 529 |
* Unignore abandoned plugins or themes. |
| 530 |
* |
| 531 |
* @param mixed $type plugin|theme. |
| 532 |
* @param mixed $slug Plugin or Themes slug. |
| 533 |
* |
| 534 |
* @return string success. |
| 535 |
* |
| 536 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 537 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() |
| 538 |
*/ |
| 539 |
public static function unignore_abandoned_plugins_themes( $type, $slug ) { |
| 540 |
$slug = urldecode( $slug ); |
| 541 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 542 |
if ( 'plugin' === $type ) { |
| 543 |
if ( '_ALL_' === $slug ) { |
| 544 |
$decodedIgnoredPlugins = array(); |
| 545 |
} else { |
| 546 |
$decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true ); |
| 547 |
if ( ! is_array( $decodedIgnoredPlugins ) ) { |
| 548 |
$decodedIgnoredPlugins = array(); |
| 549 |
} |
| 550 |
if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { |
| 551 |
unset( $decodedIgnoredPlugins[ $slug ] ); |
| 552 |
} |
| 553 |
} |
| 554 |
MainWP_DB_Common::instance()->update_user_extension( |
| 555 |
array( |
| 556 |
'userid' => null, |
| 557 |
'dismissed_plugins' => wp_json_encode( $decodedIgnoredPlugins ), |
| 558 |
) |
| 559 |
); |
| 560 |
} elseif ( 'theme' === $type ) { |
| 561 |
if ( '_ALL_' === $slug ) { |
| 562 |
$decodedIgnoredThemes = array(); |
| 563 |
} else { |
| 564 |
$decodedIgnoredThemes = json_decode( $userExtension->dismissed_themes, true ); |
| 565 |
if ( ! is_array( $decodedIgnoredThemes ) ) { |
| 566 |
$decodedIgnoredThemes = array(); |
| 567 |
} |
| 568 |
if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { |
| 569 |
unset( $decodedIgnoredThemes[ $slug ] ); |
| 570 |
} |
| 571 |
} |
| 572 |
MainWP_DB_Common::instance()->update_user_extension( |
| 573 |
array( |
| 574 |
'userid' => null, |
| 575 |
'dismissed_themes' => wp_json_encode( $decodedIgnoredThemes ), |
| 576 |
) |
| 577 |
); |
| 578 |
} |
| 579 |
|
| 580 |
return 'success'; |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* Dismis Plugin or Theme. |
| 585 |
* |
| 586 |
* @param mixed $type plugin|theme. |
| 587 |
* @param mixed $slug Plugin or Theme slug. |
| 588 |
* @param mixed $name Plugin or Theme name. |
| 589 |
* @param mixed $id Child Site ID. |
| 590 |
* |
| 591 |
* @return string success. |
| 592 |
* |
| 593 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 594 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_option() |
| 595 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 596 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 597 |
*/ |
| 598 |
public static function dismiss_plugin_theme( $type, $slug, $name, $id ) { |
| 599 |
if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { |
| 600 |
$website = MainWP_DB::instance()->get_website_by_id( $id ); |
| 601 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 602 |
$slug = urldecode( $slug ); |
| 603 |
if ( 'plugin' === $type ) { |
| 604 |
$decodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); |
| 605 |
$decodedDismissedPlugins = ! empty( $decodedDismissedPlugins ) ? json_decode( $decodedDismissedPlugins, true ) : array(); |
| 606 |
|
| 607 |
if ( ! isset( $decodedDismissedPlugins[ $slug ] ) ) { |
| 608 |
$decodedDismissedPlugins[ $slug ] = urldecode( $name ); |
| 609 |
MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedDismissedPlugins ) ); |
| 610 |
} |
| 611 |
} elseif ( 'theme' === $type ) { |
| 612 |
$decodedDismissedThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); |
| 613 |
$decodedDismissedThemes = ! empty( $decodedDismissedThemes ) ? json_decode( $decodedDismissedThemes, true ) : array(); |
| 614 |
|
| 615 |
if ( ! isset( $decodedDismissedThemes[ $slug ] ) ) { |
| 616 |
$decodedDismissedThemes[ $slug ] = urldecode( $name ); |
| 617 |
MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedDismissedThemes ) ); |
| 618 |
} |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
return 'success'; |
| 624 |
} |
| 625 |
|
| 626 |
/** |
| 627 |
* Dismiss plugins or themes. |
| 628 |
* |
| 629 |
* @param mixed $type plugin|theme. |
| 630 |
* @param mixed $slug Plugin or Theme slug. |
| 631 |
* @param mixed $name Plugin or Theme name. |
| 632 |
* |
| 633 |
* @return string success. |
| 634 |
* |
| 635 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 636 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() |
| 637 |
*/ |
| 638 |
public static function dismiss_plugins_themes( $type, $slug, $name ) { |
| 639 |
$slug = urldecode( $slug ); |
| 640 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 641 |
if ( 'plugin' === $type ) { |
| 642 |
$decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true ); |
| 643 |
if ( ! is_array( $decodedDismissedPlugins ) ) { |
| 644 |
$decodedDismissedPlugins = array(); |
| 645 |
} |
| 646 |
$decodedDismissedPlugins[ $slug ] = urldecode( $name ); |
| 647 |
MainWP_DB_Common::instance()->update_user_extension( |
| 648 |
array( |
| 649 |
'userid' => null, |
| 650 |
'dismissed_plugins' => wp_json_encode( $decodedDismissedPlugins ), |
| 651 |
) |
| 652 |
); |
| 653 |
} elseif ( 'theme' === $type ) { |
| 654 |
$decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true ); |
| 655 |
if ( ! is_array( $decodedDismissedThemes ) ) { |
| 656 |
$decodedDismissedThemes = array(); |
| 657 |
} |
| 658 |
$decodedDismissedThemes[ $slug ] = urldecode( $name ); |
| 659 |
MainWP_DB_Common::instance()->update_user_extension( |
| 660 |
array( |
| 661 |
'userid' => null, |
| 662 |
'dismissed_themes' => wp_json_encode( $decodedDismissedThemes ), |
| 663 |
) |
| 664 |
); |
| 665 |
} |
| 666 |
|
| 667 |
return 'success'; |
| 668 |
} |
| 669 |
|
| 670 |
/** |
| 671 |
* Method upgrade_plugin_theme_translation() |
| 672 |
* |
| 673 |
* Upgrade plugin or theme translations. |
| 674 |
* |
| 675 |
* @param int $id Child site ID. |
| 676 |
* @param string $type Plugin or theme. |
| 677 |
* @param array $list_items List of theme or plugin names seperated by comma. |
| 678 |
* |
| 679 |
* @return array |
| 680 |
* @throws MainWP_Exception Error messages. |
| 681 |
* |
| 682 |
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() |
| 683 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 684 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 685 |
* @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() |
| 686 |
*/ |
| 687 |
public static function upgrade_plugin_theme_translation( $id, $type, $list_items ) { // phpcs:ignore -- complex method. |
| 688 |
if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { |
| 689 |
$website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'premium_upgrades' ) ); // to fix loading premium_upgrades. |
| 690 |
if ( MainWP_System_Utility::is_suspended_site( $website ) ) { |
| 691 |
throw new MainWP_Exception( 'ERROR', esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' ); |
| 692 |
} |
| 693 |
$result = self::update_plugin_theme_translation( $website, $type, $list_items ); |
| 694 |
if ( is_array( $result ) ) { |
| 695 |
|
| 696 |
$return_results = array(); |
| 697 |
|
| 698 |
// logging feature. |
| 699 |
$_type = ''; |
| 700 |
if ( 'plugin' === $type || 'theme' === $type ) { |
| 701 |
$_type = $type; |
| 702 |
} elseif ( 'translation' === $type ) { |
| 703 |
$_type = 'trans'; |
| 704 |
} |
| 705 |
|
| 706 |
if ( ! empty( $_type ) && isset( $result['other_data'] ) ) { // ok. |
| 707 |
$output_array = $result['other_data']; // updated_data: plugins,themes,trans. |
| 708 |
mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, $_type ); |
| 709 |
} |
| 710 |
|
| 711 |
$undefined = true; |
| 712 |
|
| 713 |
if ( isset( $result['upgrades_error'] ) ) { |
| 714 |
foreach ( $result['upgrades_error'] as $k => $v ) { |
| 715 |
$return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v ); |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
if ( isset( $result['upgrades'] ) ) { |
| 720 |
if ( isset( $result['upgrades'] ) ) { |
| 721 |
foreach ( $result['upgrades'] as $k => $v ) { |
| 722 |
$return_results['result'][ rawurlencode( $k ) ] = $v; |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
if ( 'plugin' === $type ) { |
| 727 |
if ( ! empty( $website->plugin_upgrades ) ) { |
| 728 |
$plugin_upgrades = json_decode( $website->plugin_upgrades, true ); |
| 729 |
if ( is_array( $plugin_upgrades ) ) { |
| 730 |
$updated = false; |
| 731 |
if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { |
| 732 |
foreach ( $return_results['result'] as $k => $v ) { |
| 733 |
$k = rawurldecode( $k ); |
| 734 |
if ( isset( $plugin_upgrades[ $k ] ) ) { |
| 735 |
unset( $plugin_upgrades[ $k ] ); // updated. |
| 736 |
$updated = true; |
| 737 |
} |
| 738 |
} |
| 739 |
} |
| 740 |
if ( $updated ) { |
| 741 |
MainWP_DB::instance()->update_website_values( $id, array( 'plugin_upgrades' => wp_json_encode( $plugin_upgrades ) ) ); |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { |
| 747 |
$decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); |
| 748 |
$decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); |
| 749 |
if ( is_array( $decodedPremiumUpgrades ) && ! empty( $decodedPremiumUpgrades ) ) { |
| 750 |
$updated = false; |
| 751 |
foreach ( $return_results['result'] as $k => $v ) { |
| 752 |
$k = rawurldecode( $k ); |
| 753 |
if ( isset( $decodedPremiumUpgrades[ $k ] ) ) { |
| 754 |
unset( $decodedPremiumUpgrades[ $k ] ); // updated. |
| 755 |
$updated = true; |
| 756 |
} |
| 757 |
} |
| 758 |
if ( $updated ) { |
| 759 |
MainWP_DB::instance()->update_website_option( $website, 'premium_upgrades', wp_json_encode( $decodedPremiumUpgrades ) ); |
| 760 |
} |
| 761 |
} |
| 762 |
} |
| 763 |
} |
| 764 |
return $return_results; |
| 765 |
} elseif ( isset( $result['error'] ) ) { |
| 766 |
throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) ); |
| 767 |
} elseif ( isset( $result['notices'] ) ) { |
| 768 |
$noti = $result['notices']; |
| 769 |
if ( ! empty( $noti ) && is_string( $noti ) ) { |
| 770 |
throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
if ( $undefined ) { |
| 775 |
throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) ); |
| 776 |
} |
| 777 |
} |
| 778 |
} |
| 779 |
throw new MainWP_Exception( 'ERROR', esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); |
| 780 |
} |
| 781 |
|
| 782 |
/** |
| 783 |
* Method update_plugin_theme_translation() |
| 784 |
* |
| 785 |
* Upgrade plugin or theme translations. |
| 786 |
* |
| 787 |
* @param int $website Child site object. |
| 788 |
* @param string $type Plugin or theme. |
| 789 |
* @param array $list_items List of theme or plugin names seperated by comma. |
| 790 |
* |
| 791 |
* @return array|false update result or false. |
| 792 |
* @throws \Exception Error message. |
| 793 |
* |
| 794 |
* @uses \MainWP\Dashboard\MainWP_System_Utility |
| 795 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() |
| 796 |
*/ |
| 797 |
public static function update_plugin_theme_translation( $website, $type, $list_items ) { |
| 798 |
if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 799 |
/** |
| 800 |
* Action: mainwp_before_plugin_theme_translation_update |
| 801 |
* |
| 802 |
* Fires before plugin/theme/translation update actions. |
| 803 |
* |
| 804 |
* @since 4.1 |
| 805 |
*/ |
| 806 |
do_action( 'mainwp_before_plugin_theme_translation_update', $type, $list_items, $website ); |
| 807 |
|
| 808 |
$information = MainWP_Connect::fetch_url_authed( |
| 809 |
$website, |
| 810 |
( 'translation' === $type ? 'upgradetranslation' : 'upgradeplugintheme' ), |
| 811 |
array( |
| 812 |
'type' => $type, |
| 813 |
'list' => urldecode( $list_items ), |
| 814 |
), |
| 815 |
true |
| 816 |
); |
| 817 |
/** |
| 818 |
* Action: mainwp_after_plugin_theme_translation_update |
| 819 |
* |
| 820 |
* Fires before plugin/theme/translation update actions. |
| 821 |
* |
| 822 |
* @since 4.1 |
| 823 |
*/ |
| 824 |
do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, $list_items, $website ); |
| 825 |
|
| 826 |
return $information; |
| 827 |
} |
| 828 |
return false; |
| 829 |
} |
| 830 |
|
| 831 |
/** |
| 832 |
* Get plugin or theme slugs. |
| 833 |
* |
| 834 |
* @param int $id Child Site ID. |
| 835 |
* @param string $type plugin|theme. |
| 836 |
* |
| 837 |
* @return array List of plugins or themes. |
| 838 |
* |
| 839 |
* @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() |
| 840 |
* @uses \MainWP\Dashboard\MainWP_DB::query() |
| 841 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() |
| 842 |
* @uses \MainWP\Dashboard\MainWP_DB::get_website_option() |
| 843 |
* @uses \MainWP\Dashboard\MainWP_DB::fetch_object() |
| 844 |
*/ |
| 845 |
public static function get_plugin_theme_slugs( $id, $type ) { // phpcs:ignore -- complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 846 |
|
| 847 |
$userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 848 |
$sql = MainWP_DB::instance()->get_sql_website_by_id( $id ); |
| 849 |
$websites = MainWP_DB::instance()->query( $sql ); |
| 850 |
$website = MainWP_DB::fetch_object( $websites ); |
| 851 |
|
| 852 |
$slugs = array(); |
| 853 |
if ( 'plugin' === $type ) { |
| 854 |
if ( $website->is_ignorePluginUpdates ) { |
| 855 |
return ''; |
| 856 |
} |
| 857 |
|
| 858 |
$plugin_upgrades = json_decode( $website->plugin_upgrades, true ); |
| 859 |
$decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); |
| 860 |
$decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); |
| 861 |
|
| 862 |
if ( is_array( $decodedPremiumUpgrades ) ) { |
| 863 |
foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { |
| 864 |
$premiumUpgrade['premium'] = true; |
| 865 |
|
| 866 |
if ( 'plugin' === $premiumUpgrade['type'] ) { |
| 867 |
if ( ! is_array( $plugin_upgrades ) ) { |
| 868 |
$plugin_upgrades = array(); |
| 869 |
} |
| 870 |
$premiumUpgrade = array_filter( $premiumUpgrade ); |
| 871 |
$plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade ); |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
$ignored_plugins = json_decode( $website->ignored_plugins, true ); |
| 877 |
if ( is_array( $ignored_plugins ) ) { |
| 878 |
$plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins ); |
| 879 |
} |
| 880 |
|
| 881 |
$ignored_plugins = json_decode( $userExtension->ignored_plugins, true ); |
| 882 |
if ( is_array( $ignored_plugins ) ) { |
| 883 |
$plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins ); |
| 884 |
} |
| 885 |
|
| 886 |
if ( is_array( $plugin_upgrades ) ) { |
| 887 |
foreach ( $plugin_upgrades as $slug => $plugin_upgrade ) { |
| 888 |
$slugs[] = rawurlencode( $slug ); |
| 889 |
} |
| 890 |
} |
| 891 |
} elseif ( 'theme' === $type ) { |
| 892 |
|
| 893 |
if ( $website->is_ignoreThemeUpdates ) { |
| 894 |
return ''; |
| 895 |
} |
| 896 |
|
| 897 |
$theme_upgrades = json_decode( $website->theme_upgrades, true ); |
| 898 |
$decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); |
| 899 |
$decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); |
| 900 |
|
| 901 |
if ( is_array( $decodedPremiumUpgrades ) ) { |
| 902 |
foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { |
| 903 |
$premiumUpgrade['premium'] = true; |
| 904 |
|
| 905 |
if ( 'theme' === $premiumUpgrade['type'] ) { |
| 906 |
if ( ! is_array( $theme_upgrades ) ) { |
| 907 |
$theme_upgrades = array(); |
| 908 |
} |
| 909 |
$theme_upgrades[ $crrSlug ] = $premiumUpgrade; |
| 910 |
} |
| 911 |
} |
| 912 |
} |
| 913 |
|
| 914 |
$ignored_themes = json_decode( $website->ignored_themes, true ); |
| 915 |
if ( is_array( $ignored_themes ) ) { |
| 916 |
$theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes ); |
| 917 |
} |
| 918 |
|
| 919 |
$ignored_themes = json_decode( $userExtension->ignored_themes, true ); |
| 920 |
if ( is_array( $ignored_themes ) ) { |
| 921 |
$theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes ); |
| 922 |
} |
| 923 |
|
| 924 |
if ( is_array( $theme_upgrades ) ) { |
| 925 |
foreach ( $theme_upgrades as $slug => $theme_upgrade ) { |
| 926 |
$slugs[] = $slug; |
| 927 |
} |
| 928 |
} |
| 929 |
} elseif ( 'translation' === $type ) { |
| 930 |
$translation_upgrades = json_decode( $website->translation_upgrades, true ); |
| 931 |
if ( is_array( $translation_upgrades ) ) { |
| 932 |
foreach ( $translation_upgrades as $translation_upgrade ) { |
| 933 |
$slugs[] = $translation_upgrade['slug']; |
| 934 |
} |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
return implode( ',', $slugs ); |
| 939 |
} |
| 940 |
} |
| 941 |
|