Skip to content
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

Hijack the feature eligibility checks on WordPress.com sites #23189

Merged
merged 22 commits into from
Mar 16, 2022

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Mar 2, 2022

Fixes Automattic/wp-calypso#51593.
Fixes Automattic/wp-calypso#51826.
Fixes Automattic/wp-calypso#61499.

Changes proposed in this Pull Request:

Hijacks the Jetpack_Plan::supports function with a call to wpcom_site_has_feature (if exists) to make sure that Jetpack features are gated correctly on WP.com sites.

That allows us to simplify some of the existing feature eligibility checks since we can use now Jetpack_Plan::supports on all sites.

Jetpack product discussion

pdG1ka-46-p2

Does this pull request change what data or activity we track or use?

N/A.

Testing instructions:

Jetpack sites:

  • Spin up a JN site using this branch.
  • Set up Jetpack and keep it on the Free plan.
  • Apply D75906-code to your WP.com sandbox.
  • Enable incoming HTTP connections in your WP.com sandbox: sudo global-http enable.
  • Go to Settings > Jetpack Constants and enter your WP.com sandbox address in JETPACK__SANDBOX_DOMAIN.
  • Go to Jetpack > Settings > Performance and enable VideoPress.
  • Go to Posts > Add new.
  • Insert a Video block and upload a video.
  • Make sure it's correctly processed by VideoPress.
  • Insert a Payment Button block.
  • Make sure it requires a plan upgrade.

Simple sites:

  • Apply D75906-code to your WP.com sandbox.
  • Sandbox the API and a WP.com simple site with a Free plan.
  • Go to https://wordpress.com and switch to your sandboxed site.
  • Go to Posts > Add new.
  • Make sure these blocks require a Personal plan:
    • Payments button
    • Donations
    • Premium Content
  • Make sure these blocks require a Premium plan:
    • Pay with PayPal
    • Video
    • Calendly
    • OpenTable
    • WhatsApp button
  • Upgrade to a Business plan.
  • Make sure the blocks above no longer require any upgrade.
  • Insert a Tiled Gallery block in a post and publish it.
  • Visit the published post.
  • Make sure the Tiled Gallery block is rendered as expected.

Atomic sites:

  • Create a WoA dev blog with a Business plan (p9o2xV-1r2-p2).
  • Install Jetpack Beta and activate the branch of this PR.
  • Go to Jetpack > Search.
  • Make sure the instant search experience requires an upgrade.
  • Click on the upsell nudge to buy the upgrade.
  • Make sure the instant search experience is available now.
  • Go to Posts > Add new.
  • Insert a Video block and upload a video.
  • Make sure it's correctly processed by VideoPress.
  • Insert a Payment Button block.
  • Make sure it does not require any upgrade.
  • Add this change to wpcomsh (you can use SFTP via Settings > Hosting Config) to simulate that the site no longer has a Business plan (*):
diff --git a/class.atomic-plan-manager.php b/class.atomic-plan-manager.php
index d8abaf8..b179fdd 100644
--- a/class.atomic-plan-manager.php
+++ b/class.atomic-plan-manager.php
@@ -73,6 +73,7 @@ class Atomic_Plan_Manager {
 	public static function current_plan_slug() {
+		return self::FREE_PLAN_SLUG;
 		$atomic_site_id = wpcomsh_get_atomic_site_id();
 
diff --git a/wpcom-features/functions-wpcom-features.php b/wpcom-features/functions-wpcom-features.php
index c542764..c15ce1d 100644
--- a/wpcom-features/functions-wpcom-features.php
+++ b/wpcom-features/functions-wpcom-features.php
@@ -72,6 +72,8 @@ function wpcom_site_has_feature( $feature, $blog_id = 0 ) {
 		$is_wpcom_site = is_blog_wpcom( $blog ) || is_blog_atomic( $blog );
 	}
 
+	$purchases = array();
+
 	return WPCOM_Features::has_feature( $feature, $purchases, $is_wpcom_site );
 }
 
  • Go to wp-admin/post-new.php.
  • Make sure the Video block requires a Premium plan and that the upload buttons are disabled.
  • Make sure the Payment Button block requires a Personal plan.
  • Go to wp-admin/upload.php.
  • Make sure you cannot upload video files.

(*) I first tried this by actually removing the plan from SA, but that left the site on a broken state because Jetpack was deactivated. Didn't look deeply into the issue, but apparently it's caused by a conflict between Jetpack Beta and WoA dev blogs since I can remove a plan without problems when Jetpack Beta is not involved.

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello mmtr! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D75906-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Feature] Memberships Pay With Paypal [Feature] VideoPress A feature to help you upload and insert videos on your site. labels Mar 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: April 5, 2022.
  • Scheduled code freeze: March 29, 2022.

