-
Notifications
You must be signed in to change notification settings - Fork 830
Forms: Fix feedback source #45195
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
base: trunk
Are you sure you want to change the base?
Forms: Fix feedback source #45195
Conversation
- 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>
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
There was a problem hiding this 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.
/** | ||
* The source type of the feedback entry. | ||
* This is used to determine how the feedback was created. | ||
* | ||
* @var string | ||
*/ | ||
public $source_id = ''; |
There was a problem hiding this comment.
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.
if ( $this->source_type === 'widget' ) { | ||
if ( $this->page_number > 1 && ! empty( $this->permalink ) ) { | ||
return add_query_arg( 'page', $this->page_number, $this->permalink ); | ||
} | ||
} |
There was a problem hiding this comment.
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.
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.
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' ); | ||
} |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
$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.
* Return the editor URL for the feedback entry. | ||
* So that users can edit the |
There was a problem hiding this comment.
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.
* 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.
$r .= '<a href="' . $feedback_source->get_editor_url() . '">EDIT FORM</a> | '; | ||
$r .= '<a href="' . $feedback_source->get_permalink() . '">View FORM</a>'; |
There was a problem hiding this comment.
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.
$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.
Code Coverage SummaryCannot generate coverage summary while tests are failing. 🤐 Please fix the tests, or re-run the Code coverage job if it was something being flaky. |
Fixes FORMS-211
Proposed changes:
Other information:
Jetpack product discussion
See FORMS-211
Does this pull request change what data or activity we track or use?
No
Testing instructions:
TBD.