I'm trying to send an email only upon saving a post as a draft, this doesn't seem to work with the current code:
add_action( 'save_post', 'er_send_email_on_post_draft_save' ); function er_send_email_on_post_draft_save( $post_id ) { //verify post is not a revision if ( $post_id->post_status == 'draft' ) { $post_title = get_the_title( $post_id ); $post_url = get_permalink( $post_id ); $subject = 'A post has been updated'; $message = "A post has been updated on your website:\n\n"; $message .= "" .$post_title. "\n\n"; //send email to admin wp_mail( '[email protected]', $subject, $message ); } }
it works if I change the if statement to:
!wp_is_post_revision( $post_id )
but that's not what I want, I only want to send notification if it's saved as a draft only.