Skip to content

Commit de16566

Browse files
author
Ariel Jolo
committed
Clean up
1 parent e096728 commit de16566

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

themes/osi/functions.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -427,26 +427,37 @@ function osi_wpdc_comment_body( string $comment_body ) {
427427
add_filter( 'wpdc_comment_body', 'osi_wpdc_comment_body', 10, 1 );
428428

429429
/**
430-
*
431430
* Create a new Supporter in ACF, based on a Contact Forms 7 submission.
432-
*
433431
*/
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-
}
432+
433+
add_action( 'wpcf7_before_send_mail', 'save_form_data_to_cpt' );
434+
435+
/**
436+
* Save form data to a custom post type.
437+
*
438+
* @param WPCF7_ContactForm $contact_form The Contact Form 7 instance.
439+
*/
440+
function save_form_data_to_cpt( $contact_form ) {
441+
$submission = WPCF7_Submission::get_instance();
442+
443+
if ( $submission ) {
444+
$data = $submission->get_posted_data();
445+
446+
$post_id = wp_insert_post(
447+
array(
448+
'post_title' => $data['your-name'],
449+
'post_type' => 'supporter',
450+
'post_status' => 'pending',
451+
)
452+
);
453+
454+
if ( $post_id ) {
455+
update_field( 'name', $data['your-name'], $post_id );
456+
update_field( 'organization', $data['your-org'], $post_id );
457+
update_field( 'endorsement_type', $data['your-endorsement'], $post_id );
458+
update_field( 'quote', $data['your-message'], $post_id );
459+
} else {
460+
error_log( 'Failed to insert post for supporter.' );
461+
}
462+
}
452463
}

0 commit comments

Comments
 (0)