Tam Nguyen Photography

New York Beauty and Fashion Photographer

Make WordPress Send an Email when a Contributor Submits a Post for Review

Posted on August 28, 2013 in Technology, Tips

Make WordPress Send an Email when a Contributor Submits a Post for Review

Situation: you manage a blog with multiple contributors, editors, and admins. While contributors can create and edit posts, there’s no mechanism to let the site’s editors know that a post is ready for review once a contributor hits the ‘Submit for Review’ button.

I wanted to automate this process so that when a contributor is done with writing their post, he/she can just hit the button, and an email will be automatically sent to the site’s editors for proofing.

Solution: you need to create a WordPress action hook in your function.php, wherein you monitor a post’s status when it changes from ‘draft’ to ‘pending’. You also want to limit this logic to only fire when a contributor is updating the post, not an editor or admin.

The code goes something like this:

function submit_send_email ($post) {
	if ( current_user_can('contributor') ) {
		$user_info = get_userdata ($post->post_author);
		$strTo = array ('person1@example.com', 'person2@example.com');
		$strSubject = 'Your website name: ' . $user_info->user_nicename . ' submitted a post';
		$strMessage = 'A post "' . $post->post_title . '" by ' . $user_info->user_nicename . ' was submitted for review at ' . wp_get_shortlink ($post->ID) . '&preview=true. Please proof.';
		wp_mail( $strTo, $strSubject, $strMessage );
add_action( 'draft_to_pending', 'submit_send_email' );
add_action( 'auto-draft_to_pending', 'submit_send_email' );

For more information on what variables are available from the returned object of get_userdata, head over to http://codex.wordpress.org/Function_Reference/get_userdata.

By the way, in the event that you’d like your contributors to be able to upload images, here’s a snippet to add that capability to their user role.

function contributor_upload_files() {
    $role = get_role( 'contributor' );
    $role->add_cap( 'upload_files' ); 
add_action( 'admin_init', 'contributor_upload_files');

1 Comment

  1. neha May 13, 2016

    Thank You . This is helpful for me

Leave a Reply

Your email address will not be published. Required fields are marked *