Skip to content

Commit 8f1a89c

Browse files
committed
CF7 to ACF Supporters
1 parent ae19b19 commit 8f1a89c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

themes/osi/functions.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,28 @@ function osi_wpdc_comment_body( string $comment_body ) {
425425
return $trimmed_comment_body;
426426
}
427427
add_filter( 'wpdc_comment_body', 'osi_wpdc_comment_body', 10, 1 );
428+
429+
/**
430+
*
431+
* Create a new Supporter in ACF, based on a Contact Forms 7 submission.
432+
*
433+
*/
434+
add_action('wpcf7_before_send_mail', 'save_form_data_to_cpt');
435+
function save_form_data_to_cpt($contact_form) {
436+
$submission = WPCF7_Submission::get_instance();
437+
if ($submission) {
438+
$data = $submission->get_posted_data();
439+
440+
$post_id = wp_insert_post(array(
441+
'post_title' => $data['your-name'],
442+
'post_type' => 'supporter',
443+
'post_status' => 'pending'
444+
));
445+
update_field('name', $data['your-name'], $post_id);
446+
update_field('organization', $data['your-org'], $post_id);
447+
update_field('endorsement_type', $data['your-endorsement'], $post_id);
448+
update_field('quote', $data['your-message'], $post_id);
449+
} else {
450+
error_log('WPCF7_Submission instance is null.');
451+
}
452+
}

0 commit comments

Comments
 (0)