I’ve received the next code, which is meant to run when a brand new submit is revealed for the primary time, verify if a customized subject ‘specific_users’ has information (this makes use of Superior Customized Fields), and if that’s the case, ship an electronic mail to every of the chosen customers.
/**
* Ship customers a notification of latest grower posts
*/
operate notify_growers($submit) {
// Solely notify for grower posts
if ( $post->post_type != 'grower_posts' ) return;
$post_id = $post->ID;
// ...run code as soon as
if ( !get_post_meta( $post_id, 'emailsent', $single = true ) ) {
$specific_users = get_field('specific_users',$post_id);
if(isset($specific_users) && is_array($specific_users)) {
foreach($specific_users as $specific_user) {
$to = $specific_user['user_email'];
$topic = 'Grower Information: ' . get_the_title($post_id);
$message = '';
$message .= '<p>' . get_the_excerpt($post_id) . '…</p>';
$message .= '<p><a href="' . get_permalink($post_id) . '"><sturdy>Proceed Studying »</sturdy></a></p>';
wp_mail($to, $topic, $message );
}
unset($specific_user);
//print("<pre>Consumer IDs = ".print_r($user_ids,true)."</pre>");
} else { return; }
// Make sure that this does not run once more
update_post_meta( $post_id, 'emailsent', true );
}
}
add_action( 'draft_to_publish', 'notify_growers' );
add_action( 'new_to_publish', 'notify_growers' );
It isn’t sending any emails, and I am unsure the best way to go about debugging it.
Aspect query, is sending the e-mail within the foreach loop the easiest way to do it? Or ought to I do it with BCCs by some means?
Thanks,
Angus