上传图像后的Buddypress钩子

Pet*_*ter 5 php wordpress hook buddypress

我想在用户上传新图像(非头像)时更新自定义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');
}
Run Code Online (Sandbox Code Playgroud)

use*_*704 4

当您使用 buddypress 的 rtMedia 插件并上传照片时,请提供带有三个参数的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'];

}
Run Code Online (Sandbox Code Playgroud)