Advertisement
arie_cristianD

render full-size image in JNews User List

Jul 23rd, 2024
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. add_filter( 'get_avatar', 'override_user_avatar', 11, 6 );
  2.  
  3. function override_user_avatar( $avatar, $user_id, $size, $default, $alt, $args ) {
  4.     if ( 500 === $size ) {
  5.  
  6.         $profile_picture = get_the_author_meta( 'profile_picture', $user_id );
  7.  
  8.         if ( $profile_picture ) {
  9.             $image = wp_get_attachment_image_src( $profile_picture, 'full' );
  10.  
  11.             $class = array( 'avatar', 'avatar-' . (int) $args['size'], 'photo' );
  12.  
  13.             if ( ! $args['found_avatar'] || $args['force_default'] ) {
  14.                 $class[] = 'avatar-default';
  15.             }
  16.  
  17.             if ( $args['class'] ) {
  18.                 if ( is_array( $args['class'] ) ) {
  19.                     $class = array_merge( $class, $args['class'] );
  20.                 } else {
  21.                     $class[] = $args['class'];
  22.                 }
  23.             }
  24.  
  25.             $avatar = sprintf(
  26.                 "<img alt='%s' src='%s' srcset='%s' class='%s' height='%d' width='%d' %s/>",
  27.                 esc_attr( $args['alt'] ),
  28.                 esc_url( $image[0] ),
  29.                 esc_attr( "$image[0] 2x" ),
  30.                 esc_attr( join( ' ', $class ) ),
  31.                 (int) $args['height'],
  32.                 (int) $args['width'],
  33.                 $args['extra_attr']
  34.             );
  35.         }
  36.     }
  37.     return $avatar;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement