Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. function get_avatar_url($get_avatar){
  2. preg_match("/src='(.*?)'/i", $get_avatar, $matches);
  3. return $matches[1];
  4. }
  5.  
  6. <img src="<? echo get_avatar_url(get_avatar( $curauth->ID, 150 )); ?>" align="left" class="authorimage" />
  7.  
  8. $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
  9.  
  10. apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
  11.  
  12. if ( ! function_exists( 'get_avatar' ) ) :
  13.  
  14. /**
  15. * Retrieve the avatar for a user who provided a user ID or email address.
  16. *
  17. * @since 2.5
  18. * @param int|string|object $id_or_email A user ID, email address, or comment object
  19. * @param int $size Size of the avatar image
  20. * @param string $default URL to a default image to use if no avatar is available
  21. * @param string $alt Alternate text to use in image tag. Defaults to blank
  22. * @param boolean $url, true for get only the url of the image, no markup
  23. * @return string <img> tag for the user's avatar
  24. */
  25. function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false, $url = FALSE ) {
  26. if ( ! get_option('show_avatars') )
  27. return false;
  28.  
  29. if ( false === $alt)
  30. $safe_alt = '';
  31. else
  32. $safe_alt = esc_attr( $alt );
  33.  
  34. if ( !is_numeric($size) )
  35. $size = '96';
  36.  
  37. $email = '';
  38. if ( is_numeric($id_or_email) ) {
  39. $id = (int) $id_or_email;
  40. $user = get_userdata($id);
  41. if ( $user )
  42. $email = $user->user_email;
  43. } elseif ( is_object($id_or_email) ) {
  44. // No avatar for pingbacks or trackbacks
  45. $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
  46. if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
  47. return false;
  48.  
  49. if ( !empty($id_or_email->user_id) ) {
  50. $id = (int) $id_or_email->user_id;
  51. $user = get_userdata($id);
  52. if ( $user)
  53. $email = $user->user_email;
  54. } elseif ( !empty($id_or_email->comment_author_email) ) {
  55. $email = $id_or_email->comment_author_email;
  56. }
  57. } else {
  58. $email = $id_or_email;
  59. }
  60.  
  61. if ( empty($default) ) {
  62. $avatar_default = get_option('avatar_default');
  63. if ( empty($avatar_default) )
  64. $default = 'mystery';
  65. else
  66. $default = $avatar_default;
  67. }
  68.  
  69. if ( !empty($email) )
  70. $email_hash = md5( strtolower( trim( $email ) ) );
  71.  
  72. if ( is_ssl() ) {
  73. $host = 'https://secure.gravatar.com';
  74. } else {
  75. if ( !empty($email) )
  76. $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash[0] ) % 2 ) );
  77. else
  78. $host = 'http://0.gravatar.com';
  79. }
  80.  
  81. if ( 'mystery' == $default )
  82. $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
  83. elseif ( 'blank' == $default )
  84. $default = includes_url('images/blank.gif');
  85. elseif ( !empty($email) && 'gravatar_default' == $default )
  86. $default = '';
  87. elseif ( 'gravatar_default' == $default )
  88. $default = "$host/avatar/?s={$size}";
  89. elseif ( empty($email) )
  90. $default = "$host/avatar/?d=$default&s={$size}";
  91. elseif ( strpos($default, 'http://') === 0 )
  92. $default = add_query_arg( 's', $size, $default );
  93.  
  94. if ( !empty($email) ) {
  95. $out = "$host/avatar/";
  96. $out .= $email_hash;
  97. $out .= '?s='.$size;
  98. $out .= '&d=' . urlencode( $default );
  99.  
  100. $rating = get_option('avatar_rating');
  101. if ( !empty( $rating ) )
  102. $out .= "&r={$rating}";
  103.  
  104. if ( $url )
  105. $avatar = $out;
  106. else
  107. $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
  108. } else {
  109. if ( $url )
  110. $avatar = $out;
  111. else
  112. $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
  113. }
  114.  
  115. return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
  116. }
  117.  
  118. function get_gravatar_url( $email ) {
  119.  
  120. $hash = md5( strtolower( trim ( $email ) ) );
  121. return 'http://gravatar.com/avatar/' . $hash;
  122. }
  123.  
  124. // In your template ...
  125. $avatar_url = get_avatar_url ( get_the_author_meta('ID'), $size = '50' );
  126.  
  127. // Get src URL from avatar <img> tag (add to functions.php)
  128. function get_avatar_url($author_id, $size){
  129. $get_avatar = get_avatar( $author_id, $size );
  130. preg_match("/src='(.*?)'/i", $get_avatar, $matches);
  131. return ( $matches[1] );
  132. }
  133.  
  134. preg_match("/src=['"](.*?)['"]/i", $get_avatar, $matches);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement