summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php')
-rw-r--r--plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php117
1 files changed, 112 insertions, 5 deletions
diff --git a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php
index 7c142008..bfb45938 100644
--- a/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php
+++ b/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php
@@ -15,6 +15,21 @@ abstract class Jetpack_Admin_Page {
abstract function page_render();
/**
+ * Should we block the page rendering because the site is in IDC?
+ * @var bool
+ */
+ static $block_page_rendering_for_idc;
+
+ /**
+ * Flag to know if we already checked the plan.
+ *
+ * @since 4.4.0
+ *
+ * @var bool
+ */
+ static $plan_checked = false;
+
+ /**
* Function called after admin_styles to load any additional needed styles.
*
* @since 4.3.0
@@ -23,12 +38,23 @@ abstract class Jetpack_Admin_Page {
function __construct() {
$this->jetpack = Jetpack::init();
+ self::$block_page_rendering_for_idc = (
+ Jetpack::validate_sync_error_idc_option() && ! Jetpack_Options::get_option( 'safe_mode_confirmed' )
+ );
+
+ if ( ! self::$block_page_rendering_for_idc ) {
+ add_action( 'admin_enqueue_scripts', array( $this, 'additional_styles' ) );
+ }
}
function add_actions() {
- /**
- * Don't add in the modules page unless modules are available!
- */
+
+ // If user is not an admin and site is in Dev Mode, don't do anything
+ if ( ! current_user_can( 'manage_options' ) && Jetpack::is_development_mode() ) {
+ return;
+ }
+
+ // Don't add in the modules page unless modules are available!
if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
return;
}
@@ -45,6 +71,9 @@ abstract class Jetpack_Admin_Page {
add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) );
+ // Check if the site plan changed and deactivate modules accordingly.
+ add_action( 'current_screen', array( $this, 'check_plan_deactivate_modules' ) );
+
// Attach page specific actions in addition to the above
$this->add_page_actions( $hook );
}
@@ -67,6 +96,11 @@ abstract class Jetpack_Admin_Page {
// Render the page with a common top and bottom part, and page specific content
function render() {
+ // We're in an IDC: we need a decision made before we show the UI again.
+ if ( self::$block_page_rendering_for_idc ) {
+ return;
+ }
+
$this->page_render();
}
@@ -100,12 +134,85 @@ abstract class Jetpack_Admin_Page {
wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' );
wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
wp_style_add_data( 'jetpack-admin', 'suffix', $min );
-
- $this->additional_styles();
}
function is_wp_version_too_old() {
global $wp_version;
return ( ! function_exists( 'rest_api_init' ) || version_compare( $wp_version, '4.4-z', '<=' ) );
}
+
+ /**
+ * Checks the site plan and deactivates modules that were active but are no longer included in the plan.
+ *
+ * @since 4.4.0
+ *
+ * @param $page
+ *
+ * @return bool|array
+ */
+ function check_plan_deactivate_modules( $page ) {
+ if (
+ Jetpack::is_development_mode()
+ || ! in_array(
+ $page->base,
+ array(
+ 'toplevel_page_jetpack',
+ 'admin_page_jetpack_modules',
+ 'jetpack_page_vaultpress',
+ 'jetpack_page_stats',
+ 'jetpack_page_akismet-key-config'
+ )
+ )
+ || true === self::$plan_checked
+ ) {
+ return false;
+ }
+
+ self::$plan_checked = true;
+ $previous = get_option( 'jetpack_active_plan', '' );
+ $response = rest_do_request( new WP_REST_Request( 'GET', '/jetpack/v4/site' ) );
+
+ if ( ! is_object( $response ) || $response->is_error() ) {
+
+ // If we can't get information about the current plan we don't do anything
+ self::$plan_checked = true;
+ return;
+ }
+
+ $current = $response->get_data();
+ $current = json_decode( $current['data'] );
+
+ $to_deactivate = array();
+ if ( isset( $current->plan->product_slug ) ) {
+ if (
+ empty( $previous )
+ || ! isset( $previous['product_slug'] )
+ || $previous['product_slug'] !== $current->plan->product_slug
+ ) {
+ $active = Jetpack::get_active_modules();
+ switch ( $current->plan->product_slug ) {
+ case 'jetpack_free':
+ $to_deactivate = array( 'seo-tools', 'videopress' );
+ break;
+ case 'jetpack_personal':
+ case 'jetpack_personal_monthly':
+ $to_deactivate = array( 'seo-tools', 'videopress' );
+ break;
+ case 'jetpack_premium':
+ case 'jetpack_premium_monthly':
+ $to_deactivate = array( 'seo-tools' );
+ break;
+ }
+ $to_deactivate = array_intersect( $active, $to_deactivate );
+ if ( ! empty( $to_deactivate ) ) {
+ Jetpack::update_active_modules( array_filter( array_diff( $active, $to_deactivate ) ) );
+ }
+ }
+ }
+ return array(
+ 'previous' => $previous,
+ 'current' => $current,
+ 'deactivate' => $to_deactivate
+ );
+ }
}