PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 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 All 504 releases
← All changes | modules/gravatar-hovercards.php +17 -10 13.3.316.3-a.1 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 /**
3 3 * Module Name: Gravatar Hovercards
4 - * Module Description: Enable pop-up business cards over commenters’ Gravatars.
4 + * Module Description: Show a user’s Gravatar profile when visitors hover over their name or image.
5 5 * Sort Order: 11
6 6 * Recommendation Order: 13
7 7 * First Introduced: 1.1
8 8 * Requires Connection: No
@@ -13,8 +13,12 @@
13 13 *
14 14 * @package automattic/jetpack
15 15 */
16 16
17 +if ( ! defined( 'ABSPATH' ) ) {
18 + exit( 0 );
19 +}
20 +
17 21 define( 'GROFILES__CACHE_BUSTER', gmdate( 'YW' ) );
18 22
19 23 /**
20 24 * Actions that are run on init.
@@ -207,12 +211,12 @@
207 211 wp_cache_set( $cache_key, $response_body, $cache_group, 60 * MINUTE_IN_SECONDS );
208 212 }
209 213 }
210 214
211 - $profile = isset( $response_body->entry[0] ) ? $response_body->entry[0] : null;
212 - $display_name = isset( $profile->displayName ) ? $profile->displayName : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
213 - $location = isset( $profile->currentLocation ) ? $profile->currentLocation : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
214 - $description = isset( $profile->aboutMe ) ? $profile->aboutMe : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
215 + $profile = $response_body->entry[0] ?? null;
216 + $display_name = $profile->displayName ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
217 + $location = $profile->currentLocation ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
218 + $description = $profile->aboutMe ?? ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
215 219
216 220 $avatar = '
217 221 <figure data-amp-lightbox="true">
218 222 ' . $avatar . '
@@ -244,10 +248,8 @@
244 248 }
245 249
246 250 /**
247 251 * Loads Gravatar Hovercard script.
248 - *
249 - * @todo is_singular() only?
250 252 */
251 253 function grofiles_attach_cards() {
252 254
253 255 // Is the display of Avatars disabled?
@@ -259,8 +261,13 @@
259 261 if ( 'disabled' === Jetpack_Options::get_option_and_ensure_autoload( 'gravatar_disable_hovercards', '0' ) ) {
260 262 return;
261 263 }
262 264
265 + // Hovercards are only relevant on pages that render avatars.
266 + if ( ! is_singular() && ! is_home() && ! is_front_page() && ! is_archive() && ! is_search() ) {
267 + return;
268 + }
269 +
263 270 if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
264 271 wp_enqueue_style( 'gravatar-hovercard-style', plugins_url( '/gravatar/gravatar-hovercards-amp.css', __FILE__ ), array(), JETPACK__VERSION );
265 272 } else {
266 273 wp_enqueue_script( 'grofiles-cards', 'https://secure.gravatar.com/js/gprofiles.js', array(), GROFILES__CACHE_BUSTER, true );
@@ -362,9 +369,9 @@
362 369 * Returns the PHP callbacks for data sources.
363 370 *
364 371 * 'grofiles_hovercards_data_callbacks' filter
365 372 *
366 - * @return array( data_key => data_callback, ... )
373 + * @return array<string,callable> ( data_key => data_callback, ... )
367 374 */
368 375 function grofiles_hovercards_data_callbacks() {
369 376 /**
370 377 * Filter the Gravatar Hovercard PHP callbacks.
@@ -380,11 +387,11 @@
380 387
381 388 /**
382 389 * Keyed JSON object containing all profile data provided by registered callbacks
383 390 *
384 - * @param int|strung $author User ID or email address.
391 + * @param int|string $author User ID or email address.
385 392 *
386 - * @return array( data_key => data, ... )
393 + * @return array<string,mixed> ( data_key => data, ... )
387 394 */
388 395 function grofiles_hovercards_data( $author ) {
389 396 $r = array();
390 397 foreach ( grofiles_hovercards_data_callbacks() as $key => $callback ) {