Skip to content

Commit 71187a5

Browse files
Merge pull request #2345 from themeum/photo_update_fix
Fix: Admin cannot update student or instructor profile photo
2 parents 11d7e23 + bc974e5 commit 71187a5

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

classes/User.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)