Email admin when post pending?

There a couple of ways you can go about it depending on your use case and although example number 1 is perfectly valid, it might make more sense to employ the use of example number 2.

Example #1:

This will send you an email each time a post is updated/published with the status of “pending”. This will also email you if the status was already “pending” and the user hits save as pending again.

add_action( 'transition_post_status', 'pending_post_status', 10, 3 );

function pending_post_status( $new_status, $old_status, $post ) {

    if ( $new_status === "pending" ) {

        wp_mail(
            //your arguments here...
        );
    }

}

Example #2:

This will send you an email when a post is updated or published as pending only IF the previous status of the post was not already set to pending.

add_action( 'transition_post_status', 'pending_post_status', 10, 3 );

function pending_post_status( $new_status, $old_status, $post ) {

    if ( $new_status === "pending" && $old_status !== "pending" ) {

        wp_mail(
            //your arguments here...
        );
    }

}

Choose your poison…

Additional resources:

http://codex.wordpress.org/Post_Status_Transitions

Leave a Comment