Skip to content

Instantly share code, notes, and snippets.

@aurooba
Last active June 2, 2017 23:12
Show Gist options
  • Save aurooba/99cbdc0d294d5471892a6faea9ae64a0 to your computer and use it in GitHub Desktop.
Save aurooba/99cbdc0d294d5471892a6faea9ae64a0 to your computer and use it in GitHub Desktop.
Post Notification
<?php
add_action("publish_post", "publication_notification");
//add_action("save_post", "publication_notification");
//add_action ( 'draft_to_publish', 'publication_notification', 10, 3);
function publication_notification($post_id) {
$post = get_post($post_id);
$coauthors = get_coauthors($post_id);
//This grabs the name and email address from Coauthors
$author_name = $coauthors[0]->display_name;
$author_email = $coauthors[0]->user_email;
$post_title = get_the_title($post_id);
$post_link = get_permalink($post_id);
$publish_date = get_the_time('F j, Y', $post_id);
// This is grabbing the text the admin sets up with the variables
// and replaces all the variables with the post appropriate info.
$variables = array('%post_title%', '%post_link%', '%publish_date%', '%author%');
$replacements = array($post_title, $post_link, $publish_date, $author_name);
$auno_subject = carbon_get_theme_option('crb_auno_subject');
$fixed_subject = str_replace($variables, $replacements, $auno_subject);
$auno_message = carbon_get_theme_option('crb_auno_message');
$fixed_message = str_replace($variables, $replacements, $auno_message);
$email_subject = $fixed_subject;
$message = $fixed_message;
wp_mail($author_email, $email_subject, $message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment