Skip to content

Forms: restore not spam action #43559

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 5 commits into from
May 28, 2025
Merged

Conversation

CGastrell
Copy link
Contributor

@CGastrell CGastrell commented May 21, 2025

Related to FORMS-89

Proposed changes:

This PR adds the old Admin ajax process to send the submission email when the user moves a response from spam to inbox.

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

p1747734409666879-slack-C086RGTJT1D

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

No

Testing instructions:

Test this on your sandbox, local envs usually don't send emails. Unsure about JN sites.

Move a response from Spam to Inbox, you should receive a submission email on the associated email address as with a regular submission.

@CGastrell CGastrell self-assigned this May 21, 2025
@CGastrell CGastrell added [Type] Bug When a feature is broken and / or not performing as intended [Status] In Progress [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Package] Forms Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR labels May 21, 2025
Copy link
Contributor

github-actions bot commented May 21, 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 fix/jetpack-forms-restore-not-spam-action branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/jetpack-forms-restore-not-spam-action

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

Copy link
Contributor

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: June 3, 2025
    • Code freeze: June 2, 2025

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

@CGastrell CGastrell requested a review from Copilot May 21, 2025 20:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reinstates sending the contact form submission email when an entry is moved from spam back to the inbox.

  • Overrides update_item to detect a status change from spam to publish and trigger resend_email.
  • Adds resend_email method to reconstruct and send the original notification email.
  • Updates changelog to document the new behavior.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
projects/packages/forms/src/contact-form/class-contact-form-endpoint.php Adds update_item override and resend_email to resend emails on spam restore
projects/packages/forms/changelog/fix-jetpack-forms-restore-not-spam-action Documents the behavior in the changelog
Comments suppressed due to low confidence (1)

projects/packages/forms/src/contact-form/class-contact-form-endpoint.php:391

  • [nitpick] This new update_item behavior (restoring from spam and resending email) isn’t covered by existing tests; consider adding a unit or integration test to verify the status transition and email resend invocation.
public function update_item( $request ) {

$post_id = $request['id'];
$previous_status = get_post_status( $post_id );
$updated_item = parent::update_item( $request );
if ( ! is_wp_error( $updated_item ) && ! empty( $updated_item->data && ! empty( $updated_item->data['status'] ) ) ) {
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

The conditional combines empty checks incorrectly. Consider simplifying to if ( ! is_wp_error( $updated_item ) && ! empty( $updated_item->data['status'] ) ) { or use isset( $updated_item->data['status'] ) for clarity and correctness.

Suggested change
if ( ! is_wp_error( $updated_item ) && ! empty( $updated_item->data && ! empty( $updated_item->data['status'] ) ) ) {
if ( ! is_wp_error( $updated_item ) && isset( $updated_item->data['status'] ) && ! empty( $updated_item->data['status'] ) ) {

Copilot uses AI. Check for mistakes.

@@ -381,6 +381,93 @@ public function get_item_schema() {
return $this->add_additional_fields_schema( $this->schema );
}

/**
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

[nitpick] New methods update_item and resend_email should include @since annotations in their docblocks to track when this behavior was introduced.

Copilot uses AI. Check for mistakes.

Copy link

jp-launch-control bot commented May 21, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-endpoint.php 344/496 (69.35%) -5.92% 39 💔

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@enejb enejb changed the title Forms restore not spam action Forms: restore not spam action May 22, 2025
@CGastrell CGastrell requested a review from a team May 22, 2025 15:44
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*/
public function update_item( $request ) {
Copy link
Member

@simison simison May 23, 2025

Choose a reason for hiding this comment

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

I didn't look if we check earlier things like id isn't empty/invalid, post with that ID exists etc but feels like something like that is missing here? Not a blocker for merging.

Copy link
Contributor Author

@CGastrell CGastrell May 23, 2025

Choose a reason for hiding this comment

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

You're right on this one. I'm mostly relying on the parent's process to validate, but I'm also taking the id first.

Ref: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qvapyhqrf%2Serfg%2Qncv%2Sraqcbvagf%2Spynff%2Qjc%2Qerfg%2Qcbfgf%2Qpbagebyyre.cuc%3Se%3Qq13qsq59%26zb%3Q235%26sv%3Q17%23932-og

I think I'll repeat the validity check on the parent process (I need the previous status) and then allow the process to continue. Something like:

$valid_check = parent::get_post( $request['id'] );
if ( is_wp_error( $valid_check ) ) {
	return $valid_check;
}

$post_id         = $request['id'];
$previous_status = get_post_status( $post_id );
$updated_item    = parent::update_item( $request );

if ( ! is_wp_error( $updated_item ) && ! empty( $updated_item->data && ! empty( $updated_item->data['status'] ) ) ) {
...

simison
simison previously approved these changes May 23, 2025
Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

I haven't tested, but approving based on reviewing code:

  • Email sending is there,
  • Akismet marking post as "HAM" is there, which was important too

No tracking that I can see so I wonder if we should add that in a follow-up? Either bump start or Tracks.

In my understanding we'll be able to remove the other, old chunk for similar code together with Classic view, so there's no point abstracting these to use shared method?

@CGastrell CGastrell force-pushed the fix/jetpack-forms-restore-not-spam-action branch from 9571ceb to a6c3d36 Compare May 26, 2025 12:29
@CGastrell CGastrell requested a review from a team May 26, 2025 12:49
@simison simison force-pushed the fix/jetpack-forms-restore-not-spam-action branch from a6c3d36 to 1789bf7 Compare May 28, 2025 08:00
Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Tested locally and simple sites, worked well.

Rebased as well.

@simison simison merged commit ada1ed7 into trunk May 28, 2025
66 checks passed
@simison simison deleted the fix/jetpack-forms-restore-not-spam-action branch May 28, 2025 08:53
@github-actions github-actions bot added this to the jetpack/14.7 milestone May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [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