fix: profile photo priority higher than avatar fields#1703
fix: profile photo priority higher than avatar fields#1703arifulhoque7 wants to merge 3 commits intoweDevsOfficial:developfrom
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.
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.
| $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.
check if it is an array and $avatar_source[0] exists before returning
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]; |
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