Skip to content

Conversation

enejb
Copy link
Member

@enejb enejb commented Sep 16, 2025

Fixes FORMS-211

Proposed changes:

  • Store more info about the source of the form.
  • Improve the links to the source and the title.

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 FORMS-211

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

No

Testing instructions:

TBD.

enejb and others added 3 commits September 16, 2025 06:26
- Fix variable naming from $feedback_Source to $feedback_source in Contact_Form
- Add missing PHPDoc comments for get_feedback_source() method
- Add missing parameter documentation for constructor $source_type and $source_id
- Add missing function documentation for static factory methods
- Add missing text domain 'jetpack-forms' to __() function calls

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@enejb enejb requested a review from Copilot September 16, 2025 13:29
@enejb enejb added [Type] Bug When a feature is broken and / or not performing as intended [Package] Forms labels Sep 16, 2025
Copy link
Contributor

github-actions bot commented Sep 16, 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/feedback-source branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/feedback-source

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] Contact Form [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Sep 16, 2025
Copy link
Contributor

github-actions bot commented Sep 16, 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: October 7, 2025
    • Code freeze: October 6, 2025

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

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Sep 16, 2025
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 fixes feedback source tracking for forms by storing more context about how forms were created and improving edit links. The changes enable better identification of form sources (single posts, widgets, block templates, etc.) and provide appropriate edit URLs for different form contexts.

Key changes:

  • Enhanced Feedback_Source class to track source type and ID with new constructor parameters
  • Added factory methods for creating feedback sources from different contexts (widgets, templates, serialized data)
  • Updated widget context separator format and added editor URL generation logic

Reviewed Changes

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

File Description
class-feedback-source.php Core enhancement adding source type tracking, factory methods, and editor URL generation
class-contact-form.php Added method to determine feedback source from attributes and debug links
class-contact-form-plugin.php Changed widget context separator from '-' to '
changelog/fix-feedback-source (both) Changelog entries documenting the bugfix

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +54 to +60
/**
* The source type of the feedback entry.
* This is used to determine how the feedback was created.
*
* @var string
*/
public $source_id = '';
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The docstring for $source_id incorrectly describes it as 'The source type of the feedback entry'. It should describe it as the source ID, not type.

Copilot uses AI. Check for mistakes.

Comment on lines +123 to 127
if ( $this->source_type === 'widget' ) {
if ( $this->page_number > 1 && ! empty( $this->permalink ) ) {
return add_query_arg( 'page', $this->page_number, $this->permalink );
}
}
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The code block checking for 'widget' source type is duplicated. Remove the duplicate lines 123-127.

Suggested change
if ( $this->source_type === 'widget' ) {
if ( $this->page_number > 1 && ! empty( $this->permalink ) ) {
return add_query_arg( 'page', $this->page_number, $this->permalink );
}
}

Copilot uses AI. Check for mistakes.

Comment on lines +276 to +278
if ( $this->source_type === 'block_template_part' ) {
return admin_url( 'site-editor.php?p=' . esc_attr( '/wp_template_part/' . addslashes( $this->source_id ) ) . '&canvas=edit' );
}
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The code block for 'block_template_part' is duplicated. Remove the duplicate lines 276-278 as they're identical to lines 272-274.

Suggested change
if ( $this->source_type === 'block_template_part' ) {
return admin_url( 'site-editor.php?p=' . esc_attr( '/wp_template_part/' . addslashes( $this->source_id ) ) . '&canvas=edit' );
}

Copilot uses AI. Check for mistakes.


$this->id = $id > 0 ? (int) $id : 0;
$this->title = $title;
$this->page_number = $page_number;
$this->permalink = $this->id === 0 ? home_url() : '';
$this->source_type = $source_type; // possible source types: single, widget, template, template-part
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The comment lists 'template' and 'template-part' as possible source types, but the code uses 'block_template' and 'block_template_part'. Update the comment to match the actual values used in the code.

Suggested change
$this->source_type = $source_type; // possible source types: single, widget, template, template-part
$this->source_type = $source_type; // possible source types: single, widget, block_template, block_template_part

Copilot uses AI. Check for mistakes.

Comment on lines +264 to +265
* Return the editor URL for the feedback entry.
* So that users can edit the
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The docstring is incomplete. The sentence 'So that users can edit the' is cut off and should be completed or rewritten to properly describe the method's purpose.

Suggested change
* Return the editor URL for the feedback entry.
* So that users can edit the
* Returns the editor URL for the feedback entry.
* This allows users to edit the associated post, template, widget, or other source type based on the feedback's origin.

Copilot uses AI. Check for mistakes.

Comment on lines +773 to +774
$r .= '<a href="' . $feedback_source->get_editor_url() . '">EDIT FORM</a> | ';
$r .= '<a href="' . $feedback_source->get_permalink() . '">View FORM</a>';
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

These debug links should not be in production code. Either remove them or wrap them in a debug/development check to prevent them from appearing in the live output.

Suggested change
$r .= '<a href="' . $feedback_source->get_editor_url() . '">EDIT FORM</a> | ';
$r .= '<a href="' . $feedback_source->get_permalink() . '">View FORM</a>';
if ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || current_user_can( 'manage_options' ) ) {
$r .= '<a href="' . $feedback_source->get_editor_url() . '">EDIT FORM</a> | ';
$r .= '<a href="' . $feedback_source->get_permalink() . '">View FORM</a>';
}

Copilot uses AI. Check for mistakes.

Copy link

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [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.

1 participant