PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 15.2.1
Jetpack – WP Security, Backup, Speed, & Growth v15.2.1
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 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7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3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / gravatar-hovercards.php
jetpack / modules Last commit date
carousel 9 months ago comment-likes 1 year ago comments 9 months ago custom-post-types 1 year ago external-media 1 year ago google-fonts 11 months ago gravatar 6 years ago infinite-scroll 9 months ago likes 9 months ago markdown 1 year ago memberships 11 months ago photon-cdn 11 months ago plugin-search 1 year ago post-by-email 1 year ago related-posts 10 months ago scan 9 months ago seo-tools 1 year ago sharedaddy 9 months ago shortcodes 9 months ago simple-payments 1 year ago site-icon 11 months ago sitemaps 10 months ago stats 1 year ago subscriptions 9 months ago theme-tools 9 months ago tiled-gallery 1 year ago verification-tools 1 year ago videopress 11 months ago widget-visibility 11 months ago widgets 9 months ago woocommerce-analytics 9 months ago wordads 9 months ago wpcom-tos 1 year ago account-protection.php 1 year ago blaze.php 1 year ago blocks.php 1 year ago carousel.php 1 year ago comment-likes.php 10 months ago comments.php 1 year ago contact-form.php 1 year ago copy-post.php 1 year ago custom-content-types.php 1 year ago google-fonts.php 1 year ago gravatar-hovercards.php 1 year ago infinite-scroll.php 1 year ago json-api.php 1 year ago latex.php 1 year ago likes.php 9 months ago markdown.php 1 year ago module-extras.php 1 year ago module-headings.php 1 year ago module-info.php 1 year ago monitor.php 1 year ago notes.php 1 year ago photon-cdn.php 10 months ago photon.php 1 year ago plugin-search.php 1 year ago post-by-email.php 1 year ago post-list.php 1 year ago protect.php 1 year ago publicize.php 1 year ago related-posts.php 1 year ago search.php 1 year ago seo-tools.php 1 year ago sharedaddy.php 1 year ago shortcodes.php 1 year ago shortlinks.php 11 months ago simple-payments.php 1 year ago sitemaps.php 1 year ago sso.php 1 year ago stats.php 10 months ago subscriptions.php 11 months ago theme-tools.php 1 year ago tiled-gallery.php 1 year ago vaultpress.php 1 year ago verification-tools.php 1 year ago videopress.php 1 year ago waf.php 1 year ago widget-visibility.php 1 year ago widgets.php 1 year ago woocommerce-analytics.php 1 year ago wordads.php 1 year ago wpgroho.js 1 year ago
gravatar-hovercards.php
406 lines
1 <?php
2 /**
3 * Module Name: Gravatar Hovercards
4 * Module Description: Show a user’s Gravatar profile when visitors hover over their name or image.
5 * Sort Order: 11
6 * Recommendation Order: 13
7 * First Introduced: 1.1
8 * Requires Connection: No
9 * Auto Activate: No
10 * Module Tags: Social, Appearance
11 * Feature: Appearance
12 * Additional Search Queries: gravatar, hovercards
13 *
14 * @package automattic/jetpack
15 */
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 0 );
19 }
20
21 define( 'GROFILES__CACHE_BUSTER', gmdate( 'YW' ) );
22
23 /**
24 * Actions that are run on init.
25 */
26 function grofiles_hovercards_init() {
27 add_filter( 'get_avatar', 'grofiles_get_avatar', 10, 2 );
28 add_action( 'wp_enqueue_scripts', 'grofiles_attach_cards' );
29 add_action( 'wp_footer', 'grofiles_extra_data' );
30 add_action( 'admin_init', 'grofiles_add_settings' );
31
32 add_action( 'load-index.php', 'grofiles_admin_cards' );
33 add_action( 'load-users.php', 'grofiles_admin_cards' );
34 add_action( 'load-edit-comments.php', 'grofiles_admin_cards' );
35 add_action( 'load-options-discussion.php', 'grofiles_admin_cards_forced' );
36
37 add_filter( 'jetpack_module_configuration_url_gravatar-hovercards', 'gravatar_hovercards_configuration_url' );
38
39 add_filter( 'get_comment_author_url', 'grofiles_amp_comment_author_url', 10, 2 );
40 }
41
42 /**
43 * Set configuration page URL.
44 */
45 function gravatar_hovercards_configuration_url() {
46 return admin_url( 'options-discussion.php#show_avatars' );
47 }
48
49 add_action( 'jetpack_modules_loaded', 'grofiles_hovercards_init' );
50
51 /* Hovercard Settings */
52
53 /**
54 * Adds Gravatar Hovercard setting
55 *
56 * @todo - always print HTML, hide via CSS/JS if !show_avatars
57 */
58 function grofiles_add_settings() {
59 if ( ! get_option( 'show_avatars' ) ) {
60 return;
61 }
62
63 add_settings_field( 'gravatar_disable_hovercards', __( 'Gravatar Hovercards', 'jetpack' ), 'grofiles_setting_callback', 'discussion', 'avatars' );
64 register_setting( 'discussion', 'gravatar_disable_hovercards', 'grofiles_hovercard_option_sanitize' );
65 }
66
67 /**
68 * HTML for Gravatar Hovercard setting
69 */
70 function grofiles_setting_callback() {
71 global $current_user;
72
73 $option = get_option( 'gravatar_disable_hovercards' );
74 printf(
75 "<label id='gravatar-hovercard-options'><input %s name='gravatar_disable_hovercards' id='gravatar_disable_hovercards' type='checkbox' value='enabled' class='code'/>%s</label>",
76 checked( $option, 'enabled', false ),
77 esc_html__( 'View people\'s profiles when you mouse over their Gravatars', 'jetpack' )
78 );
79
80 ?>
81 <style type="text/css">
82 #grav-profile-example img {
83 float: left;
84 }
85 #grav-profile-example span {
86 padding: 0 1em;
87 }
88 </style>
89 <script type="text/javascript">
90 // <![CDATA[
91 jQuery( function($) {
92 var tr = $( '#gravatar_disable_hovercards' ).change( function() {
93 if ( $( this ).is( ':checked' ) ) {
94 $( '#grav-profile-example' ).slideDown( 'fast' );
95 } else {
96 $( '#grav-profile-example' ).slideUp( 'fast' );
97 }
98 } ).parents( 'tr' );
99 var ftr = tr.parents( 'table' ).find( 'tr:first' );
100 if ( ftr.length && !ftr.find( '#gravatar_disable_hovercards' ).length ) {
101 ftr.after( tr );
102 }
103 } );
104 // ]]>
105 </script>
106 <p id="grav-profile-example" class="hide-if-no-js"
107 <?php
108 if ( 'disabled' === $option ) {
109 echo ' style="display:none"';}
110 ?>
111 >
112 <?php echo get_avatar( $current_user->ID, 64 ); ?> <span><?php esc_html_e( 'Put your mouse over your Gravatar to check out your profile.', 'jetpack' ); ?> <br class="clear" /></span></p>
113 <?php
114 }
115
116 /**
117 * Sanitation filter for Gravatar Hovercard setting
118 *
119 * @param string $val Disabled or enabled.
120 */
121 function grofiles_hovercard_option_sanitize( $val ) {
122 if ( 'disabled' === $val ) {
123 return $val;
124 }
125
126 return $val ? 'enabled' : 'disabled';
127 }
128
129 /* Hovercard Display */
130
131 /**
132 * Stores the gravatars' users that need extra profile data attached.
133 *
134 * Getter/Setter
135 *
136 * @param int|string|null $author Setter: User ID or email address. Getter: null.
137 *
138 * @return mixed Setter: void. Getter: array of user IDs and email addresses.
139 */
140 function grofiles_gravatars_to_append( $author = null ) {
141 static $authors = array();
142
143 // Get.
144 if ( $author === null ) {
145 return array_keys( $authors );
146 }
147
148 // Set.
149
150 if ( is_numeric( $author ) ) {
151 $author = (int) $author;
152 }
153
154 $authors[ $author ] = true;
155 }
156
157 /**
158 * In AMP, override the comment URL to allow for interactivity without
159 * navigating to a new page
160 *
161 * @param string $url The comment author's URL.
162 * @param int $id The comment ID.
163 *
164 * @return string The adjusted URL
165 */
166 function grofiles_amp_comment_author_url( $url, $id ) {
167 if ( 'comment' === get_comment_type( $id ) && class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
168 // @todo Disabling the comment author link in this way is not ideal since clicking the link does not cause the lightbox to open in the same way as clicking the gravatar. Likely get_comment_author_url_link should be used instead so that the href attribute can be replaced with an `on` attribute that activates the gallery.
169 return '#!';
170 }
171
172 return $url;
173 }
174
175 /**
176 * Stores the user ID or email address for each gravatar generated.
177 *
178 * Attached to the 'get_avatar' filter.
179 *
180 * @param string $avatar The <img/> element of the avatar.
181 * @param mixed $author User ID, email address, user login, comment object, user object, post object.
182 *
183 * @return string The <img/> element of the avatar.
184 */
185 function grofiles_get_avatar( $avatar, $author ) {
186 $is_amp = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request();
187
188 if ( is_numeric( $author ) ) {
189 grofiles_gravatars_to_append( $author );
190 } elseif ( is_string( $author ) ) {
191 if ( str_contains( $author, '@' ) ) {
192 grofiles_gravatars_to_append( $author );
193 } else {
194 $user = get_user_by( 'slug', $author );
195 if ( $user ) {
196 grofiles_gravatars_to_append( $user->ID );
197 }
198 }
199 } elseif ( isset( $author->comment_type ) ) {
200 if ( $is_amp ) {
201 if ( 1 === preg_match( '/avatar\/([a-zA-Z0-9]+)\?/', $avatar, $email_hash ) ) {
202 $email_hash = $email_hash[1];
203 $cache_group = 'gravatar_profiles_';
204 $cache_key = 'gravatar_profile_' . $email_hash;
205
206 $response_body = wp_cache_get( $cache_key, $cache_group );
207 if ( false === $response_body ) {
208 $response = wp_remote_get( esc_url_raw( 'https://gravatar.com/' . $email_hash . '.json' ) );
209 if ( is_array( $response ) && ! is_wp_error( $response ) ) {
210 $response_body = json_decode( $response['body'] );
211 wp_cache_set( $cache_key, $response_body, $cache_group, 60 * MINUTE_IN_SECONDS );
212 }
213 }
214
215 $profile = isset( $response_body->entry[0] ) ? $response_body->entry[0] : null;
216 $display_name = isset( $profile->displayName ) ? $profile->displayName : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
217 $location = isset( $profile->currentLocation ) ? $profile->currentLocation : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
218 $description = isset( $profile->aboutMe ) ? $profile->aboutMe : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
219
220 $avatar = '
221 <figure data-amp-lightbox="true">
222 ' . $avatar . '
223 <figcaption>
224 ' . esc_html( $display_name ) . ( ! empty( $location ) ? '' . esc_html( $location ) : '' ) . ( ! empty( $description ) ? '' . esc_html( $description ) : '' ) . '
225 </figcaption>
226 </figure>
227 ';
228 }
229
230 return $avatar;
231 }
232
233 if ( '' !== $author->comment_type && 'comment' !== $author->comment_type ) {
234 return $avatar;
235 }
236 if ( $author->user_id ) {
237 grofiles_gravatars_to_append( $author->user_id );
238 } else {
239 grofiles_gravatars_to_append( $author->comment_author_email );
240 }
241 } elseif ( isset( $author->user_login ) ) {
242 grofiles_gravatars_to_append( $author->ID );
243 } elseif ( isset( $author->post_author ) ) {
244 grofiles_gravatars_to_append( $author->post_author );
245 }
246
247 return $avatar;
248 }
249
250 /**
251 * Loads Gravatar Hovercard script.
252 *
253 * @todo is_singular() only?
254 */
255 function grofiles_attach_cards() {
256
257 // Is the display of Avatars disabled?
258 if ( ! get_option( 'show_avatars' ) ) {
259 return;
260 }
261
262 // Is the display of Gravatar Hovercards disabled?
263 if ( 'disabled' === Jetpack_Options::get_option_and_ensure_autoload( 'gravatar_disable_hovercards', '0' ) ) {
264 return;
265 }
266
267 if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
268 wp_enqueue_style( 'gravatar-hovercard-style', plugins_url( '/gravatar/gravatar-hovercards-amp.css', __FILE__ ), array(), JETPACK__VERSION );
269 } else {
270 wp_enqueue_script( 'grofiles-cards', 'https://secure.gravatar.com/js/gprofiles.js', array(), GROFILES__CACHE_BUSTER, true );
271 wp_enqueue_script( 'wpgroho', plugins_url( 'wpgroho.js', __FILE__ ), array( 'grofiles-cards' ), JETPACK__VERSION, true );
272 if ( is_user_logged_in() ) {
273 $cu = wp_get_current_user();
274 $my_hash = md5( $cu->user_email );
275 } elseif ( ! empty( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) {
276 $my_hash = md5( filter_var( wp_unslash( $_COOKIE[ 'comment_author_email_' . COOKIEHASH ] ) ) );
277 } else {
278 $my_hash = '';
279 }
280 wp_localize_script( 'wpgroho', 'WPGroHo', compact( 'my_hash' ) );
281 }
282 }
283 /**
284 * Add hovercards on Discussion settings panel.
285 */
286 function grofiles_attach_cards_forced() {
287 add_filter( 'pre_option_gravatar_disable_hovercards', 'grofiles_force_gravatar_enable_hovercards' );
288 grofiles_attach_cards();
289 }
290 /**
291 * Set hovercards as enabled on Discussion settings panel.
292 */
293 function grofiles_force_gravatar_enable_hovercards() {
294 return 'enabled';
295 }
296 /**
297 * Add script to admin footer on Discussion settings panel.
298 */
299 function grofiles_admin_cards_forced() {
300 add_action( 'admin_footer', 'grofiles_attach_cards_forced' );
301 }
302 /**
303 * Add script to admin footer.
304 */
305 function grofiles_admin_cards() {
306 add_action( 'admin_footer', 'grofiles_attach_cards' );
307 }
308 /**
309 * Dequeue the FE assets when there are no gravatars on the page to be displayed.
310 */
311 function grofiles_extra_data() {
312 $authors = grofiles_gravatars_to_append();
313
314 if ( ! $authors ) {
315 wp_dequeue_script( 'grofiles-cards' );
316 wp_dequeue_script( 'wpgroho' );
317 } else {
318 ?>
319 <div style="display:none">
320 <?php
321 foreach ( $authors as $author ) {
322 grofiles_hovercards_data_html( $author );
323 }
324 ?>
325 </div>
326 <?php
327 }
328 }
329
330 /**
331 * Echoes the data from grofiles_hovercards_data() as HTML elements.
332 *
333 * @since 5.5.0 Add support for a passed WP_User object
334 *
335 * @param int|string|WP_User $author User ID, email address, or a WP_User object.
336 */
337 function grofiles_hovercards_data_html( $author ) {
338 $data = grofiles_hovercards_data( $author );
339 $hash = '';
340 if ( is_numeric( $author ) ) {
341 $user = get_userdata( $author );
342 if ( $user ) {
343 $hash = md5( $user->user_email );
344 }
345 } elseif ( is_email( $author ) ) {
346 $hash = md5( $author );
347 } elseif ( is_a( $author, 'WP_User' ) ) {
348 $hash = md5( $author->user_email );
349 }
350
351 if ( ! $hash ) {
352 return;
353 }
354 ?>
355 <div class="grofile-hash-map-<?php echo esc_attr( $hash ); ?>">
356 <?php foreach ( $data as $key => $value ) : ?>
357 <span class="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span>
358 <?php endforeach; ?>
359 </div>
360 <?php
361 }
362
363 /* API */
364
365 /**
366 * Returns the PHP callbacks for data sources.
367 *
368 * 'grofiles_hovercards_data_callbacks' filter
369 *
370 * @return array<string,callable> ( data_key => data_callback, ... )
371 */
372 function grofiles_hovercards_data_callbacks() {
373 /**
374 * Filter the Gravatar Hovercard PHP callbacks.
375 *
376 * @module gravatar-hovercards
377 *
378 * @since 1.1.0
379 *
380 * @param array $args Array of data callbacks.
381 */
382 return apply_filters( 'grofiles_hovercards_data_callbacks', array() );
383 }
384
385 /**
386 * Keyed JSON object containing all profile data provided by registered callbacks
387 *
388 * @param int|string $author User ID or email address.
389 *
390 * @return array<string,mixed> ( data_key => data, ... )
391 */
392 function grofiles_hovercards_data( $author ) {
393 $r = array();
394 foreach ( grofiles_hovercards_data_callbacks() as $key => $callback ) {
395 if ( ! is_callable( $callback ) ) {
396 continue;
397 }
398 $data = call_user_func( $callback, $author, $key );
399 if ( $data !== null ) {
400 $r[ $key ] = $data;
401 }
402 }
403
404 return $r;
405 }
406