gpt4 book ai didi

wordpress - 从头像获取 BuddyPress 事件 id

转载 作者:行者123 更新时间:2023-12-04 04:16:12 28 4
gpt4 key购买 nike

当用户上传新头像时,头像会发布在事件墙中。
如何使用 userId 获取此事件 ID?

我认为唯一的方法是创建一个自己的查询,对吧?

最佳答案

您可以编写查询来获取该事件。还有一个过滤器可以卡在其中,在头像上传后会被调用(稍后解释):

<?php

global $wpdb;

$query = "SELECT * FROM {$wpdb->prefix}bp_activity WHERE " .
"`type` = 'new_avatar' AND `user_id` = %d " .
"ORDER BY `date_recorded` DESC LIMIT 1";

$result =
$wpdb->get_row(
$wpdb->prepare($query, $user_id)
);

if ($result) {
// found an activity item for avatar upload
var_dump($result);
} else {
// user has not uploaded an avatar
}

结果如下:
stdClass Object
(
[id] => 2 <-- this is the activity ID
[user_id] => 1
[component] => profile
[type] => new_avatar
[action] => admin changed their profile picture
[content] =>
[primary_link] => http://example.com/wordpress/members/admin/
[item_id] => 0
[secondary_item_id] => 0
[date_recorded] => 2016-03-29 04:41:53
[hide_sitewide] => 0
[mptt_left] => 0
[mptt_right] => 0
[is_spam] => 0
)

有一个被调用的 Action ,您可以挂接该 Action ,当此事件发生时将调用该 Action 。是 xprofile_avatar_uploaded它传递两个参数, $item_id (用户 ID)和 $type (例如裁剪或相机)。此过滤器在头像上传后执行。

在您的函数中的某处,添加:
add_action('xprofile_avatar_uploaded', 'callback');

function callback($user_id, $type)
{
// $user_id uploaded new avatar
}

我发现你也可以打电话:
$img = bp_get_activity_avatar(['user_id' => $user_id]);

获取 HTML 以显示头像。它们存储在 wp-content/uploads/avatars .

您也可以调用:
$url = bp_core_fetch_avatar(['item_id' => $user_id, 'html' => false]);

获取头像的完整 URL。

关于wordpress - 从头像获取 BuddyPress 事件 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36243484/

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