gpt4 book ai didi

php - BuddyPress,发布新故事时发送通知

转载 作者:行者123 更新时间:2023-11-29 14:09:26 26 4
gpt4 key购买 nike

我已经使用自定义配置文件字段设置了 BuddyPress,该字段列出了与我的网站相关的标签的复选框。

有没有办法在新帖子发布时根据注册的 BuddyPress 用户的自定义个人资料字段选择向其发送自动通知?

最佳答案

save_post Hook 可以帮助您。

http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

大致如下:

function send_bp_message( $post_id ) 
{
//verify post is not a revision
if( wp_is_post_revision($post_id) )
{
return;
}

// get the user ids you want to notify
global $bp, $wpdb;

$custom_field_id = 1; // the profile field you want to check
$custom_field_value = 'true'; // the value you're looking for

$stmt = $wpdb->prepare("
SELECT
{$bp->profile->table_name_data}.user_id
FROM
{$bp->profile->table_name_data}
LEFT JOIN
{$bp->profile->table_name_fields} ON {$bp->profile->table_name_fields}.id = {$bp->profile->table_name_data}.field_id
WHERE
{$bp->profile->table_name_fields}.id = %d
AND
{$bp->profile->table_name_data}.value LIKE %s
", $custom_field_id, $custom_field_value);

$recipient_ids = $wpdb->get_col($stmt); // array of matched user ids

// send buddypress notification to matched user ids
// (you could loop through $recipient_ids to send individual notifications)
$msg_args = array(
'sender_id' => 1, // 1 = admin
'recipients' => $recipient_ids,
'subject' => 'New post',
'content' => 'A new post has been created...'
);
$thread_id = messages_new_message($message_args);
}
add_action('save_post', 'send_bp_message');

关于php - BuddyPress,发布新故事时发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com