php - Wordpress - 当其他用户喜欢他们的帖子时向用户发送电子邮件
问题描述
我有这个功能来检查用户何时被其他用户喜欢,当他们的帖子被其他人喜欢时,我如何向帖子作者发送电子邮件?
/**
* Utility to test if the post is already liked
* @since 0.5
*/
function already_liked( $post_id, $is_comment ) {
$post_users = NULL;
$user_id = NULL;
if ( is_user_logged_in() ) { // user is logged in
$user_id = get_current_user_id();
$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_liked" ) : get_post_meta( $post_id, "_user_liked" );
if ( count( $post_meta_users ) != 0 ) {
$post_users = $post_meta_users[0];
}
} else { // user is anonymous
$user_id = sl_get_ip();
$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_IP" ) : get_post_meta( $post_id, "_user_IP" );
if ( count( $post_meta_users ) != 0 ) { // meta exists, set up values
$post_users = $post_meta_users[0];
}
}
if ( is_array( $post_users ) && in_array( $user_id, $post_users ) ) {
return true;
} else {
return false;
}
} // already_liked()
这个帖子用户喜欢
/**
* Utility retrieves post meta user likes (user id array),
* then adds new user id to retrieved array
* @since 0.5
*/
function post_user_likes( $user_id, $post_id, $is_comment ) {
$post_users = '';
$post_meta_users = ( $is_comment == 1 ) ? get_comment_meta( $post_id, "_user_comment_liked" ) : get_post_meta( $post_id, "_user_liked" );
if ( count( $post_meta_users ) != 0 ) {
$post_users = $post_meta_users[0];
}
if ( !is_array( $post_users ) ) {
$post_users = array();
}
if ( !in_array( $user_id, $post_users ) ) {
$post_users['user-' . $user_id] = $user_id;
}
return $post_users;
} // post_user_likes()
解决方案
推荐阅读
- excel - 将当前时间戳添加到文件名的末尾
- python - 通过 .ENV 在 SETTINGS.PY 中自动创建 SECRET_KEY
- php - 在 CloudFlare 网站上重定向后使用会话数据
- r - 控制R中pmap输出的顺序
- jss - 当我尝试在 css 中使用 has() 时,jss 注入规则警告/错误
- python - 多轨迹绘图图表上不必要的额外边距
- tensorflow - 我们可以将 VGG19 与迁移学习和其他图像尺寸一起使用吗?
- python - Python 中用于推文分类的循环神经网络 (LSTM) 中的错误
- c# - 成员的自定义配置仅支持类型上的顶级个人成员
- ckeditor - Ckeditor 文件上传中的服务器响应无效