$post_id
is an integer (just the post id) and not a post object (the whole post with id,status,title …)
so globalize the $post
object and check the status from there eg:
function er_send_email_on_post_draft_save( $post_id ) {
global $post;
//verify post is not a revision
if ( $post->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 );
}
}
and if you want you can use a hook fired only when post is saved as draft
add_action('draft_post', 'send_my_mail_on_draft' );
function send_my_mail_on_draft( $post_id,$post){
$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 );
}