@@ -246,7 +246,11 @@ private function delete_existing_user_photo( $user_id, $type ) {
246246 $ meta_key = 'cover_photo ' == $ type ? '_tutor_cover_photo ' : '_tutor_profile_photo ' ;
247247 $ photo_id = get_user_meta ( $ user_id , $ meta_key , true );
248248 if ( is_numeric ( $ photo_id ) ) {
249- wp_delete_attachment ( $ photo_id , true );
249+ $ attachment = get_post ( $ photo_id );
250+ $ post_author = (int ) $ attachment ->post_author ?? 0 ;
251+ if ( $ user_id === $ post_author ) {
252+ wp_delete_attachment ( $ photo_id , true );
253+ }
250254 }
251255 delete_user_meta ( $ user_id , $ meta_key );
252256 }
@@ -375,15 +379,6 @@ public function profile_update( $user_id ) {
375379 $ _tutor_profile_bio = Input::post ( self ::PROFILE_BIO_META , '' , Input::TYPE_KSES_POST );
376380 $ _tutor_profile_image = Input::post ( self ::PROFILE_PHOTO_META , '' , Input::TYPE_KSES_POST );
377381
378- // Check if the image uploaded is by the same user.
379- if ( is_numeric ( $ _tutor_profile_image ) ) {
380- $ attachment = get_post ( $ _tutor_profile_image );
381- $ author_id = (int ) $ attachment ->post_author ?? 0 ;
382- if ( 'attachment ' === $ attachment ->post_type && $ user_id !== $ author_id ) {
383- return ;
384- }
385- }
386-
387382 update_user_meta ( $ user_id , self ::PROFILE_JOB_TITLE_META , $ _tutor_profile_job_title );
388383 update_user_meta ( $ user_id , self ::PROFILE_BIO_META , $ _tutor_profile_bio );
389384 update_user_meta ( $ user_id , self ::PROFILE_PHOTO_META , $ _tutor_profile_image );
0 commit comments