/**
* Mail
*/
class Mail {
/**
* Construct
*/
public function __construct() {
add_action( 'updated_postmeta', array( $this, 'post_status_mail' ), 20, 4 );
add_action( 'added_post_meta', array( $this, 'post_status_mail' ), 20, 4 );
}
/**
* Send mail on status change.
*/
public function post_status_mail( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( '_post_status' !== $meta_key ) {
return;
}
if ( 'completed' !== $meta_value ) {
return;
}
// Headers
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$headers[] = 'From: Karel-Jan Tolsma <noreply@kareljantolsma.nl>';
$headers[] = 'Cc: somemail@somedomain.com';
$headers[] = 'Cc: someothermail@somedomain.com';
// To
$to = 'somemail@somedomain.com';
// Subject
$subject = sprintf(
'Post changed to %s',
$meta_value
);
// Body
$body = 'Some post has changed.';
// Mail
wp_mail( $to, $subject, $body, $headers );
}
}