Skip to content

Newsletter Categories: add helper class #44537

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

Merged
merged 12 commits into from
Jul 30, 2025

Conversation

arcangelini
Copy link
Contributor

@arcangelini arcangelini commented Jul 30, 2025

Fixes CML-687

Proposed changes:

  • Add new helper class for getting and setting newsletter category option
  • Use helper in WPCOM_JSON_API_Site_Settings_Endpoint and Jetpack_Core_API_Data
  • Adds unit tests to cover new class and make sure all areas are *nsync

The original issue was related to the wpcom_newsletter_categories option being stored in one format [{term_id: 123}, {term_id: 456}] but being returned in 2 different versions. The API endpoint was returning [123, 456] but the redux store for Jetpack was being populated with the raw version. This was causing discrepancies in how we display and save the data.

To prevent code duplication and allow for cleaner testing I made a helper class.

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

No

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

No

Testing instructions:

Add this change to an Atomic site.

  1. Go to YOUR_ATOMIC_SITE.com/wp-admin/admin.php?page=jetpack#newsletter
  2. Toggle the newsletter categories and save
  3. Refresh the page and make sure the changes persist
  4. For fun — you can open the console on this page and view window.Initial_State.settings.wpcom_newsletter_categories to make sure you are getting the proper formatting.

Add this change to an Atomic site.

  1. Go to https://wordpress.com/settings/newsletter/YOUR_ATOMIC_SITE.com
  2. Toggle the newsletter categories and save
  3. Refresh the page and make sure the changes persist

@arcangelini arcangelini requested a review from a team July 30, 2025 03:10
@arcangelini arcangelini self-assigned this Jul 30, 2025
@arcangelini arcangelini added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Jul 30, 2025
Copy link
Contributor

github-actions bot commented Jul 30, 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 arcanagelinis/newsletter-fix-v2 branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack arcanagelinis/newsletter-fix-v2

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 github-actions bot added [Feature] WPCOM API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Jul 30, 2025
Copy link
Contributor

github-actions bot commented Jul 30, 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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: August 5, 2025
    • Code freeze: August 4, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link

jp-launch-control bot commented Jul 30, 2025

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/_inc/client/newsletter/newsletter-categories.jsx 0/30 (0.00%) 0.00% 1 ❤️‍🩹
projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php 166/877 (18.93%) 0.63% -17 💚
projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php 337/781 (43.15%) 1.08% -27 💚

1 file is newly checked for coverage.

File Coverage
projects/plugins/jetpack/_inc/lib/class-jetpack-newsletter-category-helper.php 27/28 (96.43%) 💚

Full summary · PHP report · JS report

@github-actions github-actions bot added the Admin Page React-powered dashboard under the Jetpack menu label Jul 30, 2025
@@ -54,7 +54,10 @@ function NewsletterCategories( props ) {
dispatch,
} = props;

const checkedCategoriesIds = newsletterCategories.map( mapCategoriesIds );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was causing an error because it is possible for newsletterCategories to be undefined in the beginning

Copy link
Member

@allilevine allilevine left a comment

Choose a reason for hiding this comment

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

Thanks for aligning these! 🙌 I can update Atomic categories from both Calypso and Jetpack settings without errors.

I still can't enable/disable categories overall from Calypso for an Atomic site. Is that a separate fix?

Screenshot 2025-07-30 at 3 00 21 PM

@arcangelini
Copy link
Contributor Author

I still can't enable/disable categories overall from Calypso for an Atomic site. Is that a separate fix?

@allilevine thanks for pointing that out. I did not know that this was an issue as well I thought only the category picker was broken.

Copy link
Member

@allilevine allilevine left a comment

Choose a reason for hiding this comment

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

All Calypso category settings changes are working for me. ✅

@arcangelini arcangelini merged commit 8e6e8a9 into trunk Jul 30, 2025
73 of 76 checks passed
@arcangelini arcangelini deleted the arcanagelinis/newsletter-fix-v2 branch July 30, 2025 21:22
@github-actions github-actions bot added this to the jetpack/14.9 milestone Jul 30, 2025
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin Page React-powered dashboard under the Jetpack menu [Feature] WPCOM API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants