Skip to content

Commit

Permalink
#19 Add Filter for bbpress compatibility
Browse files Browse the repository at this point in the history
Add filter to set User Profile Avatar to bbpress Forum page
  • Loading branch information
RHSRSK committed Jul 1, 2024
1 parent b4e8ff1 commit efaec83
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions includes/wp-user-profile-avatar-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WPUPA_User {
*/
public function __construct() {
add_filter( 'get_avatar_url', array( $this, 'wpupa_get_user_avatar_url' ), 10, 3 );
add_filter('get_avatar', array( $this, 'wpupa_integrate_user_avatar_to_bbpress_profile' ), 10, 5);
}

/**
Expand Down Expand Up @@ -72,6 +73,34 @@ public function wpupa_get_user_avatar_url( $url, $id_or_email, $args ) {
return esc_url( $url );
}


public function wpupa_integrate_user_avatar_to_bbpress_profile($avatar, $id_or_email, $size, $default, $alt) {

// Get the user ID
if (is_numeric($id_or_email)) {
$user_id = (int) $id_or_email;
} elseif (is_object($id_or_email)) {
$user_id = $id_or_email->user_id;
} else {
$user = get_user_by('email', $id_or_email);
$user_id = $user ? $user->ID : 0;
}

// Get the user avatar profile picture URL

$attachment_id = esc_attr( get_user_meta( $user_id, '_wpupa_attachment_id', true ) );
$image_source = wp_get_attachment_image_src( $attachment_id );


if ($image_source) {
$avatar = "<img alt='{$alt}' src='{$image_source[0]}' class='avatar avatar-{$size} photo' height='{$image_source[2]}' width='{$image_source[1]}' />";
}

return $avatar;
}


}


new WPUPA_User();

0 comments on commit efaec83

Please sign in to comment.