jetpack_gravatar_profile_shortcode

Display Gravatar profile.

Description

(string) jetpack_gravatar_profile_shortcode( (array) $atts ); 

Returns (string)

Parameters (1)

0. $atts (array)
Shortcode attributes.

Usage

  1. if ( !function_exists( 'jetpack_gravatar_profile_shortcode' ) ) { 
  2. require_once '/modules/shortcodes/gravatar.php'; 
  3.  
  4. // Shortcode attributes. 
  5. $atts = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_gravatar_profile_shortcode($atts); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/shortcodes/gravatar.php  
  1. function jetpack_gravatar_profile_shortcode( $atts ) { 
  2. // Give each use of the shortcode a unique ID 
  3. static $instance = 0; 
  4.  
  5. // Process passed attributes 
  6. $atts = shortcode_atts( array( 
  7. 'who' => null,  
  8. ), $atts, 'jetpack_gravatar_profile' ); 
  9.  
  10. // Can specify username, user ID, or email address 
  11. if ( is_numeric( $atts['who'] ) ) { 
  12. $user = get_user_by( 'id', (int) $atts['who'] ); 
  13. } elseif ( is_email( $atts['who'] ) ) { 
  14. $user = get_user_by( 'email', sanitize_email( $atts['who'] ) ); 
  15. } elseif ( is_string( $atts['who'] ) ) { 
  16. $user = get_user_by( 'login', sanitize_user( $atts['who'] ) ); 
  17. } else { 
  18. $user = false; 
  19.  
  20. // Bail if we don't have a user 
  21. if ( false === $user ) { 
  22. return false; 
  23.  
  24. // Render the shortcode 
  25. $gravatar_url = set_url_scheme( 'http://gravatar.com/' . $user->user_login ); 
  26.  
  27. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { 
  28. $avatar_url = wpcom_get_avatar_url( $user->ID, 96 ); 
  29. $avatar_url = $avatar_url[0]; 
  30. $user_location = get_user_attribute( $user->ID, 'location' ); 
  31. } else { 
  32. $avatar_url = get_avatar_url( $user->user_email, array( 'size' => 96 ) ); 
  33. $user_location = get_user_meta( $user->ID, 'location', true ); 
  34.  
  35. ob_start(); 
  36.  
  37. ?> 
  38. <script type="text/javascript"> 
  39. ( function() { 
  40. if ( null === document.getElementById( 'gravatar-profile-embed-styles' ) ) { 
  41. var headID = document.getElementsByTagName( 'head' )[0]; 
  42. var styleNode = document.createElement( 'style' ); 
  43. styleNode.type = 'text/css'; 
  44. styleNode.id = 'gravatar-profile-embed-styles'; 
  45.  
  46. var gCSS = '.grofile-wrap { border: solid 1px #eee; padding: 10px; } .grofile { padding: 0 0 5px 0; } .grofile-left { float: left; display: block; width: 96px; margin-right: 15px; } .grofile .gravatar { margin-bottom: 5px; } .grofile-clear { clear: left; font-size: 1px; height: 1px; } .grofile ul li a { text-indent: -99999px; } .grofile .grofile-left a:hover { text-decoration: none !important; border: none !important; } .grofile-name { margin-top: 0; }'; 
  47.  
  48. if ( document.all ) { 
  49. styleNode.innerText = gCSS; 
  50. } else { 
  51. styleNode.textContent = gCSS; 
  52.  
  53. headID.appendChild( styleNode ); 
  54. } )(); 
  55. </script> 
  56.  
  57. <div class="grofile vcard" id="grofile-embed-<?php echo esc_attr( $instance ); ?>"> 
  58. <div class="grofile-inner"> 
  59. <div class="grofile-left"> 
  60. <div class="grofile-img"> 
  61. <a href="<?php echo esc_url( $gravatar_url ); ?>"> 
  62. <img src="<?php echo esc_url( $avatar_url ); ?>" width="96" height="96" class="no-grav gravatar photo" /> 
  63. </a> 
  64. </div> 
  65. </div> 
  66. <div class="grofile-right"> 
  67. <p class="grofile-name fn"> 
  68. <strong><?php echo esc_html( $user->display_name ); ?></strong> 
  69. <?php if ( ! empty( $user_location ) ) : ?><br><span class="grofile-location adr"><?php echo esc_html( $user_location ); ?></span><?php endif; ?> 
  70. </p> 
  71. <p class="grofile-bio"><strong><?php esc_html_e( 'Bio:', 'jetpack' ); ?></strong> <?php echo wp_kses_post( $user->description ); ?></p> 
  72. <p class="grofile-view"> 
  73. <a href="<?php echo esc_url( $gravatar_url ); ?>"><?php esc_html_e( 'View complete profile', 'jetpack' ); ?></a> 
  74. </p> 
  75. </div> 
  76. <span class="grofile-clear"> </span> 
  77. </div> 
  78. </div><?php 
  79.  
  80. // Increment and return the rendered profile 
  81. $instance++; 
  82.  
  83. return ob_get_clean();