← All changes
|
jetpack_vendor/automattic/jetpack-status/src/class-modules.php
+22
-8
16.2
→
16.3-a.7
View file →
| @@ -217,8 +217,10 @@ | ||
| 217 | 217 | // We don't delete it from the options though, as it will be active again when a plugin gets reactivated. |
| 218 | 218 | $active = array_intersect( $active, $this->get_available() ); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | + Feature_Policy::ensure_hooks(); | |
| 222 | + | |
| 221 | 223 | /** |
| 222 | 224 | * Allow filtering of the active modules. |
| 223 | 225 | * |
| 224 | 226 | * Gives theme and plugin developers the power to alter the modules that |
| @@ -470,16 +472,14 @@ | ||
| 470 | 472 | if ( file_exists( $module_path ) ) { |
| 471 | 473 | require_once $this->get_path( $module ); |
| 472 | 474 | } |
| 473 | 475 | |
| 474 | - $active[] = $module; | |
| 475 | - $this->update_active( $active ); | |
| 476 | + $this->update_active( array_merge( $this->get_saved_active(), array( $module ) ) ); | |
| 476 | 477 | |
| 477 | 478 | $state->state( 'error', false ); // the override. |
| 478 | 479 | ob_end_clean(); |
| 479 | 480 | } else { // Not a Jetpack plugin. |
| 480 | - $active[] = $module; | |
| 481 | - $this->update_active( $active ); | |
| 481 | + $this->update_active( array_merge( $this->get_saved_active(), array( $module ) ) ); | |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | if ( $redirect ) { |
| 485 | 485 | wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) ); |
| @@ -492,11 +492,14 @@ | ||
| 492 | 492 | |
| 493 | 493 | /** |
| 494 | 494 | * Deactivate module. |
| 495 | 495 | * |
| 496 | + * A module a `jetpack_active_modules` callback forces on keeps running; callers that report | |
| 497 | + * back to a person should check is_active() afterwards. | |
| 498 | + * | |
| 496 | 499 | * @param string $module Module slug. |
| 497 | 500 | * |
| 498 | - * @return bool | |
| 501 | + * @return bool Whether the saved list changed. | |
| 499 | 502 | */ |
| 500 | 503 | public function deactivate( $module ) { |
| 501 | 504 | /** |
| 502 | 505 | * Fires when a module is deactivated. |
| @@ -506,12 +509,23 @@ | ||
| 506 | 509 | * @param string $module Module slug. |
| 507 | 510 | */ |
| 508 | 511 | do_action( 'jetpack_pre_deactivate_module', $module ); |
| 509 | 512 | |
| 510 | - $active = $this->get_active(); | |
| 511 | - $new = array_filter( array_diff( $active, (array) $module ) ); | |
| 513 | + return $this->update_active( array_filter( array_diff( $this->get_saved_active(), (array) $module ) ) ); | |
| 514 | + } | |
| 512 | 515 | |
| 513 | - return $this->update_active( $new ); | |
| 516 | + /** | |
| 517 | + * The active modules as saved, before filters add or drop any. | |
| 518 | + * | |
| 519 | + * Switching one module builds on this rather than get_active(), which would save whatever a | |
| 520 | + * `jetpack_active_modules` callback forces on. | |
| 521 | + * | |
| 522 | + * @return string[] Module slugs. | |
| 523 | + */ | |
| 524 | + private function get_saved_active() { | |
| 525 | + $saved = \Jetpack_Options::get_option( 'active_modules', array() ); | |
| 526 | + | |
| 527 | + return is_array( $saved ) ? array_values( $saved ) : array(); | |
| 514 | 528 | } |
| 515 | 529 | |
| 516 | 530 | /** |
| 517 | 531 | * Generate a module's path from its slug. |