PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-status/src/class-modules.php +28 -14 13.6.2 → 16.3-beta View file →
@@ -74,10 +74,10 @@
74 74 $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort'];
75 75 $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order'];
76 76 $mod['deactivate'] = empty( $mod['deactivate'] );
77 77 $mod['free'] = empty( $mod['free'] );
78 - $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' === $mod['requires_connection'] ) ? false : true;
79 - $mod['requires_user_connection'] = ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] ) ? false : true;
78 + $mod['requires_connection'] = empty( $mod['requires_connection'] ) || 'No' !== $mod['requires_connection'];
79 + $mod['requires_user_connection'] = ! ( empty( $mod['requires_user_connection'] ) || 'No' === $mod['requires_user_connection'] );
80 80
81 81 if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ), true ) ) {
82 82 $mod['auto_activate'] = 'No';
83 83 } else {
@@ -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
@@ -416,9 +418,9 @@
416 418 $status = new Status();
417 419 $state = new CookieState();
418 420
419 421 if ( ! \Jetpack::is_connection_ready() ) {
420 - if ( ! $status->is_offline_mode() && ! $status->is_onboarding() ) {
422 + if ( ! $status->is_offline_mode() ) {
421 423 return false;
422 424 }
423 425
424 426 // If we're not connected but in offline mode, make sure the module doesn't require a connection.
@@ -443,9 +445,9 @@
443 445 }
444 446 if ( $deactivated ) {
445 447 $state->state( 'deactivated_plugins', implode( ',', $deactivated ) );
446 448 wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) );
447 - exit;
449 + exit( 0 );
448 450 }
449 451 }
450 452 }
451 453
@@ -467,19 +469,17 @@
467 469
468 470 ob_start();
469 471 $module_path = $this->get_path( $module );
470 472 if ( file_exists( $module_path ) ) {
471 - require $this->get_path( $module ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
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' ) );
@@ -484,9 +484,9 @@
484 484 if ( $redirect ) {
485 485 wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) );
486 486 }
487 487 if ( $exit ) {
488 - exit;
488 + exit( 0 );
489 489 }
490 490 return true;
491 491 }
492 492
@@ -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.