Created
September 19, 2021 15:57
-
-
Save idokd/d49d6637ab03451d23e15c21c99f7f5d to your computer and use it in GitHub Desktop.
WordPress + Mailgun plugin - Apply Template to all WordPress mail
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 | |
| /* | |
| This code with conjunction of Wordpress Mailgun plugin will force all wordpress mails to apply mailgun wordpress to all mail, | |
| This could be easy way to beautify emails. | |
| use {{subject}} {{text}} or {{{html}}} - see that html has triple {{{ in order to use raw content and not escape special chars | |
| */ | |
| add_filter( 'mg_mutate_message_body', function( $body ) { | |
| $body[ 'template' ] = 'wordpress'; | |
| $vars = []; | |
| $vars[ 'subject' ] = $body[ 'subject' ]; | |
| $vars[ 'text' ] = $body[ 'text' ]; | |
| $vars[ 'html' ] = !isset( $body[ 'html' ] ) || !$body[ 'html' ] ? nl2br( $body[ 'text' ] ) : null; | |
| $vars[ 'body' ] = isset( $vars[ 'html' ] ) && $vars[ 'html' ] ? $vars[ 'html' ] : $vars[ 'text' ]; | |
| $body[ 'h:X-Mailgun-Variables' ] = json_encode( $vars ); | |
| return( $body ); | |
| }, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment