Skip to content

Conversation

@edanzer
Copy link
Contributor

@edanzer edanzer commented Jul 23, 2025

Fixes FORMS-232

Proposed changes:

Important:

  • This is branched from and is the backend counterpart to this PR, which adds MailPoet integration in the editor. By testing this, you can also test that PR in the editor.
  • All MailPoet integration remains behind a feature flag which is false by default. See testing instructions.

Changes:

  • In class-contact-form-plugin.php, we hook onto the 'grunion_after_feedback_post_inserted' to fire MailPoet integration logic.
    • This is wrapped in our MailPoet feature flag
  • Adds a new MailPoet_Integration class to handle MailPoet logic.
    • The main callback is MailPoetIntegration::handle_mailpoet_integration(). This method runs some simple checks for spam and for the connectMailPoet form attribute, and if all is clear, fires MailPoet integration methods, including
    • Instantiating the MailPoet API
    • Creating a Jetpack Form Subscribers list if one does not already exist. The method for this allow allows us to pass in a field name. In a future PR, we should fetch all lists and allow users to select one or add a new list in the block editor in the MailPoet card. I'd like to handle that separately.
    • Extracting subscriber data from the form. Email is the only required field for MailPoet, but we also check for first name and last name. For all fields, we try to find them using both field IDs and field Labels.
    • Finally, adding the contact to the MailPoet list.

Follow ups (not yet done):

  • We'll want to tie this into the Consent checkbox field, or create a new one for MailPoet. We'll want to check for consent before adding users to the list, depending on conditions.
  • We'll want to fetch all MailPoet lists, and show them in the MailPoet card in the modal. Users will be able to select one, or add a new list.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

See the linear issue and project above.

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

Yes.

Testing instructions:

  • Add a form to a page. Be sure to include at least an "Email" field. You can also try adding "First Name" and "Last Name". Other fields will not be added to MailPoet.
  • If needed, install and activate MailPoet from the modal, and get and add a MailPoet key. To get a key, you can create a free account at https://account.mailpoet.com
  • When everything active and connected, you'll be able to enable the toggle on the card header, which means your form is now connected to MailPoet. You'll see the MailPoet icon on the sidebar.
  • Go to the frontend and submit your form.
  • Go to MailPoet -> Lists and confirm the "Jetpack Form Subscribers" list is added.
  • Go to MailPoet -> Subscribers and confirm a contact has been added using the email you added to the form.
  • Disable MailPoet connection in the modal, resave, resubmit the form, and confirm that the email/contact is not added to MailPoet.

@edanzer edanzer self-assigned this Jul 23, 2025
@edanzer edanzer added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. [Pri] Normal [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account [Block] Contact Form Form block (also see Contact Form label) [Package] Forms labels Jul 23, 2025
@edanzer edanzer marked this pull request as ready for review July 23, 2025 23:00
@github-actions
Copy link
Contributor

github-actions bot commented Jul 23, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/forms-backend-mailpoet-integration branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-backend-mailpoet-integration

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

github-actions bot commented Jul 23, 2025

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.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jul 23, 2025
@jp-launch-control
Copy link

jp-launch-control bot commented Jul 23, 2025

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 435/1177 (36.96%) -0.14% 6 💔
projects/packages/forms/src/contact-form/class-contact-form.php 622/1140 (54.56%) 0.04% 0 💚
projects/packages/forms/src/class-jetpack-forms.php 8/21 (38.10%) 4.76% -1 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/forms/src/service/class-mailpoet-integration.php 0/69 (0.00%) 💔

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@edanzer edanzer removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 23, 2025
@edanzer edanzer requested a review from a team July 23, 2025 23:16
@edanzer edanzer force-pushed the add/forms-enableMailPoet-attribute branch from 2dfca0c to f97ce7d Compare July 24, 2025 14:48
@edanzer edanzer force-pushed the add/forms-backend-mailpoet-integration branch from 0d1e6e2 to f344c08 Compare July 24, 2025 14:49
dhasilva
dhasilva previously approved these changes Jul 24, 2025
Copy link
Contributor

@dhasilva dhasilva left a comment

Choose a reason for hiding this comment

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

LGTM, works as described

@enejb
Copy link
Member

enejb commented Jul 24, 2025

It would be good to wait for #44121 to land since then we could make sure that you can work the the fields easier.

Base automatically changed from add/forms-enableMailPoet-attribute to trunk July 24, 2025 19:27
@edanzer edanzer dismissed dhasilva’s stale review July 24, 2025 19:27

The base branch was changed.

@edanzer edanzer force-pushed the add/forms-backend-mailpoet-integration branch from f344c08 to 3b9a0ec Compare July 24, 2025 19:29
@edanzer edanzer force-pushed the add/forms-backend-mailpoet-integration branch from b23d67a to 7f0fc47 Compare July 25, 2025 00:17
@edanzer
Copy link
Contributor Author

edanzer commented Jul 25, 2025

Update: I hadn't wrapped the hook for the MailPoet logic in the feature flag. This has now been added. So if feature flag is off, no backend MailPoet logic will run (except that connectMailPoet will be added as a new default attribute).

@edanzer edanzer merged commit e1f4dff into trunk Jul 25, 2025
67 of 68 checks passed
@edanzer edanzer deleted the add/forms-backend-mailpoet-integration branch July 25, 2025 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Package] Forms [Pri] Normal [Status] Needs Privacy Updates Our support docs will need to be updated to take this change into account [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants