Forms: Add ref support to the contact-form shortcode#47129
Forms: Add ref support to the contact-form shortcode#47129
Conversation
|
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! |
955efea to
c2e6dac
Compare
…t type The [contact-form ref='1234'] shortcode was ignoring the ref attribute. This adds support for loading the form content from the referenced jetpack_form post, matching the behavior of the block version. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
c2e6dac to
c90e8c5
Compare
There was a problem hiding this comment.
Pull request overview
This pull request adds support for the ref attribute in the [contact-form] shortcode to load form content from a jetpack_form post type, bringing feature parity with the block version of the contact form. The implementation includes proper validation, permission checks, and circular reference prevention.
Changes:
- Added
render_form_by_ref()method to handle loading and rendering forms fromjetpack_formposts - Modified the
parse()method to handle therefattribute in shortcodes - Added comprehensive test coverage for valid refs, invalid refs, circular references, and status checks
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/packages/forms/src/contact-form/class-contact-form.php | Adds render_form_by_ref() method and integrates ref attribute handling into the shortcode parser with validation, permission checks, and circular reference prevention |
| projects/packages/forms/tests/php/contact-form/Contact_Form_Synced_Test.php | Adds four new test cases covering shortcode ref attribute: valid form loading, invalid ref handling, circular reference prevention, and status validation |
| projects/packages/forms/changelog/fix-missing-shortcode-ref-attribute | Adds changelog entry documenting the fix |
projects/packages/forms/changelog/fix-missing-shortcode-ref-attribute
Outdated
Show resolved
Hide resolved
| // Circular reference prevention. | ||
| if ( self::has_seen( $ref_id ) ) { | ||
| return ''; | ||
| } | ||
|
|
There was a problem hiding this comment.
The circular reference check using has_seen happens before set_ref_id is called, which means the first check at line 219 can never catch the immediate self-reference case. The redundant check at line 247 catches this case instead. Consider either removing the check at line 219 or moving set_ref_id before has_seen to make the logic clearer. The block implementation in class-contact-form-block.php only uses one check (at line 813) before set_ref_id (at line 860), which is clearer.
| // Circular reference prevention. | |
| if ( self::has_seen( $ref_id ) ) { | |
| return ''; | |
| } |
Code Coverage SummaryCoverage changed in 2 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
…tribute Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Add ref support for the
Proposed changes:
refattribute in the[contact-form]shortcode to load form content from ajetpack_formpost[contact-form ref='1234']now properly loads the form from the referencedjetpack_formpost, matching the behavior of the block versionOther information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Enable
Central Form Managementjetpack_formpost via the Forms dashboard (WP Admin > Forms > Add New)post=123)[contact-form ref="123"](using your form's ID)jetpack_formshould be displayedrefattribute