Skip to content

Instantly share code, notes, and snippets.

@trgino
Created January 28, 2020 14:31
Show Gist options
  • Save trgino/078c2eeaae82ba5e301739638456d483 to your computer and use it in GitHub Desktop.
Save trgino/078c2eeaae82ba5e301739638456d483 to your computer and use it in GitHub Desktop.
<?php
function ohub_cf7_handle_success_submission( $contact_form ) {
global $wpdb;
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
$table_name = $wpdb->prefix.'log_mail';
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$wpdb->insert(
$table_name,
array(
'ctime' => time(),
'status' => 1,
'form' => (!empty($title) ? sanitize_title($title) : $title),
'urun' => (isset($posted_data['product']) ? $posted_data['product'] : '-'),
'isim' => (isset($posted_data['your-name']) ? $posted_data['your-name'] : '-'),
'eposta' => (isset($posted_data['your-email']) ? $posted_data['your-email'] : '-'),
'telefon' => (isset($posted_data['your-phone']) ? $posted_data['your-phone'] : '-'),
'firma' => (isset($posted_data['your-company']) ? $posted_data['your-company'] : '-'),
'konu' => (isset($posted_data['your-subject']) ? $posted_data['your-subject'] : '-'),
'mesaj' => (isset($posted_data['your-message']) ? $posted_data['your-message'] : '-')
),
array(
'%d',
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
)
);
}
}
add_action( 'wpcf7_mail_sent', 'ohub_cf7_handle_success_submission' );
function ohub_cf7_handle_failed_submission( $contact_form ) {
global $wpdb;
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
$table_name = $wpdb->prefix.'log_mail';
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$wpdb->insert(
$table_name,
array(
'ctime' => time(),
'status' => 2,
'form' => (!empty($title) ? sanitize_title($title) : $title),
'urun' => (isset($posted_data['product']) ? $posted_data['product'] : '-'),
'isim' => (isset($posted_data['your-name']) ? $posted_data['your-name'] : '-'),
'eposta' => (isset($posted_data['your-email']) ? $posted_data['your-email'] : '-'),
'telefon' => (isset($posted_data['your-phone']) ? $posted_data['your-phone'] : '-'),
'firma' => (isset($posted_data['your-company']) ? $posted_data['your-company'] : '-'),
'konu' => (isset($posted_data['your-subject']) ? $posted_data['your-subject'] : '-'),
'mesaj' => (isset($posted_data['your-message']) ? $posted_data['your-message'] : '-')
),
array(
'%d',
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
)
);
}
}
add_action( 'wpcf7_mail_failed', 'ohub_cf7_handle_failed_submission' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment