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

person Peter    schedule 10.05.2016    source แหล่งที่มา
comment
คุณช่วยแบ่งปันรายละเอียดเกี่ยวกับตำแหน่งที่จะอัพโหลดภาพใน Buddypress ได้ไหม?   -  person user5200704    schedule 12.05.2016
comment
การอัปโหลดรูปภาพปกติ DOMAIN.COM/members/USERNAME/media/photo   -  person Peter    schedule 12.05.2016
comment
สื่อ/ภาพถ่ายไม่ได้ระบุค่าเริ่มต้นของ Buddypress ว่าปลั๊กอินภายนอกจาก Buddypress คืออะไร ถ้าใช่ ให้ชื่อปลั๊กอินหรือลิงก์ที่ใช้ปลั๊กอินให้ฉันด้วย   -  person user5200704    schedule 12.05.2016


คำตอบ (2)


เมื่อคุณใช้ปลั๊กอิน rtMedia สำหรับ Buddypress และอัปโหลดรูปภาพ ให้ดำเนินการ rtmedia_after_add_media พร้อมด้วยอาร์กิวเมนต์ 3 รายการที่คุณสามารถจัดการการปรับแต่งของคุณได้

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

}
person user5200704    schedule 12.05.2016

ฉันแทนที่ bp_core_avatar_handle_upload ด้วยฟังก์ชันต่อไปนี้ โดยจะเรียก bp_core_avatar_handle_upload ภายใน แต่หลีกเลี่ยงการวนซ้ำไม่สิ้นสุดโดยการตั้งค่าและตรวจสอบค่าของตัวแปรส่วนกลาง

global $my_bp_group_avatar_upload;
    function my_bp_group_avatar_upload( $upload, $file, $upload_dir_filter )
    {
    // Global.
    global $my_bp_group_avatar_upload;

    // Check upload filter.
    if ( $upload_dir_filter != ‘groups_avatar_upload_dir’ )
    return;

    // Check if this is the second call.
    if ( $my_bp_group_avatar_upload !== 2 )
    {
    // We are being called for the first time!

    // We are about to call the second time.
    $my_bp_group_avatar_upload = 2;

    // Call the function.
    // We’re calling ourselves too, but this time the global equals 2, so we are now in the else statement.
    if ( bp_core_avatar_handle_upload( $file, $upload_dir_filter ) ) {
    // Do stuff here, the upload was a success.
    }

    // We’ve executed the function. We can bail out of the original function run.
    return FALSE;
    } else {
    // We have been called a second time, so set this to something other than 2.
    $my_bp_group_avatar_upload = 0;

    // We want to continue with the execution.
    return TRUE;
    }
    }
    add_filter( ‘bp_core_pre_avatar_handle_upload’, ‘my_bp_group_avatar_upload’, 10, 3 );
person Vinod Kumar    schedule 13.05.2016