gpt4 book ai didi

php - 图片上传后的 Buddypress 钩子(Hook)

转载 作者:可可西里 更新时间:2023-11-01 13:52:38 25 4
gpt4 key购买 nike

我想在用户上传新图片(不是头像)时更新自定义 user_meta 字段。

头像上传的工作代码

add_action('xprofile_avatar_uploaded', 'callback');

function callback($user_id, $type)
{
// $activity_id = <- the activity from the uploded image.

update_user_meta($user_id, 'image_'.$activity_id, '1');
}

最佳答案

当您将 rtMedia 插件用于 buddypress 并上传照片时,请提供带有三个参数的操作 rtmedia_after_add_media,您可以处理自定义。

add_action( 'rtmedia_after_add_media', 'rtmedia_after_add_media_update_usermeta', 10, 3 );

function rtmedia_after_add_media_update_usermeta( $media_ids, $file_object, $uploaded ){
// its not provide user id arg so you can get current user id using function get_current_user_id() or $uploaded array have key media_author;
// $media_ids give all attahment ids when you upload file
// $file_object give infomation about file like name, path etc
// $uploaded current upload give settings and update information. Its also gives authore id who is upload media.
// $user_id = $uploaded['media_author'];
$user_id = $uploaded['media_author'];

}

关于php - 图片上传后的 Buddypress 钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37128196/

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