Last active
July 17, 2018 09:45
-
-
Save AndreKelling/b2e22d38e229c8c0da0bb34412b8ff59 to your computer and use it in GitHub Desktop.
Wordpress / Contact Form 7 / Hook to wrap Header and Footer Templates around eMail HTML message body
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 | |
/** | |
* Displays mail template parts header and footer | |
*/ | |
add_action( 'wpcf7_before_send_mail', 'wpcf7_add_text_to_mail_body' ); | |
function wpcf7_add_text_to_mail_body($contact_form){ | |
// get mail property | |
$mail = $contact_form->prop( 'mail' ); // returns array | |
ob_start(); | |
// get header temlate from themes root (one above) | |
include_once( realpath(__DIR__ . '/..').'/mail-header.php'); | |
$header = ob_get_clean(); | |
$body = $mail['body']; | |
ob_start(); | |
// get footer temlate from themes root (one above) | |
include_once( realpath(__DIR__ . '/..').'/mail-footer.php'); | |
$footer = ob_get_clean(); | |
// add content back to email body | |
$mail['body'] = $header.$body.$footer; | |
// set mail property with changed value(s) | |
$contact_form->set_properties( array( 'mail' => $mail ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment