How to fully publish/render give_forms when creating programmatically via Zapier w/WPForms as trigger? #7390
Replies: 2 comments
-
I've also tried the following ~gist (to no avail): `function update_newly_created_post($post_id) {
} add_action('some_hook_that_triggers_after_post_creation', 'update_newly_created_post'); |
Beta Was this translation helpful? Give feedback.
-
I can now populate and edit all necessary/applicable options for a new donation form programmatically via my frontend form (as well as other methods, such as Webhooks, etc). The ONLY issue preventing full autonomous form creation is there is something within the GiveWP code base handling the publishing/updating for new post/give_forms (including insertion into the database). Everything is there in the new form, all options, custom text, colors, uploaded images...I can see all in the form settings, BUT nothing renders correctly, nor inserts/populates the applicable database tables until I physically go to the wp-admin/edit page and click on the 'Update' button. I've written multiple variations of custom plugins to mimic this action...all to no avail. I've scoured your code base and cannot find what is preventing my additional efforts. PLEASE HELP! This functionality is the basis of our entire business model. |
Beta Was this translation helpful? Give feedback.
-
(I have GiveWP Agency Plan and WPForms Elite plan, if it matters) I am trying to automatically create new donation forms and subsequent P2P campaigns via Zapier using WPForms frontend form submittal as the trigger. I have tried using 'post submissions' in WPForms settings. I have also used Wordpress REST-API...have also used Webhooks by Zapier to POST.
I added the following to my functions.php:
`add_action('rest_api_init', function () {
$meta_fields = [
'_give_form_template',
'_give_goal_option',
'_give_set_goal',
'_give_goal_color',
'_give_goal_format',
'_give_from_name',
'_give_from_email',
'_affwp_give_allow_referrals',
'_give_recurring',
'_give_period_functionality',
'_give_period',
'_give_period_interval',
'_give_price_option',
'_give_form_goal_progress',
'give_pdf_colorpicker',
'give_pdf_company_name',
'give_pdf_email_address',
'give_pdf_header_message',
'give_pdf_logo_upload',
'give_pdf_name',
'give_pdf_receipts_enable_disable',
'affwp_landing_page_user_name',
'give_pdf_address_line1',
'give_pdf_address_line2',
'give_pdf_address_city_state_zip',
'_give_form_status',
'_give_anonymous_donation',
'_form_give_fee_recovery',
'_form_give_fee_mode',
'_give_custom_amount',
'_give_sequoia_form_template_settings' // This is your complex nested field
];
});`
Both methods worked, I can fully populate all the fields and settings, even setting 'sequoia' as the template, etc. I can see the form in the menu Donations->All Forms....however, the form does not display/function properly (doesn't show goal bar, custom amount, recurring, etc) or appear in the database until I physically/manually click the 'UPDATE' button on the wp-admin/edit page. Once I've done this, everything functions/displays as expected per the meta values I've posted, etc.
I've even tried direct database manipulation, mimicking the new rows in _posts, _postmeta, _give_campains, _give_formmeta, and _give_p2p_campaigns created during the new form/P2P Campaign creation process. This also posted all my fields and settings but did not fully initiate the resulting form until I manually clicked 'UPDATE' on the edit page.
I've written a dropin plugin in an attempt to auto update the post...this didn't work either
`<?php
/**
*/
// Register a post save hook for
give_forms
add_action('save_post_give_forms', 'wp_post_auto_update_on_creation', 10, 3);
/**
Callback to update the post as if manually clicking "Update".
@param int $post_id The post ID.
@param WP_Post $post The post object.
@param bool $update Whether it's an existing post being updated.
*/
function wp_post_auto_update_on_creation($post_id, $post, $update)
{
// Skip if it's an update or post revision
if ($update || wp_is_post_revision($post_id)) {
return;
}
// Ensure the '_give_donation_levels' meta key is populated
$default_donation_levels = [
[
'_give_id' => ['level_id' => '0'],
'_give_amount' => '10.000000',
'_give_text' => '',
'_give_recurring' => 'yes',
'_give_period_interval' => '1',
'_give_period' => 'month',
'_give_times' => '0',
],
[
'_give_id' => ['level_id' => '1'],
'_give_amount' => '25.000000',
'_give_text' => '',
'_give_recurring' => 'yes',
'_give_period_interval' => '1',
'_give_period' => 'month',
'_give_times' => '0',
],
[
'_give_id' => ['level_id' => '2'],
'_give_amount' => '50.000000',
'_give_text' => '',
'_give_recurring' => 'yes',
'_give_period_interval' => '1',
'_give_period' => 'month',
'_give_times' => '0',
],
[
'_give_id' => ['level_id' => '3'],
'_give_amount' => '100.000000',
'_give_text' => '',
'_give_default' => 'default',
'_give_recurring' => 'yes',
'_give_period_interval' => '1',
'_give_period' => 'month',
'_give_times' => '0',
],
[
'_give_id' => ['level_id' => '5'],
'_give_amount' => '250.000000',
'_give_text' => '',
'_give_recurring' => 'yes',
'_give_period_interval' => '1',
'_give_period' => 'month',
'_give_times' => '0',
],
];
update_post_meta($post_id, '_give_donation_levels', $default_donation_levels);
// Create the PDF template for the donation form
$pdf_template_id = wp_insert_post([
'post_title' => $post->post_title . ' Receipt',
'post_type' => 'give_pdf_template',
'post_status' => 'publish',
'post_parent' => $post_id,
'guid' => get_site_url(null, 'give_pdf_template/' . sanitize_title($post->post_title) . '/'),
]);
// Add default metadata for the PDF template
if (!is_wp_error($pdf_template_id) && $pdf_template_id > 0) {
update_post_meta($pdf_template_id, 'give_pdf_receipts_enable_disable', 'enabled');
update_post_meta($pdf_template_id, 'give_pdf_name', $post->post_title . ' Receipt');
update_post_meta($pdf_template_id, 'give_pdf_colorpicker', '#256aba');
}
// Log the result
$log_message = $pdf_template_id > 0 ? "Success: Post ID $post_id updated, PDF Template ID $pdf_template_id created." : "Error: Unable to update Post ID $post_id or create PDF Template.";
error_log(date('Y-m-d H:i:s') . " - $log_message\n", 3, WP_CONTENT_DIR . '/wp-auto-update-log.txt');
}
`
What else can I do to automatically update the new form so that it renders correctly and ultimately registers in the database correctly, etc after I've created it programmatically?
Beta Was this translation helpful? Give feedback.
All reactions