Skip to content

Forms: Add ref support to the contact-form shortcode#47129

Open
enejb wants to merge 2 commits intotrunkfrom
fix/missing-shortcode-ref-attribute
Open

Forms: Add ref support to the contact-form shortcode#47129
enejb wants to merge 2 commits intotrunkfrom
fix/missing-shortcode-ref-attribute

Conversation

@enejb
Copy link
Member

@enejb enejb commented Feb 13, 2026

Add ref support for the

Proposed changes:

  • Add support for the ref attribute in the [contact-form] shortcode to load form content from a jetpack_form post
  • The shortcode [contact-form ref='1234'] now properly loads the form from the referenced jetpack_form post, matching the behavior of the block version
  • Includes circular reference prevention to avoid infinite loops
  • Validates that referenced form exists, is the correct post type, and is published (or user can edit)

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

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

No.

Testing instructions:

Enable Central Form Management

add_filter( 'jetpack_block_editor_feature_flags', 'eb_register_feature' );
function eb_register_feature( $flags ) {
    $flags['central-form-management'] = true;
    return $flags;
}
  1. Create a new jetpack_form post via the Forms dashboard (WP Admin > Forms > Add New)
  2. Add some form fields (e.g., Name, Email, Message) and publish the form
  3. Note the form's post ID from the URL (e.g., post=123)
  4. In a post or page, add the shortcode: [contact-form ref="123"] (using your form's ID)
  5. View the post/page on the frontend and submit the form.
  6. Expected: The form fields from the referenced jetpack_form should be displayed
  7. Before this fix: The shortcode would render a default form, ignoring the ref attribute

Copilot AI review requested due to automatic review settings February 13, 2026 18:25
@enejb enejb added the [Status] Needs Review This PR is ready for review. label Feb 13, 2026
@enejb enejb self-assigned this Feb 13, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2026

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/missing-shortcode-ref-attribute branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/missing-shortcode-ref-attribute

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
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 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!

@enejb enejb force-pushed the fix/missing-shortcode-ref-attribute branch from 955efea to c2e6dac Compare February 13, 2026 18:27
@github-actions github-actions bot added the [Block] Contact Form Form block (also see Contact Form label) label Feb 13, 2026
…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>
@enejb enejb force-pushed the fix/missing-shortcode-ref-attribute branch from c2e6dac to c90e8c5 Compare February 13, 2026 18:30
Copy link
Contributor

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 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 from jetpack_form posts
  • Modified the parse() method to handle the ref attribute 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

Comment on lines +218 to +222
// Circular reference prevention.
if ( self::has_seen( $ref_id ) ) {
return '';
}

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
// Circular reference prevention.
if ( self::has_seen( $ref_id ) ) {
return '';
}

Copilot uses AI. Check for mistakes.
@jp-launch-control
Copy link

jp-launch-control bot commented Feb 13, 2026

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form.php 952/1518 (62.71%) -1.11% 40 💔
projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php 567/609 (93.10%) 5.36% -40 💚

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@enejb enejb changed the title Forms: fix shortcode ref attribute to load form from jetpack_form post type Forms: Add ref support to the contact-form shortcode Feb 13, 2026
…tribute

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 13, 2026 19:06
Copy link
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant