Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active January 1, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejolley/88ff07584c36e22055aa to your computer and use it in GitHub Desktop.
Save mikejolley/88ff07584c36e22055aa to your computer and use it in GitHub Desktop.
class My_Job_Manager_Custom_Alerts {
/**
* Constructor
*/
public function __construct() {
add_action( 'publish_to_expired', array( $this, 'expired_post' ) );
}
/**
* Expired post triggered by publish_to_expired hook
* @param $post post object
*/
public function expired_post( $post ) {
if ( 'job_listing' == $post->post_type ) {
$send_to = '';
$email = get_post_meta( $post->ID, '_application', true );
$user = $post->post_author;
if ( is_email( $email ) ) {
$send_to = $email;
} elseif ( $user ) {
$user = get_user_by( 'id', $user );
$send_to = $user->user_email;
}
if ( ! $send_to )
return;
$message = sprintf( "Hello,\n\nThe job “%s” which you posted on %s has just expired and will no longer be visible.\n\nTo check your other active listings, or post a new job listing, please visit your dashboard.", esc_html( $post->post_title ), esc_html( get_bloginfo( 'name' ) ) );
wp_mail( $send_to, 'Your job listing has expired', $message );
}
}
}
new My_Job_Manager_Custom_Alerts();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment