So I manage a blog of about 15 contributors and 5 editors. I wanted to implement a system so that each time a contributor hits the ‘Submit for Review’ button, and email is sent to the editors to proof. I’ve cooked up an action, but it seemed to fire off at “edit post” time and not “submit” time.
My workaround was to put a check for the post status, only fire the email of it’s “pending”, but before they hit submit, the status is still ‘draft’… this means it only works on the second they hit submit for review.
Here’s my snippet so far. Please help!
function submit_send_email() {
global $post;
if ( current_user_can('contributor') && $post->post_status == 'pending' ) {
$user_info = get_userdata ($post->post_author);
$strTo = array ('email@example.com');
$strSubject = 'Fstoppers: ' . $user_info->user_nicename . ' submitted a post';
$strMessage = '"' . $post->post_title . '" by ' . $user_info->user_nicename . ' was submitted a post for review at ' . wp_get_shortlink ($post->ID) . '&preview=true. Please proof.';
wp_mail( $strTo, $strSubject, $strMessage );
}
}
add_action('edit_post','submit_send_email');
UPDATE: I tried to make Frankenstein setup, having my action schedule an event that would get run 15 seconds later, no dice.
function submit_send_email ($post) {
if ( $post->post_status == 'pending' ) {
$user_info = get_userdata ($post->post_author);
$strTo = array ('email@example.com');
$strSubject = 'Fstoppers: ' . $user_info->user_nicename . ' submitted a post';
$strMessage = '"' . $post->post_title . '" by ' . $user_info->user_nicename . ' was submitted a post for review at ' . wp_get_shortlink ($post->ID) . '&preview=true. Please proof.';
wp_mail( $strTo, $strSubject, $strMessage );
}
}
function submit_for_review() {
global $post;
if ( current_user_can('contributor') ) {
wp_schedule_single_event( time() + 15, 'submit_send_email_event', $post );
}
}
add_action('submit_send_email_event','submit_send_email', 10, 1);
add_action('save_post','submit_for_review');
You need Post Status Transitions actions
I am in a similar situation and the ugly method I came up with was to create a file with the following:
I then run a cron every 30 mins to see if there’s any new posts.
(I also have various other maintenance scripts running in here, etc.)
Thought this might help you.