Php Wordpress-当用户获得新的关注者时,向他们发送电子邮件
我正在使用一个简单的插件“”,我需要做的就是在用户获得新的关注者后发送一封电子邮件 我认为这是插件代码的重要部分:Php Wordpress-当用户获得新的关注者时,向他们发送电子邮件,php,wordpress,email,author,Php,Wordpress,Email,Author,我正在使用一个简单的插件“”,我需要做的就是在用户获得新的关注者后发送一封电子邮件 我认为这是插件代码的重要部分: function pwuf_follow_user( $user_id, $user_to_follow ) { $following = pwuf_get_following( $user_id ); if ( $following && is_array( $following ) ) { $following[] = $us
function pwuf_follow_user( $user_id, $user_to_follow ) {
$following = pwuf_get_following( $user_id );
if ( $following && is_array( $following ) ) {
$following[] = $user_to_follow;
} else {
$following = array();
$following[] = $user_to_follow;
}
// retrieve the IDs of all users who are following $user_to_follow
$followers = pwuf_get_followers( $user_to_follow );
if ( $followers && is_array( $followers ) ) {
$followers[] = $user_id;
} else {
$followers = array();
$followers[] = $user_id;
}
do_action( 'pwuf_pre_follow_user', $user_id, $user_to_follow );
// update the IDs that this user is following
$followed = update_user_meta( $user_id, '_pwuf_following', $following );
// update the IDs that follow $user_id
$followers = update_user_meta( $user_to_follow, '_pwuf_followers', $followers );
// increase the followers count
$followed_count = pwuf_increase_followed_by_count( $user_to_follow ) ;
if ( $followed ) {
do_action( 'pwuf_post_follow_user', $user_id, $user_to_follow );
return true;
}
return false;
}
在这里检查一个用户是否在跟踪另一个用户:
function pwuf_is_following( $user_id, $followed_user ) {
$following = pwuf_get_following( $user_id );
$ret = false; // is not following by default
if ( is_array( $following ) && in_array( $followed_user, $following ) ) {
$ret = true; // is following
}
return $ret;
}
我试图在更新用户元后添加此代码,但什么也没发生
$subscribers = explode(",", $user_to_follow );
$emails = array ();
foreach ( $subscribers as $subscriber ) {
$user_info = get_userdata($subscriber);
$emails[] = $user_info ->user_email;
}
$body = sprintf( $user_to_follow->display_name, 'followed your work! See <%s>' );
wp_mail( $emails, 'New followers!', $body );
$subscribers=explode(“,”,$user\u to\u follow);
$emails=array();
foreach($subscriber作为$subscriber){
$user\u info=get\u userdata($subscriber);
$emails[]=$user\u info->user\u email;
}
$body=sprintf($user_to_follow->display_name,'follow your work!See');
wp_邮件($email,$newfollowers!',$body);
我相信当任何一个用户被另一个用户跟踪时,您都希望向该用户发送电子邮件。在这种情况下,插件中有一个可用的操作钩子,该钩子在以下过程成功时执行:
do_action( 'pwuf_post_follow_user', $user_id, $user_to_follow );
您可以将自己的代码挂接到此操作
add_action('pwuf_post_follow_user', $user_id, $user_to_follow) {
$follower = get_userdata($user_id);
$recipient = get_userdata($user_to_follow);
$recipient_email = $recipient->user_email;
$body = sprintf('%s followed your work!', $follower->display_name );
wp_mail( $recipient_email , 'New follower!', $body );
}
referenece:您能告诉我如何获取关注者的个人资料url,以便用户可以丰富关注者个人资料吗?我的意思是追随者的名字将是href链接@AdhamMohamed检查信息您可以再次检索Hanks@Ghazanfar我做到了
$follower=get_userdata($user_id)$follower\u url=get\u author\u posts\u url($user\u id);$recipient=get_userdata($user_to_follow);$recipient\u email=$recipient->user\u email;$body=sprintf('%s跟随您的工作!'.“\n\n”,$follower->display\u name);$body.=sprintf('访问艺术家页面:%s',$follower\u url);wp_邮件($recipient_email,$newfollower!',$body)代码>