-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent module activation when plan doesn't support them #8983
Conversation
class.jetpack-modules-list-table.php
Outdated
@@ -231,8 +220,10 @@ function single_row( $item ) { | |||
if ( ! empty( $item['activated'] ) ) | |||
$row_class .= ' active'; | |||
|
|||
if ( ! $this->is_module_available( $item ) ) | |||
if ( ! Jetpack_Admin::is_module_available( $item ) ) { | |||
error_log($item['module']." is NOT available"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
class.jetpack.php
Outdated
@@ -4033,7 +4051,9 @@ function admin_page_load() { | |||
$module = stripslashes( $_GET['module'] ); | |||
check_admin_referer( "jetpack_activate-$module" ); | |||
Jetpack::log( 'activate', $module ); | |||
Jetpack::activate_module( $module ); | |||
if ( ! Jetpack::activate_module( $module ) ) { | |||
Jetpack::state( 'error', sprintf( __( 'Could not activated %s', 'jetpack' ), $module ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Could not activate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
'akismet', | ||
'vaultpress', | ||
'wordads', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to remove videopress and wordads from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - they are modules, the others are plugins. Modules are automatically added to the list based on metadata.
'google-analytics', | ||
'wordads', | ||
'search', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, did you mean to remove some items from this list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above - yes ;)
On a Free plan I don't have any configuration options on "Data Backups" (on Free plan), although maybe that's correct? I'm not sure what I'd actually configure at this point. I don't get the
banner in Calypso (correctly), so can't test that bit. I just get a banner asking me to upgrade to get access to that feature. On Personal I'd expect Data Backups to be available, but it doesn't appear to be. On Premium On Professional |
@beaulebens - thanks for the detailed feedback.
That appears to be a deliberate feature that was added to the modules list at some point - not a thing I added.
These are existing bugs unrelated to my changes, and should be handled in a separate PR. They also probably need some design/UX work to figure out how things need to behave. Having now dealt with the code for this change, I actually recommend throwing away the whole modules list code and either just doing without it, or replacing it with a cleanroom implementation. In its current form it is very hard to understand what's going on. Case in point: The HTML implementation that is rendered out as a table appears to be completely replaced in the DOM by a Javascript implementation using JS templates at load time - all the data is being rendered twice, and it is impossible to tell why your changes are having no effect until you realise this is what's going on. I would encourage you, if you could, to confirm that the Data Backups behaviour is actually identical in |
Gotcha -- I hadn't realized that "Data Backups" was already in the list; I figured you'd added it as part of this. I've just tested I've just gone through with that in mind and done some more testing, and this seems to handle things much better and more explicitly than the current |
@@ -1452,6 +1452,13 @@ public static function refresh_active_plan_from_wpcom() { | |||
* @return array Active Jetpack plan details | |||
*/ | |||
public static function get_active_plan() { | |||
global $active_plan_cache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any better way to do this than introducing another global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I couldn't think of one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear: We could refactor the whole way that we list out modules, and then we'd only need to call this one - but that requires a lot more time than "hack week" necessarily allows.
class.jetpack.php
Outdated
if ( ! isset( $plan['supports'] ) ) { | ||
$plan['supports'] = array(); | ||
// get available features | ||
foreach( self::get_available_modules() as $module_slug ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing -- foreach (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does seem to work in all of my testing, so I'm going to go ahead and approve. I agree that this entire module-listing UI probably needs to be gutted and simplified at some point.
Related: #9033 |
* Changelog 6.0: create base for changelog. * Add #8938 to changelog * Add #8962 to changelog * Add #8974 to changelog * Add #8975 to changelog * Add #8978 to changelog * Add #8867 to changelog * Add #8937 to changelog * Add #8961 to changelog * Add #8855 to changelog * Add #8944 to changelog * Add #8973 to changelog * Add #8977 to changelog * Add #8979 to changelog * Add #8980 to changelog * Add #8982 to changelog * Add #8983 to changelog * Add #8984 to changelog * Add #8986 to changelog * Add #9005 to changelog * Add #9010 to changelog * Add #9012 to changelog * Add #9021 to changelog * Add #9022 to changelog * Add #9056 to changelog * Add #9061 to changelog * Add #9079 to changelog * Add #9080 to changelog * Add #9088 to changelog * Add #9096 to changelog * Add #9097 to changelog * Add #9100 to changelog * Add #9107 to changelog * Add #8969 to changelog * Add #8993 to changelog * Add #9003 to changelog * Add #9031 to changelog * Add #8945 to changelog * Add #9052 to changelog * Add #9058 to changelog * Add #9066 to changelog * Add #9076 to changelog * Add #9053 to changelog * Add #9108 to changelog * Add #9135 to changelog * Add #9148 to changelog * Add #9125 to changelog * Add #9137 to changelog * Added testing instructions for 6.0. * Added IS testing instructions, huge props to @tiagonoronha. * Added #8498 to changelog. * Added #8954 to changelog. * Added #8985 to changelog. * add #9027 * add #9112 to changelog * add #9136 to changelog * add #9102 to changelog * add #9093 to changelog * add #9062 to changelog * add #9172 to changelog
Fixes #7867
Some plans support different modules. This change declares plan support in the module header, and checks for that support when rendering the "active plan" information.
This allows us to easily render inactive rows in the
jetpack_modules
page and elsewhere, so that users know which modules are truly available.This change also adds some basic checking in WP-cli and elsewhere for whether plan activation was successful.
Changes proposed in this Pull Request:
Plan: business, premium, personal
(default isfree
) attributeJetpack::get_active_plan()
responsejetpack_modules
list if they are not supported by the current planThe goal is NOT to prevent users from being able to hack the code to enable modules they shouldn't (since that is impossible anyway) but to help users understand what features their plan supports, and prevent them from accidentally enabling features that it doesn't.
Further work:
jetpack_modules
page.Testing instructions:
/wp-admin/admin.php?page=jetpack_modules
Configure
link./settings/traffic/{site_domain}
in CalypsoEnable
link next toSEO Tools module is disabled in Jetpack.
There was a problem saving your changes. Please try again.
(TODO: a better error message - in the network response you will see the actual error is{error: "not_supported", message: "The requested Jetpack module is not supported by your plan."}
)Proposed changelog entry for your changes:
available
status in Jetpack modules list