Created
June 19, 2017 16:07
-
-
Save lukaswilkeer/f7bd9d4e5051881e52df536d936cd3f4 to your computer and use it in GitHub Desktop.
Send emails from wordpress using mailgun and wp hooks
This file contains 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 | |
require_once VENDOR_PATH . 'autoload.php'; | |
use Mailgun\Mailgun; | |
// WORDPRESS SHIT | |
// Email de aviso de post | |
function send_mail_post_pending_mailgun ($post_id, $post) { | |
$mgClient = new Mailgun('KEY'); | |
$domain = "DOMAIN.COM"; | |
$post_status = get_post_status( $post ); | |
if( $post_status === 'pending' && ! wp_is_post_revision( $post ) ) { | |
$email = get_option( 'admin_email' ); | |
$subject = '[REVISAR NOVO POST] ' . get_the_title( $post ); | |
$message = 'Existe um novo post para revisão: ' . get_the_title( $post ) . "\n\n"; | |
$message .= 'Revisar o post: ' . admin_url( "post.php?post={$post_id}&action=edit" ); | |
$data = array('from' => 'Mailgun Sandbox <[email protected]>', | |
'to' => $email, | |
'subject' => $subject, | |
'text' => $message); | |
$mgClient->sendMessage($domain, $data); | |
} | |
} | |
add_action('save_post', 'send_mail_post_pending_mailgun', 10, 2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment