Created
January 21, 2016 13:53
-
-
Save celsowhite/57d72d6e5115d261cdcf to your computer and use it in GitHub Desktop.
Automatic emails sent to wordpress admins depending on the status of a post. Easy ability for team members to keep up to date with content publishing without going into the backend.
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
/*========================================= | |
Draft to Under Construction Project Hook | |
Upon changing the status of a post with a specific parent from draft to published, send an email notifying the team. | |
Codex reference: https://codex.wordpress.org/Post_Status_Transitions | |
=========================================*/ | |
function draft_to_under_construction_project( $new_status, $old_status, $post ) { | |
if ($post->post_type == 'projects' && $post->post_parent == 7334 && $old_status == 'draft' && $new_status == 'publish') { | |
$multiple_recipients = array( | |
'celso.white13@gmail.com' | |
); | |
$subject = "New Project Posted"; | |
$title = $post->post_title; | |
$link = get_post_permalink($post->ID); | |
$message = 'A new project, ' . $title . ', has moved from draft to under constuction. View the project <a href="' . $link . '">here.</a>'; | |
$headers = array('From: The Water Trust <admin@watertrust.org>', 'Content-Type: text/html; charset=UTF-8'); | |
wp_mail( $multiple_recipients, $subject, $message, $headers ); | |
} | |
} | |
add_action('transition_post_status', 'draft_to_under_construction_project', 10, 3); | |
/*========================================= | |
Draft to Complete Project Hook | |
Upon changing the status of a post from draft to published, send an email notifying the team. | |
Codex reference: https://codex.wordpress.org/Post_Status_Transitions | |
=========================================*/ | |
function draft_to_published_project( $new_status, $old_status, $post ) { | |
if ($post->post_type == 'projects' && $post->post_parent !== 7334 && $old_status == 'draft' && $new_status == 'publish') { | |
$multiple_recipients = array( | |
'celso.white13@gmail.com' | |
); | |
$subject = "New Project Posted"; | |
$title = $post->post_title; | |
$link = get_post_permalink($post->ID); | |
$message = 'A new project, ' . $title . ', has been published. View the project <a href="' . $link . '">here.</a>'; | |
$headers = array('From: The Water Trust <admin@watertrust.org>', 'Content-Type: text/html; charset=UTF-8'); | |
wp_mail( $multiple_recipients, $subject, $message, $headers ); | |
} | |
} | |
add_action('transition_post_status', 'draft_to_published_project', 10, 3); | |
/*========================================= | |
Under Construction to Complete Hook | |
Upon changing a published post from one parent type to another, send an email notifying the team. | |
Codex reference: https://codex.wordpress.org/Plugin_API/Action_Reference/post_updated | |
=========================================*/ | |
function under_construction_to_complete($post_ID, $post_after, $post_before) { | |
if ($post_before->post_parent == 7334 && ($post_after->post_parent == 9 || $post_after->post_parent == 7)) { | |
$multiple_recipients = array( | |
'celso.white13@gmail.com' | |
); | |
$subject = "Project Complete"; | |
$title = $post_after->post_title; | |
$link = get_post_permalink($post_ID); | |
$message = 'The project ' . $title . ' has moved from under construction to complete. View the project <a href="' . $link . '">here.</a>'; | |
$headers = array('From: The Water Trust <admin@watertrust.org>', 'Content-Type: text/html; charset=UTF-8'); | |
wp_mail( $multiple_recipients, $subject, $message, $headers ); | |
} | |
} | |
add_action('post_updated', 'under_construction_to_complete', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment