PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.2.3
Jetpack – WP Security, Backup, Speed, & Growth v6.2.3
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / gravatar.php

gravatar.php in Jetpack – WP Security, Backup, Speed, & Growth 6.2.3, at modules/shortcodes/gravatar.php

151 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gravatar shortcode for avatar and profile.
4 *
5 * Usage:
6 *
7 * [gravatar email="user@example.org" size="48"]
8 * [gravatar_profile who="user@example.org"]
9 */
10
11 add_shortcode( 'gravatar', 'jetpack_gravatar_shortcode' );
12 add_shortcode( 'gravatar_profile', 'jetpack_gravatar_profile_shortcode' );
13
14 /**
15 * Get gravatar using the email provided at the specified size.
16 *
17 * @since 4.5.0
18 *
19 * @param array $atts Shortcode attributes.
20 *
21 * @return bool|string
22 */
23 function jetpack_gravatar_shortcode( $atts ) {
24 $atts = shortcode_atts( array(
25 'email' => '',
26 'size' => 96,
27 ), $atts );
28
29 if ( empty( $atts['email'] ) || ! is_email( $atts['email'] ) ) {
30 return false;
31 }
32
33 $atts['size'] = intval( $atts['size'] );
34 if ( 0 > $atts['size'] ) {
35 $atts['size'] = 96;
36 }
37
38 return get_avatar( $atts['email'], $atts['size'] );
39 }
40
41 /**
42 * Display Gravatar profile
43 *
44 * @since 4.5.0
45 *
46 * @param array $atts Shortcode attributes.
47 *
48 * @uses shortcode_atts()
49 * @uses get_user_by()
50 * @uses is_email()
51 * @uses sanitize_email()
52 * @uses sanitize_user()
53 * @uses set_url_scheme()
54 * @uses wpcom_get_avatar_url()
55 * @uses get_user_attribute()
56 * @uses esc_url()
57 * @uses esc_html()
58 * @uses _e()
59 *
60 * @return string
61 */
62 function jetpack_gravatar_profile_shortcode( $atts ) {
63 // Give each use of the shortcode a unique ID
64 static $instance = 0;
65
66 // Process passed attributes
67 $atts = shortcode_atts( array(
68 'who' => null,
69 ), $atts, 'jetpack_gravatar_profile' );
70
71 // Can specify username, user ID, or email address
72 if ( is_numeric( $atts['who'] ) ) {
73 $user = get_user_by( 'id', (int) $atts['who'] );
74 } elseif ( is_email( $atts['who'] ) ) {
75 $user = get_user_by( 'email', sanitize_email( $atts['who'] ) );
76 } elseif ( is_string( $atts['who'] ) ) {
77 $user = get_user_by( 'login', sanitize_user( $atts['who'] ) );
78 } else {
79 $user = false;
80 }
81
82 // Bail if we don't have a user
83 if ( false === $user ) {
84 return false;
85 }
86
87 // Render the shortcode
88 $gravatar_url = set_url_scheme( 'http://gravatar.com/' . $user->user_login );
89
90 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
91 $avatar_url = wpcom_get_avatar_url( $user->ID, 96 );
92 $avatar_url = $avatar_url[0];
93 $user_location = get_user_attribute( $user->ID, 'location' );
94 } else {
95 $avatar_url = get_avatar_url( $user->user_email, array( 'size' => 96 ) );
96 $user_location = get_user_meta( $user->ID, 'location', true );
97 }
98
99 ob_start();
100
101 ?>
102 <script type="text/javascript">
103 ( function() {
104 if ( null === document.getElementById( 'gravatar-profile-embed-styles' ) ) {
105 var headID = document.getElementsByTagName( 'head' )[0];
106 var styleNode = document.createElement( 'style' );
107 styleNode.type = 'text/css';
108 styleNode.id = 'gravatar-profile-embed-styles';
109
110 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; }';
111
112 if ( document.all ) {
113 styleNode.innerText = gCSS;
114 } else {
115 styleNode.textContent = gCSS;
116 }
117
118 headID.appendChild( styleNode );
119 }
120 } )();
121 </script>
122
123 <div class="grofile vcard" id="grofile-embed-<?php echo esc_attr( $instance ); ?>">
124 <div class="grofile-inner">
125 <div class="grofile-left">
126 <div class="grofile-img">
127 <a href="<?php echo esc_url( $gravatar_url ); ?>">
128 <img src="<?php echo esc_url( $avatar_url ); ?>" width="96" height="96" class="no-grav gravatar photo" />
129 </a>
130 </div>
131 </div>
132 <div class="grofile-right">
133 <p class="grofile-name fn">
134 <strong><?php echo esc_html( $user->display_name ); ?></strong>
135 <?php if ( ! empty( $user_location ) ) : ?><br><span class="grofile-location adr"><?php echo esc_html( $user_location ); ?></span><?php endif; ?>
136 </p>
137 <p class="grofile-bio"><strong><?php esc_html_e( 'Bio:', 'jetpack' ); ?></strong> <?php echo wp_kses_post( $user->description ); ?></p>
138 <p class="grofile-view">
139 <a href="<?php echo esc_url( $gravatar_url ); ?>"><?php esc_html_e( 'View complete profile', 'jetpack' ); ?></a>
140 </p>
141 </div>
142 <span class="grofile-clear">&nbsp;</span>
143 </div>
144 </div><?php
145
146 // Increment and return the rendered profile
147 $instance++;
148
149 return ob_get_clean();
150 }
151