Email Editors When a Post Is Submitted for Review
Notifies editors and administrators by email when a contributor submits a post for review, with a link to edit it.
Opens WPIDE on
Code
add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) {
$roles = array( 'editor', 'administrator' ); // Roles that receive the email.
if ( 'pending' !== $new_status || 'pending' === $old_status || wp_is_post_revision( $post ) ) {
return;
}
$emails = get_users( array( 'role__in' => $roles, 'fields' => array( 'user_email' ) ) );
$to = wp_list_pluck( $emails, 'user_email' );
if ( ! $to ) {
return;
}
$author = get_the_author_meta( 'display_name', $post->post_author );
wp_mail(
$to,
sprintf( 'Pending review: %s', wp_strip_all_tags( $post->post_title ) ),
sprintf( "%s submitted \"%s\" for review.\n\nReview it here: %s\n", $author, wp_strip_all_tags( $post->post_title ), admin_url( 'post.php?post=' . $post->ID . '&action=edit' ) )
);
}, 10, 3 );
Notes
Change $roles to choose who is notified.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.