我想在用户上传新图像(不是虚拟形象)时更新自定义用户元数据字段。
头像上传工作代码

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');
}

最佳答案

当你在BuddyPress和Upload照片中使用RTMedia插件时,在添加带有三个参数的媒体后提供一个操作RTMedia,你可以处理你的自定义。

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'];

}

08-27 21:11