-
Notifications
You must be signed in to change notification settings - Fork 151
fix: profile photo priority higher than avatar fields #1703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix: profile photo priority higher than avatar fields #1703
Conversation
WalkthroughUpdates wpuf_get_custom_avatar($user_id) to prefer Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
wpuf-functions.php (3)
676-687: Return a sanitized URL and support non‑IDwpuf_profile_photovalues.
- The PR description mentions escaping, but this branch returns a raw URL.
- Some installs may store
wpuf_profile_photoas a URL (string), not an attachment ID. Handle both.Apply this diff within this hunk:
function wpuf_get_custom_avatar( $user_id ) { - // First check for profile photo (higher priority) - $profile_photo = get_user_meta( $user_id, 'wpuf_profile_photo', true ); + // First check for profile photo (higher priority) + $profile_photo = get_user_meta( $user_id, 'wpuf_profile_photo', true ); + + // If stored as an absolute URL, use it directly + if ( is_string( $profile_photo ) && filter_var( $profile_photo, FILTER_VALIDATE_URL ) ) { + return esc_url_raw( $profile_photo ); + } if ( absint( $profile_photo ) > 0 ) { wpuf_avatar_add_image_size(); $avatar_source = wp_get_attachment_image_src( $profile_photo, 'wpuf_avatar_image_size' ); - if ( $avatar_source ) { - return $avatar_source[0]; + if ( $avatar_source ) { + return esc_url_raw( $avatar_source[0] ); } }
692-703: Ensure consistent return type and sanitize; avoid returning a numeric ID.If the attachment lookup fails for a numeric meta, this can return an integer (attachment ID) and later render as an invalid img src. Always return a URL (or empty string) and sanitize it.
Apply this diff:
if ( absint( $avatar ) > 0 ) { wpuf_avatar_add_image_size(); $avatar_source = wp_get_attachment_image_src( $avatar, 'wpuf_avatar_image_size' ); - if ( $avatar_source ) { - $avatar = $avatar_source[0]; - } + if ( $avatar_source ) { + return esc_url_raw( $avatar_source[0] ); + } } - return $avatar; + return is_string( $avatar ) ? esc_url_raw( $avatar ) : '';
786-791: Sanitize URL when populatingget_avatar_data.Small hardening: sanitize before assigning to
$args['url']. Core will escape on render, but this keeps the contract clean.Replace the assignment at Line 790:
$args['url'] = esc_url_raw( $custom_avatar_url );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
wpuf-functions.php(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Inspections
wpuf-functions.php
[warning] 1-1: PHPCS: The method parameter $post_id is never used.
[error] 1-1: PHPCS: Processing form data without nonce verification.
sapayth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the comment
| $avatar_source = wp_get_attachment_image_src( $profile_photo, 'wpuf_avatar_image_size' ); | ||
|
|
||
| if ( $avatar_source ) { | ||
| return $avatar_source[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if it is an array and $avatar_source[0] exists before returning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done @sapayth vai
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check with empty()
wp_get_attachment_im age_src() returns false or an incomplete array structure
| $avatar_source = wp_get_attachment_image_src( $profile_photo, 'wpuf_avatar_image_size' ); | ||
|
|
||
| if ( $avatar_source ) { | ||
| return $avatar_source[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check with empty()
feat(avatar): add support for
wpuf_profile_photowith higher priorityclose issue
Changes:
wpuf_profile_photoinwpuf_get_custom_avatar()user_avatarwpuf_avatar_add_image_size()to ensure consistent sizingesc_url()for securitySummary by CodeRabbit
New Features
Bug Fixes