-
Notifications
You must be signed in to change notification settings - Fork 154
Feat/integration specific ai builder #1754
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: develop
Are you sure you want to change the base?
Feat/integration specific ai builder #1754
Conversation
WalkthroughThis PR adds integration support to the AI Form Builder, allowing users to select from available integrations (WooCommerce, EDD, Events Calendar) when generating forms. Changes include frontend UI for integration selection, REST endpoints to fetch available integrations, integration-specific system prompts, and enhanced form settings management. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
🧹 Nitpick comments (5)
includes/AI_Manager.php (1)
106-114: Consider sanitizing$_GET['page']input.While this code runs in an authenticated admin context and the value is only used for comparison (not stored or output), it's good practice to sanitize superglobal access. The static analysis tool flagged this for nonce verification, but since this is just determining context during script enqueueing (not processing a form submission), nonce verification isn't strictly necessary here.
Apply this diff for improved defensive coding:
// Determine form type based on current admin page $form_type = 'post'; // Default to post if ( isset( $_GET['page'] ) ) { - if ( 'wpuf-profile-forms' === $_GET['page'] ) { + $page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); + if ( 'wpuf-profile-forms' === $page ) { $form_type = 'profile'; - } elseif ( 'wpuf-post-forms' === $_GET['page'] ) { + } elseif ( 'wpuf-post-forms' === $page ) { $form_type = 'post'; } }includes/AI/RestController.php (2)
489-496: Remove unused loop variable$key.The static analysis correctly identified that
$keyis unused in the foreach loop.Apply this diff:
// Filter integrations based on form type and enabled status $available_integrations = []; - foreach ( $all_integrations as $key => $integration ) { + foreach ( $all_integrations as $integration ) { // Only include if enabled and supports the current form type if ( $integration['enabled'] && in_array( $form_type, $integration['form_types'], true ) ) { $available_integrations[] = $integration; } }
462-487: Consider caching integration availability checks.The
class_existschecks for WooCommerce, EDD, and Events Calendar run on every API request. While these are fast operations, consider caching the result using a transient if this endpoint is called frequently.This is a minor optimization that could be deferred. The current implementation is functionally correct.
assets/js/components/FormInputStage.vue (2)
271-342: Consider extracting default prompts to reduce duplication.The default post form prompts (lines 323-340) duplicate the initial prompts in
data()(lines 148-165). Consider extracting to a constant or shared method for maintainability.// At the top of the script, before export default: const DEFAULT_POST_PROMPTS = { templates: [ { id: 'paid_guest_post', label: 'Paid Guest Post' }, // ... other templates ], instructions: { paid_guest_post: 'Create a Paid Guest Post submission form...', // ... other instructions } }; // Then use in both data() and updatePromptTemplates(): // this.promptTemplates = DEFAULT_POST_PROMPTS.templates.map(t => ({...t, label: this.__(t.label, 'wp-user-frontend')}));
187-190: Consider usingloadingIntegrationsstate in the UI.The
loadingIntegrationsstate is tracked but not reflected in the UI. Consider showing a loading indicator or disabling the select while loading.<select v-model="selectedIntegration" + :disabled="loadingIntegrations" class="..."
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
assets/js/components/AIFormBuilder.vue(4 hunks)assets/js/components/FormInputStage.vue(5 hunks)includes/AI/FormGenerator.php(2 hunks)includes/AI/Form_Builder.php(1 hunks)includes/AI/RestController.php(5 hunks)includes/AI/wpuf-ai-prompt-edd.md(1 hunks)includes/AI/wpuf-ai-prompt-events-calendar.md(1 hunks)includes/AI/wpuf-ai-prompt-woocommerce.md(1 hunks)includes/AI_Manager.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
includes/AI/FormGenerator.php (1)
wpuf-functions.php (1)
wpuf_is_pro_active(4988-4990)
🪛 GitHub Check: Run PHPCS inspection
includes/AI_Manager.php
[warning] 111-111:
Processing form data without nonce verification.
[warning] 109-109:
Processing form data without nonce verification.
[warning] 108-108:
Processing form data without nonce verification.
🪛 LanguageTool
includes/AI/wpuf-ai-prompt-woocommerce.md
[uncategorized] ~423-~423: Did you mean the formatting language “Markdown” (= proper noun)?
Context: ...ur form" or ANY other text - DO NOT use markdown code blocks (no ```) - DO NOT add expla...
(MARKDOWN_NNP)
includes/AI/wpuf-ai-prompt-events-calendar.md
[grammar] ~143-~143: Use a hyphen to join words.
Context: ...y-mm-dd", "time": "yes" } ### All Day Event:json { "template": "chec...
(QB_NEW_EN_HYPHEN)
[uncategorized] ~365-~365: Did you mean the formatting language “Markdown” (= proper noun)?
Context: ...ur form" or ANY other text - DO NOT use markdown code blocks (no ```) - DO NOT add expla...
(MARKDOWN_NNP)
includes/AI/wpuf-ai-prompt-edd.md
[uncategorized] ~282-~282: Did you mean the formatting language “Markdown” (= proper noun)?
Context: ...ur form" or ANY other text - DO NOT use markdown code blocks (no ```) - DO NOT add expla...
(MARKDOWN_NNP)
🪛 PHPMD (2.15.0)
includes/AI/RestController.php
491-491: Avoid unused local variables such as '$key'. (undefined)
(UnusedLocalVariable)
🔇 Additional comments (19)
includes/AI_Manager.php (1)
116-129: LGTM!The
formTypeis correctly added to the localization data, enabling the frontend to determine which integrations to display based on the current form context.includes/AI/Form_Builder.php (2)
78-78: LGTM!The call to
merge_form_settingscorrectly passes the AI settings with a null-coalescing fallback to an empty array, ensuring the merge logic handles both present and absent settings gracefully.
82-93: LGTM!The
merge_form_settingshelper is well-implemented. Usingarray_mergecorrectly gives AI-provided settings precedence over defaults. This approach is clean and follows the single responsibility principle.includes/AI/FormGenerator.php (2)
708-709: Consider using the existing helper function consistently.The code uses
function_exists( 'wpuf_is_pro_active' ) && wpuf_is_pro_active()here, which is correct. This pattern is safe since the function is defined in wpuf-functions.php. The defensive check is appropriate.
742-765: LGTM!The Pro version guidance is correctly scoped to integration forms only, providing context-aware field recommendations. The WooCommerce and Events Calendar specific notes help the AI generate appropriate field types based on the plugin version.
includes/AI/wpuf-ai-prompt-woocommerce.md (3)
34-54: LGTM!The form_settings with
post_type: "product"is correctly documented as mandatory for WooCommerce forms. The example JSON structure is clear and matches the expected format.
56-64: Good emphasis on WooCommerce-specific taxonomies.The critical notes about using
product_catandproduct_taginstead of generic WordPress taxonomies are important for correct form generation. This guidance will help prevent common integration issues.
265-275: Based on the verification attempt, I've encountered limitations in accessing the repository directly. However, the web search results provide some insight:The web search indicates that
numeric_text_fieldis available in both WP User Frontend and WP User Frontend Pro, suggesting it may not be an exclusive Pro feature. However, the results are somewhat ambiguous about the distinction between free and Pro availability.Since I cannot access the file to verify:
- Whether the prompt header actually marks this as a Pro field
- How the pricing field documentation handles Pro guidance
- The document's overall scope and audience
I cannot definitively confirm or refute the original review comment's concern.
Manual verification is needed to confirm whether
numeric_text_fieldfor Stock Quantity is documented as Pro-only and whether comparable Pro-feature guidance exists for other fields in this prompt file.includes/AI/RestController.php (3)
101-107: LGTM!The
integrationparameter is properly defined with validation (enum), sanitization, and sensible defaults. The empty string in the enum allows for "no integration" selection.
145-159: LGTM!The new
/integrationsendpoint is correctly registered with proper permission callback and form_type filtering parameter. The enum validation ensures only valid form types are accepted.
305-308: LGTM!The integration is correctly propagated into the conversation context when provided, enabling the FormGenerator to select the appropriate integration-specific prompt.
includes/AI/wpuf-ai-prompt-edd.md (1)
1-325: LGTM! Comprehensive EDD prompt template.The prompt correctly enforces EDD-specific requirements including
post_type: "download", EDD taxonomies (download_category,download_tag), and meta fields (edd_price,edd_download_files,edd_product_notes). The JSON examples are valid and the documentation is thorough.assets/js/components/AIFormBuilder.vue (2)
8-14: LGTM! Integration prop and event handling properly wired.The bi-directional binding for
selectedIntegrationbetween parent and child components is correctly implemented using the prop and event pattern.
115-143: LGTM! API call correctly handles optional integration parameter.The integration parameter is conditionally added to the request body only when provided, maintaining backward compatibility.
includes/AI/wpuf-ai-prompt-events-calendar.md (1)
1-53: Well-structured Events Calendar prompt template.The prompt correctly enforces TEC-specific requirements including
post_type: "tribe_events", proper taxonomy usage (tribe_events_cat), and meta field conventions with_Eventprefix.assets/js/components/FormInputStage.vue (4)
30-53: LGTM! Integration selector UI implementation.The selector is conditionally rendered only for post forms with available integrations, uses appropriate form styling, and includes helpful description text.
223-255: LGTM! Integration fetching with proper error handling.The fetch logic correctly handles the REST API call with appropriate headers, checks response status, and gracefully handles errors without breaking the UI.
257-269: LGTM! Clean state management on integration change.Properly clears prompt selection and form description when integration changes, ensuring a clean slate for the new integration's prompts.
364-372: LGTM! Generation payload includes integration.The start-generation event correctly includes the selected integration alongside the description and prompt.
| // Get integration type from context if provided | ||
| $integration = $context['integration'] ?? ''; | ||
|
|
||
| // Check if Pro is active using the proper function | ||
| $is_pro_active = function_exists( 'wpuf_is_pro_active' ) && wpuf_is_pro_active(); | ||
|
|
||
| // Determine which prompt file to use based on form type and integration | ||
| if ( 'profile' === $form_type || 'registration' === $form_type ) { | ||
| // Registration/Profile form prompt - USE MINIMAL REGISTRATION PROMPT | ||
| // Registration/Profile form - use registration prompt | ||
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt-registration.md'; | ||
| } else { | ||
| // Post form prompt - USE MINIMAL PROMPT | ||
| } elseif ( 'post' === $form_type && ! empty( $integration ) ) { | ||
| // Post form WITH integration - use integration-specific prompts | ||
| $integration_prompts = [ | ||
| 'woocommerce' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-woocommerce.md', | ||
| 'edd' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-edd.md', | ||
| 'events_calendar' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-events-calendar.md', | ||
| ]; | ||
|
|
||
| // Use integration prompt if available, fallback to minimal prompt | ||
| if ( isset( $integration_prompts[ $integration ] ) && file_exists( $integration_prompts[ $integration ] ) ) { | ||
| $prompt_file = $integration_prompts[ $integration ]; | ||
| } else { | ||
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | ||
| } | ||
| } elseif ( 'post' === $form_type && empty( $integration ) ) { | ||
| // Post form WITHOUT integration - use minimal prompt | ||
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; |
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.
Potential uninitialized variable if form_type has unexpected value.
The conditional logic covers profile, registration, and post form types, but if $form_type is something else (e.g., an empty string or unexpected value), $prompt_file would be uninitialized, causing an error at line 735.
Consider adding a fallback:
} elseif ( 'post' === $form_type && empty( $integration ) ) {
// Post form WITHOUT integration - use minimal prompt
$prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md';
+ } else {
+ // Fallback for any unexpected form_type
+ $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md';
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Get integration type from context if provided | |
| $integration = $context['integration'] ?? ''; | |
| // Check if Pro is active using the proper function | |
| $is_pro_active = function_exists( 'wpuf_is_pro_active' ) && wpuf_is_pro_active(); | |
| // Determine which prompt file to use based on form type and integration | |
| if ( 'profile' === $form_type || 'registration' === $form_type ) { | |
| // Registration/Profile form prompt - USE MINIMAL REGISTRATION PROMPT | |
| // Registration/Profile form - use registration prompt | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt-registration.md'; | |
| } else { | |
| // Post form prompt - USE MINIMAL PROMPT | |
| } elseif ( 'post' === $form_type && ! empty( $integration ) ) { | |
| // Post form WITH integration - use integration-specific prompts | |
| $integration_prompts = [ | |
| 'woocommerce' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-woocommerce.md', | |
| 'edd' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-edd.md', | |
| 'events_calendar' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-events-calendar.md', | |
| ]; | |
| // Use integration prompt if available, fallback to minimal prompt | |
| if ( isset( $integration_prompts[ $integration ] ) && file_exists( $integration_prompts[ $integration ] ) ) { | |
| $prompt_file = $integration_prompts[ $integration ]; | |
| } else { | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | |
| } | |
| } elseif ( 'post' === $form_type && empty( $integration ) ) { | |
| // Post form WITHOUT integration - use minimal prompt | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | |
| // Get integration type from context if provided | |
| $integration = $context['integration'] ?? ''; | |
| // Check if Pro is active using the proper function | |
| $is_pro_active = function_exists( 'wpuf_is_pro_active' ) && wpuf_is_pro_active(); | |
| // Determine which prompt file to use based on form type and integration | |
| if ( 'profile' === $form_type || 'registration' === $form_type ) { | |
| // Registration/Profile form - use registration prompt | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt-registration.md'; | |
| } elseif ( 'post' === $form_type && ! empty( $integration ) ) { | |
| // Post form WITH integration - use integration-specific prompts | |
| $integration_prompts = [ | |
| 'woocommerce' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-woocommerce.md', | |
| 'edd' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-edd.md', | |
| 'events_calendar' => WPUF_ROOT . '/includes/AI/wpuf-ai-prompt-events-calendar.md', | |
| ]; | |
| // Use integration prompt if available, fallback to minimal prompt | |
| if ( isset( $integration_prompts[ $integration ] ) && file_exists( $integration_prompts[ $integration ] ) ) { | |
| $prompt_file = $integration_prompts[ $integration ]; | |
| } else { | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | |
| } | |
| } elseif ( 'post' === $form_type && empty( $integration ) ) { | |
| // Post form WITHOUT integration - use minimal prompt | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | |
| } else { | |
| // Fallback for any unexpected form_type | |
| $prompt_file = WPUF_ROOT . '/includes/AI/wpuf-ai-minimal-prompt.md'; | |
| } |
🤖 Prompt for AI Agents
In includes/AI/FormGenerator.php around lines 705 to 731, the conditional sets
$prompt_file only for 'profile', 'registration', and 'post' cases, leaving
$prompt_file uninitialized for any other $form_type; add a final fallback branch
or initialize $prompt_file before the condition to a sensible default (e.g., the
minimal prompt path) so $prompt_file is always defined, and ensure any
file_exists checks still apply when using the fallback.
| ```json | ||
| ### Event Address: | ||
| ```json | ||
| { | ||
| "template": "text_field", | ||
| "label": "Event Address", | ||
| ``` |
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.
Fix malformed JSON example - appears to be a copy-paste error.
This section has a formatting issue with nested markdown code blocks and an incomplete JSON example. The "Event Address" field example is truncated.
Apply this diff to fix the malformed section:
-```json
-### Event Address:
-```json
-{
- "template": "text_field",
- "label": "Event Address",
-```
+### Event Address:
+```json
+{
+ "template": "text_field",
+ "label": "Event Address",
+ "name": "_EventAddress",
+ "is_meta": "yes",
+ "placeholder": "Enter event address"
+}
+```🤖 Prompt for AI Agents
In includes/AI/wpuf-ai-prompt-events-calendar.md around lines 236 to 242, the
Event Address example contains a malformed/truncated JSON block and
nested/missing code fences; replace the broken snippet with a well-formed JSON
code block that includes the full example fields (template, label, name,
is_meta, placeholder) and ensure the code block opens with ```json and closes
with ``` so the example renders correctly.
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
@arifulhoque7 vai
2 fields are missing for all kind of woocommerce form
2 fields are missing for digital product form
While regenerating form, it's not loading woocommerce or edd templates automatically as pre-selected Screen.Recording.2025-12-02.at.4.08.23.PM.mov
2 fields are missing for digital downloads form
Unnecessary field (product tag) for product form according to manual woo tmplate creation |




Close issue
AI Form Builder with Pre-built Integration Templates for WooCommerce, EDD, and The Events Calendar
📋 Overview
This feature adds integration-specific AI form generation capabilities to the WP User Frontend AI Form Builder, enabling users to create specialized forms for popular WordPress plugins with pre-configured field structures and intelligent prompts.
✨ Key Features
🎯 Integration Selector UI
🤖 Specialized AI Prompts
Added three comprehensive prompt templates with precise field structures:
wpuf-ai-prompt-woocommerce.md(463 lines)post_type: "product"automaticallywpuf-ai-prompt-edd.md(325 lines)post_type: "download"automaticallywpuf-ai-prompt-events-calendar.md(408 lines)post_type: "tribe_events"automatically🔌 Backend API
GET /wpuf/v1/ai-form-builder/integrationsAI_Manager.phpFormGenerator.php📁 Modified Files
File | Changes | Lines -- | -- | -- assets/js/components/AIFormBuilder.vue | Integration state management | +42 assets/js/components/FormInputStage.vue | Integration selector UI | +167 includes/AI/FormGenerator.php | Integration-specific prompts | +53 includes/AI/Form_Builder.php | Integration context passing | +15 includes/AI/RestController.php | Integrations endpoint | +86 includes/AI_Manager.php | Integration detection | +11New Files:
includes/AI/wpuf-ai-prompt-woocommerce.md(+463 lines)includes/AI/wpuf-ai-prompt-edd.md(+325 lines)includes/AI/wpuf-ai-prompt-events-calendar.md(+408 lines)Total: +1,548 lines, -22 lines
🎨 User Experience
Before:
After:
_regular_price, EDD pricing tiers, Event date/time fieldspost_typeconfiguration🌍 Multilingual Support
All prompts include:
🔧 Technical Details
Integration Detection:
API Response Format:
✅ Testing Checklist
post_typeis set correctly in form settingsis_meta: "yes"🚀 Ready for Review
This feature significantly enhances the AI Form Builder by providing intelligent, plugin-specific form generation that reduces setup time and ensures compatibility with popular WordPress eCommerce and events plugins.
Branch:
feat/integration-specific-ai-builderBase:
developCommits: 1 feature commit
Status: ✅ Ready for review
Summary by CodeRabbit
Release Notes
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.