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 +42 -20 13.5.2 → 16.3-beta View file →
@@ -21,16 +21,18 @@
21 21 /**
22 22 * Check whether or not a Jetpack module is active.
23 23 *
24 24 * @param string $module The slug of a Jetpack module.
25 + * @param bool $available_only Whether to only check among available modules.
26 + *
25 27 * @return bool
26 28 */
27 - public function is_active( $module ) {
29 + public function is_active( $module, $available_only = true ) {
28 30 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
29 31 return true;
30 32 }
31 33
32 - return in_array( $module, self::get_active(), true );
34 + return in_array( $module, self::get_active( $available_only ), true );
33 35 }
34 36
35 37 /**
36 38 * Load module data from module file. Headers differ from WordPress
@@ -72,10 +74,10 @@
72 74 $mod['sort'] = empty( $mod['sort'] ) ? 10 : (int) $mod['sort'];
73 75 $mod['recommendation_order'] = empty( $mod['recommendation_order'] ) ? 20 : (int) $mod['recommendation_order'];
74 76 $mod['deactivate'] = empty( $mod['deactivate'] );
75 77 $mod['free'] = empty( $mod['free'] );
76 - $mod['requires_connection'] = ( ! empty( $mod['requires_connection'] ) && 'No' === $mod['requires_connection'] ) ? false : true;
77 - $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'] );
78 80
79 81 if ( empty( $mod['auto_activate'] ) || ! in_array( strtolower( $mod['auto_activate'] ), array( 'yes', 'no', 'public' ), true ) ) {
80 82 $mod['auto_activate'] = 'No';
81 83 } else {
@@ -183,10 +185,14 @@
183 185 }
184 186
185 187 /**
186 188 * Get a list of activated modules as an array of module slugs.
189 + *
190 + * @param bool $available_only Filter out the unavailable (deleted) modules.
191 + *
192 + * @return array
187 193 */
188 - public function get_active() {
194 + public function get_active( $available_only = true ) {
189 195 $active = \Jetpack_Options::get_option( 'active_modules' );
190 196
191 197 if ( ! is_array( $active ) ) {
192 198 $active = array();
@@ -205,12 +211,16 @@
205 211 && get_site_option( 'jetpack_protect_active' ) ) {
206 212 $active[] = 'protect';
207 213 }
208 214
209 - // If it's not available, it shouldn't be active.
210 - // We don't delete it from the options though, as it will be active again when a plugin gets reactivated.
211 - $active = array_intersect( $active, $this->get_available() );
215 + if ( $available_only ) {
216 + // If it's not available, it shouldn't be active.
217 + // We don't delete it from the options though, as it will be active again when a plugin gets reactivated.
218 + $active = array_intersect( $active, $this->get_available() );
219 + }
212 220
221 + Feature_Policy::ensure_hooks();
222 +
213 223 /**
214 224 * Allow filtering of the active modules.
215 225 *
216 226 * Gives theme and plugin developers the power to alter the modules that
@@ -408,9 +418,9 @@
408 418 $status = new Status();
409 419 $state = new CookieState();
410 420
411 421 if ( ! \Jetpack::is_connection_ready() ) {
412 - if ( ! $status->is_offline_mode() && ! $status->is_onboarding() ) {
422 + if ( ! $status->is_offline_mode() ) {
413 423 return false;
414 424 }
415 425
416 426 // If we're not connected but in offline mode, make sure the module doesn't require a connection.
@@ -435,9 +445,9 @@
435 445 }
436 446 if ( $deactivated ) {
437 447 $state->state( 'deactivated_plugins', implode( ',', $deactivated ) );
438 448 wp_safe_redirect( add_query_arg( 'jetpack_restate', 1 ) );
439 - exit;
449 + exit( 0 );
440 450 }
441 451 }
442 452 }
443 453
@@ -459,19 +469,17 @@
459 469
460 470 ob_start();
461 471 $module_path = $this->get_path( $module );
462 472 if ( file_exists( $module_path ) ) {
463 - require $this->get_path( $module ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
473 + require_once $this->get_path( $module );
464 474 }
465 475
466 - $active[] = $module;
467 - $this->update_active( $active );
476 + $this->update_active( array_merge( $this->get_saved_active(), array( $module ) ) );
468 477
469 478 $state->state( 'error', false ); // the override.
470 479 ob_end_clean();
471 480 } else { // Not a Jetpack plugin.
472 - $active[] = $module;
473 - $this->update_active( $active );
481 + $this->update_active( array_merge( $this->get_saved_active(), array( $module ) ) );
474 482 }
475 483
476 484 if ( $redirect ) {
477 485 wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) );
@@ -476,9 +484,9 @@
476 484 if ( $redirect ) {
477 485 wp_safe_redirect( ( new Paths() )->admin_url( 'page=jetpack' ) );
478 486 }
479 487 if ( $exit ) {
480 - exit;
488 + exit( 0 );
481 489 }
482 490 return true;
483 491 }
484 492
@@ -484,11 +492,14 @@
484 492
485 493 /**
486 494 * Deactivate module.
487 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 + *
488 499 * @param string $module Module slug.
489 500 *
490 - * @return bool
501 + * @return bool Whether the saved list changed.
491 502 */
492 503 public function deactivate( $module ) {
493 504 /**
494 505 * Fires when a module is deactivated.
@@ -498,12 +509,23 @@
498 509 * @param string $module Module slug.
499 510 */
500 511 do_action( 'jetpack_pre_deactivate_module', $module );
501 512
502 - $active = $this->get_active();
503 - $new = array_filter( array_diff( $active, (array) $module ) );
513 + return $this->update_active( array_filter( array_diff( $this->get_saved_active(), (array) $module ) ) );
514 + }
504 515
505 - 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();
506 528 }
507 529
508 530 /**
509 531 * Generate a module's path from its slug.