我已经编写了一个“关注帖子”脚本,我想在其中添加一个功能,即如果用户关注的帖子已更新,则向用户发送电子邮件。如果我将电子邮件硬编码为wp\\u mail(),则我的脚本只会发送电子邮件,例如。
wp_mail(\'[email protected]\', $subject, $message, $headers);
但是,当我与所有关注该帖子的用户动态交流时,它根本不会发送任何电子邮件,我的代码如下所示:
http://pastebin.com/yPirRwKn 或:
function favorites_send_email($postid, $post) {
if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) {
return;
}
if ( wp_is_post_revision( $post_id ) ) {
return;
}
$slug = \'journal\';
if ( $slug != $post->post_type ) {
return;
}
$posttitle = get_the_title($postid);
$posturl = get_permalink($postid);
$headers = "From: NAME <[email protected]>\\r\\n";
$headers .= "MIME-Version: 1.0\\r\\n";
$headers .= "Content-Type: text/html; charset=UTF-8\\r\\n";
$subject = \'En af dine favoritter er blevet opdateret!\';
$message = "Læs mere på nedenstående link (husk du skal logge på, hvis du er logget ud):\\r\\n";
$message .= "<a href=\'" . $posturl . "\'>" . $posttitle . "</a>\\r\\n";
global $wpdb;
$table_name = get_table_name(\'favorite_posts\');
$getusers = $wpdb->get_results("SELECT userid FROM " . $table_name . " WHERE postid = " . $postid);
foreach ($get_users as $get_user) {
$theuser = get_userdata($get_user->userid);
$email_data[] = array(\'name\' => $theuser->display_name, \'email\' => $theuser->user_email);
}
foreach($email_data as $data) {
wp_mail($data["email"], $subject, $message, $headers);
}
}
add_action(\'save_post\', \'favorites_send_email\', 10, 3);
感谢您的帮助!