Forms: Add PHP foundation for custom field extensibility#47931
Forms: Add PHP foundation for custom field extensibility#47931
Conversation
Add filter hooks to enable external developers to create custom form fields: - jetpack_forms_validate_field: Custom validation for field types - jetpack_forms_render_field: Custom frontend field rendering - jetpack_forms_render_field_value: Custom value rendering for different contexts - jetpack_forms_field_types: Register custom field types - jetpack_forms_error_types: Add custom error messages These filters form the foundation of the field extensibility API. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add a new class that provides a WordPress-style registration API similar to register_post_type(). External developers can use register_jetpack_form_field() to register custom form fields with a single function call. The registry handles: - Block registration with PHP - Validation callback registration - Frontend field rendering - Response value rendering for different contexts (email, CSV, API) - Error message registration - Editor and dashboard script enqueueing Global functions added: - register_jetpack_form_field($type, $args) - get_jetpack_form_field($type) - jetpack_form_field_exists($type) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update Form_Editor to include custom registered field blocks in the allowed blocks list. This enables custom fields registered via register_jetpack_form_field() to appear in the block inserter when editing jetpack-form post types. Also adds a filter 'jetpack_form_editor_allowed_blocks' for plugins to add additional blocks to the form editor. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive PHPUnit tests for the field extensibility system: Form_Field_Registry_Test (38 tests): - Registration API tests (global functions, validation) - Filter integration tests (field types, validation, rendering) - Error message registration tests - Block name generation tests Field_Extensibility_Test (19 tests): - Core filter hook tests for Contact_Form_Field and Feedback_Field - Integration tests verifying Form_Field_Registry works with existing classes - End-to-end workflow tests All tests verify that custom fields can be registered, validated, and rendered across different contexts (email, CSV, API, dashboard). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <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! |
|
@claude review this PR. |
|
Claude finished @enejb's task in 2m 34s —— View job PR Review: Forms — Add PHP foundation for custom field extensibilityTasks:
Overall this is well-structured work that follows WordPress conventions closely. The Bug:
|
Code Coverage SummaryCoverage changed in 5 files.
2 files are newly checked for coverage.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Fixes #
Proposed changes
Contact_Form_Fieldfor custom field validation (jetpack_forms_validate_field), rendering (jetpack_forms_render_field), and field type registration (jetpack_forms_field_types)jetpack_forms_render_field_valuefilter toFeedback_Fieldfor custom value rendering across contexts (email, CSV, API, dashboard)jetpack_forms_error_typesfilter toContact_Formfor custom validation error messagesForm_Field_Registryclass providing a unifiedregister()API (similar toregister_post_type()) that handles block registration, validation, rendering, error messages, and asset enqueueing in one callform-field-functions.php:register_jetpack_form_field(),unregister_jetpack_form_field(),get_jetpack_form_field()Form_Field_Registry_Test) and the filter-based extensibility (Field_Extensibility_Test)Other information
This is PR 1/5 in the stacked custom field extensibility API series:
Form_Field_RegistryRelated product discussion/links
Does this pull request change what data or activity we track or use?
No changes to tracked data or activity.
Testing instructions
functions.php:Contact_Form_Field::get_registered_field_types()