@mmtr mmtr changed the title Hijack the feature eligibility checks on WordPress.com sites [WIP] Hijack the feature eligibility checks on WordPress.com sites Mar 3, 2022
// Manually mapping WordPress.com features to Jetpack module slugs.
foreach ( $plan['features']['active'] as $wpcom_feature ) {
switch ( $wpcom_feature ) {
case 'wordads-jetpack':
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we no longer need this, since in D75985-code we're reporting wordads as the active feature (along with wordads-jetpack for old Jetpack sites).

@mmtr mmtr changed the title [WIP] Hijack the feature eligibility checks on WordPress.com sites Hijack the feature eligibility checks on WordPress.com sites Mar 3, 2022
@mmtr mmtr added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Mar 3, 2022
@mmtr mmtr added this to the jetpack/10.8 milestone Mar 10, 2022
…ks-wpcom-sites

# Conflicts:
#	projects/plugins/jetpack/modules/simple-payments/simple-payments.php
@mmtr mmtr added [Status] In Progress and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 10, 2022
@mmtr mmtr changed the title Hijack the feature eligibility checks on WordPress.com sites [WIP] Hijack the feature eligibility checks on WordPress.com sites Mar 10, 2022
// Jetpack_Plan does not exist on WordPress.com.
if ( class_exists( 'Jetpack_Plan' ) ) {
// Jetpack_Plan::get does not exist on WordPress.com.
if ( method_exists( 'Jetpack_Plan', 'get' ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents fatals on WP.com since we're adding a Jetpack_Plan class there with only the supports method (see D75906-code).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to fully sync Jetpack_Plan to wpcom instead, so when p9dueE-4mF-p2 and later work happens we don't have to figure out how to fix things then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would this is okay and something we can fix properly when Jetpack is on WP.com.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fully sync Jetpack_Plan to wpcom instead

That'd require to refactor the Jetpack_Plan class in order to ensure its methods also work in WP.com. I took a briefly look at what would be needed, and it didn't seem trivial, so I decided to keep things simple for this PR.

@mmtr mmtr changed the title [WIP] Hijack the feature eligibility checks on WordPress.com sites Hijack the feature eligibility checks on WordPress.com sites Mar 10, 2022
@mmtr mmtr added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Mar 10, 2022
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests well for me on Jetpack and wpcom simple. I wasn't able to test on Atomic though (for some reason I see no wpcom-features/ directory in my copy of wpcomsh`, so I'll leave that to somebody else.

@mmtr
Copy link
Member Author

mmtr commented Mar 16, 2022

for some reason I see no wpcom-features/ directory in my copy of wpcomsh`

If you used an existing WoA dev blog created a while ago, that may explain it, since wpcomsh is not automatically updated on WoA dev blogs and the wpcom-features folder was added recently.

I'll leave that to somebody else.

Already tested in #23189 (review) 🙂

@mmtr mmtr added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 16, 2022
@mmtr mmtr enabled auto-merge (squash) March 16, 2022 10:16
@mmtr mmtr merged commit a09c00e into master Mar 16, 2022
@mmtr mmtr deleted the update/feature-checks-wpcom-sites branch March 16, 2022 10:19
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D75906-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 16, 2022
@mmtr
Copy link
Member Author

mmtr commented Mar 16, 2022

r241836-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Tiled Gallery [Feature] Memberships [Feature] Pay with PayPal aka Simple Payments [Feature] VideoPress A feature to help you upload and insert videos on your site. Plans [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Projects
None yet
7 participants