我正在尝试向所有在发布帖子时关注某个帖子作者的用户发送电子邮件。我在下面有这个函数,但似乎不起作用。一些注意事项
元值=“following”是一个数组,其中包含作者用户关注的内容。
function followerPost_notification($post_id) {
$post = get_post($post_id);
$uid = $post->post_author;
$user_info = get_userdata($post->post_author);
$email = $user_info->user_email;
$first_name = $user_info->first_name;
$pTitle = $post->post_title;
$pUrl = get_permalink($post_id);
//Email Info
$subject = \'New Post Published by a Person you Follow!\' ;
$headers[] = \'Content-Type: text/html; charset=UTF-8\';
// WP_User_Query arguments
$args = array (
\'meta_query
\' => array(
array(
\'key\' => \'following\',
),
),
);
// The User Query
$user_query = new WP_User_Query( $args );
$q = $user_query->results;
// The User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
$uid2 = $user->ID;
$uemail = $user->user_email;
$to = $uemail;
$meta= get_user_meta($uid2,\'following\', true);
$arr = implode(\',\', $meta);
if(strpos($uid, $arr)) {
ob_start();
include("template/email_header.php");
?>
<p>New post published by a person you follow</p>
<p><em>This is an automated email, please don\'t reply to this email.</em></p>
<?php
include("template/email_footer.php");
$message = ob_get_contents();
ob_end_clean();
wp_mail( $to, $subject, $message, $headers );
}
}
} else {
// no users found
}
}
add_action(\'publish_post\', \'followerPost_notification\');