Last active
July 27, 2020 06:01
-
-
Save zxcnasab/b3054dd6c05fcd5d42576cfb734a60fc to your computer and use it in GitHub Desktop.
Modify CF7 Data Before Submission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wpcf7_before_send_mail', 'wpcf7_custom_data', 90, 1 ); | |
function wpcf7_custom_data( $WPCF7_ContactForm ){ | |
// Submission object, that generated when the user click the submit button. | |
$submission = WPCF7_Submission :: get_instance(); | |
if ( $submission ){ | |
$posted_data = $submission->get_posted_data(); | |
if ( empty( $posted_data ) ){ return; } | |
// Got ip data | |
$ip_data = $posted_data['ip']; | |
$ipv6 = $_SERVER['REMOTE_ADDR']; | |
// Got e-mail text | |
$mail = $WPCF7_ContactForm->prop( 'mail' ); | |
// Replace "[ip]" field inside e-mail text | |
$new_mail = str_replace( '[ip]', $ipv6, $mail ); | |
// Set | |
$WPCF7_ContactForm->set_properties( array( 'mail' => $new_mail ) ); | |
return $WPCF7_ContactForm; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment