Tutorial: Send an email to the employer when a job listing is approved

Note: All code examples on this site are provided for developer reference/guidance only and we cannot guarantee that they will always work as expected. Our support policy does not include assistance with modifying or debugging code from any code examples, and they may be changed or removed if we find they no longer work due to changes in our plugins.

Strong communication is definitely an important part of any business or website. So it makes sense that you’d want to email your employers / job listing submitters when their listings are finally approved!

To do so, simply add the following code to a plugin like Code Snippets:

<?php

function listing_published_send_email($post_id) {
	if( 'job_listing' != get_post_type( $post_id ) ) {
		return;
	}
	$post = get_post($post_id);
	$author = get_userdata($post->post_author);

	$message = "
	  Hi ".$author->display_name.",
	  Your listing, ".$post->post_title." has just been approved at ".get_permalink( $post_id ).". Well done!
	";
	wp_mail($author->user_email, "Your job listing is online", $message);
}
add_action('pending_to_publish', 'listing_published_send_email');
add_action('pending_payment_to_publish', 'listing_published_send_email');

You can customize those messages quite easily, so be creative with it!

Screen Shot 2015-02-18 at 10.21.10 pm

Another option of course is to use a plugin like Post Status Notifier Lite, but some of us prefer to do things ourselves with some code.

Send an email to the candidate when their resume is approved

If you’re using the Resume Manager add-on, you can also have an email sent to the candidate when their resume is approved. The code is similar to the above, just with some minor changes:

function resume_published_send_email($post_id) {
   if( 'resume' != get_post_type( $post_id ) ) {
		return;
	}
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);

   $message = "
      Hi ".$author->display_name.",
      Your resume, ".$post->post_title." has just been approved at ".get_permalink( $post_id ).". Well done!
   ";
   wp_mail($author->user_email, "Your resume is online", $message);
}
add_action('pending_to_publish', 'resume_published_send_email');
add_action('pending_payment_to_publish', 'resume_published_send_email');