PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.7
Jetpack – WP Security, Backup, Speed, & Growth v7.7
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
← All changes | modules/plugin-search.php +157 -174 12.8.37.7 View file →
@@ -1,30 +1,21 @@
1 -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 -/**
3 - * Adds the PSH functionality to Jetpack.
4 - *
5 - * @package automattic/jetpack
6 - */
1 +<?php
7 2
8 -// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
9 -
10 -use Automattic\Jetpack\Constants;
11 -use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
12 -use Automattic\Jetpack\Redirect;
13 3 use Automattic\Jetpack\Tracking;
14 4
15 -// Disable direct access and execution.
5 +/**
6 + * Disable direct access and execution.
7 + */
16 8 if ( ! defined( 'ABSPATH' ) ) {
17 9 exit;
18 10 }
19 11
12 +
20 13 if (
21 14 is_admin() &&
22 - Jetpack::is_connection_ready() &&
15 + Jetpack::is_active() &&
23 16 /** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
24 17 apply_filters( 'jetpack_show_promotions', true ) &&
25 - // Disable feature hints when plugins cannot be installed.
26 - ! Constants::is_true( 'DISALLOW_FILE_MODS' ) &&
27 18 jetpack_is_psh_active()
28 19 ) {
29 20 Jetpack_Plugin_Search::init();
30 21 }
@@ -39,20 +30,10 @@
39 30 * @since 7.1.0
40 31 */
41 32 class Jetpack_Plugin_Search {
42 33
43 - /**
44 - * PSH slug name.
45 - *
46 - * @var string
47 - */
48 - public static $slug = 'jetpack-plugin-search';
34 + static $slug = 'jetpack-plugin-search';
49 35
50 - /**
51 - * Singleton constructor.
52 - *
53 - * @return Jetpack_Plugin_Search
54 - */
55 36 public static function init() {
56 37 static $instance = null;
57 38
58 39 if ( ! $instance ) {
@@ -61,11 +42,8 @@
61 42
62 43 return $instance;
63 44 }
64 45
65 - /**
66 - * Jetpack_Plugin_Search constructor.
67 - */
68 46 public function __construct() {
69 47 add_action( 'current_screen', array( $this, 'start' ) );
70 48 }
71 49
@@ -71,14 +49,14 @@
71 49
72 50 /**
73 51 * Add actions and filters only if this is the plugin installation screen and it's the first page.
74 52 *
75 - * @param object $screen WP SCreen object.
53 + * @param object $screen
76 54 *
77 55 * @since 7.1.0
78 56 */
79 57 public function start( $screen ) {
80 - if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 === intval( $_GET['paged'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
58 + if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 == $_GET['paged'] ) ) {
81 59 add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) );
82 60 add_filter( 'plugins_api_result', array( $this, 'inject_jetpack_module_suggestion' ), 10, 3 );
83 61 add_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
84 62 add_filter( 'plugin_install_action_links', array( $this, 'insert_module_related_links' ), 10, 2 );
@@ -105,25 +83,21 @@
105 83 *
106 84 * @since 7.1.0
107 85 */
108 86 public static function register_endpoints() {
109 - register_rest_route(
110 - 'jetpack/v4',
111 - '/hints',
112 - array(
113 - 'methods' => WP_REST_Server::EDITABLE,
114 - 'callback' => __CLASS__ . '::dismiss',
115 - 'permission_callback' => __CLASS__ . '::can_request',
116 - 'args' => array(
117 - 'hint' => array(
118 - 'default' => '',
119 - 'type' => 'string',
120 - 'required' => true,
121 - 'validate_callback' => __CLASS__ . '::is_hint_id',
122 - ),
87 + register_rest_route( 'jetpack/v4', '/hints', array(
88 + 'methods' => WP_REST_Server::EDITABLE,
89 + 'callback' => __CLASS__ . '::dismiss',
90 + 'permission_callback' => __CLASS__ . '::can_request',
91 + 'args' => array(
92 + 'hint' => array(
93 + 'default' => '',
94 + 'type' => 'string',
95 + 'required' => true,
96 + 'validate_callback' => __CLASS__ . '::is_hint_id',
123 97 ),
124 98 )
125 - );
99 + ) );
126 100 }
127 101
128 102 /**
129 103 * A WordPress REST API permission callback method that accepts a request object and
@@ -141,11 +115,11 @@
141 115 * Validates that the ID of the hint to dismiss is a string.
142 116 *
143 117 * @since 7.1.0
144 118 *
145 - * @param string|bool $value Value to check.
119 + * @param string|bool $value Value to check.
146 120 * @param WP_REST_Request $request The request sent to the WP REST API.
147 - * @param string $param Name of the parameter passed to endpoint holding $value.
121 + * @param string $param Name of the parameter passed to endpoint holding $value.
148 122 *
149 123 * @return bool|WP_Error
150 124 */
151 125 public static function is_hint_id( $value, $request, $param ) {
@@ -150,9 +124,8 @@
150 124 */
151 125 public static function is_hint_id( $value, $request, $param ) {
152 126 return in_array( $value, Jetpack::get_available_modules(), true )
153 127 ? true
154 - /* translators: %s is the name of a parameter passed to an endpoint. */
155 128 : new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an alphanumeric string.', 'jetpack' ), $param ) );
156 129 }
157 130
158 131 /**
@@ -212,9 +185,9 @@
212 185 *
213 186 * @return bool True if $hint should be displayed.
214 187 */
215 188 protected function should_display_hint( $hint ) {
216 - $dismissed_hints = static::get_dismissed_hints();
189 + $dismissed_hints = $this->get_dismissed_hints();
217 190 // If more than 2 hints have been dismissed, then show no more.
218 191 if ( 2 < count( $dismissed_hints ) ) {
219 192 return false;
220 193 }
@@ -226,11 +199,8 @@
226 199
227 200 return ! in_array( $hint, $dismissed_hints, true );
228 201 }
229 202
230 - /**
231 - * Load the search scripts and CSS for PSH.
232 - */
233 203 public function load_plugins_search_script() {
234 204 wp_enqueue_script( self::$slug, plugins_url( 'modules/plugin-search/plugin-search.js', JETPACK__PLUGIN_FILE ), array( 'jquery' ), JETPACK__VERSION, true );
235 205 wp_localize_script(
236 206 self::$slug,
@@ -252,14 +222,14 @@
252 222 'supportText' => esc_html__(
253 223 'Learn more about these suggestions.',
254 224 'jetpack'
255 225 ),
256 - 'supportLink' => Redirect::get_url( 'plugin-hint-learn-support' ),
226 + 'supportLink' => 'https://jetpack.com/redirect/?source=plugin-hint-learn-support',
257 227 'hideText' => esc_html__( 'Hide this suggestion', 'jetpack' ),
258 228 )
259 229 );
260 230
261 - wp_enqueue_style( self::$slug, plugins_url( 'modules/plugin-search/plugin-search.css', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION );
231 + wp_enqueue_style( self::$slug, plugins_url( 'modules/plugin-search/plugin-search.css', JETPACK__PLUGIN_FILE ) );
262 232 }
263 233
264 234 /**
265 235 * Get the plugin repo's data for Jetpack to populate the fields with.
@@ -269,23 +239,20 @@
269 239 public static function get_jetpack_plugin_data() {
270 240 $data = get_transient( 'jetpack_plugin_data' );
271 241
272 242 if ( false === $data || is_wp_error( $data ) ) {
273 - include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
274 - $data = plugins_api(
275 - 'plugin_information',
276 - array(
277 - 'slug' => 'jetpack',
278 - 'is_ssl' => is_ssl(),
279 - 'fields' => array(
280 - 'banners' => true,
281 - 'reviews' => true,
282 - 'active_installs' => true,
283 - 'versions' => false,
284 - 'sections' => false,
285 - ),
286 - )
287 - );
243 + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
244 + $data = plugins_api( 'plugin_information', array(
245 + 'slug' => 'jetpack',
246 + 'is_ssl' => is_ssl(),
247 + 'fields' => array(
248 + 'banners' => true,
249 + 'reviews' => true,
250 + 'active_installs' => true,
251 + 'versions' => false,
252 + 'sections' => false,
253 + ),
254 + ) );
288 255 set_transient( 'jetpack_plugin_data', $data, DAY_IN_SECONDS );
289 256 }
290 257
291 258 return $data;
@@ -300,16 +267,16 @@
300 267 */
301 268 public function get_extra_features() {
302 269 return array(
303 270 'akismet' => array(
304 - 'name' => 'Akismet',
305 - 'search_terms' => 'akismet, anti-spam, antispam, comments, spam, spam protection, form spam, captcha, no captcha, nocaptcha, recaptcha, phising, google',
306 - 'short_description' => esc_html__( 'Keep your visitors and search engines happy by stopping comment and contact form spam with Akismet.', 'jetpack' ),
271 + 'name' => 'Akismet',
272 + 'search_terms' => 'akismet, anti-spam, antispam, comments, spam, spam protection, form spam, captcha, no captcha, nocaptcha, recaptcha, phising, google',
273 + 'short_description' => esc_html__( 'Keep your visitors and search engines happy by stopping comment and contact form spam with Akismet.', 'jetpack' ),
307 274 'requires_connection' => true,
308 - 'module' => 'akismet',
309 - 'sort' => '16',
310 - 'learn_more_button' => Redirect::get_url( 'plugin-hint-upgrade-akismet' ),
311 - 'configure_url' => admin_url( 'admin.php?page=akismet-key-config' ),
275 + 'module' => 'akismet',
276 + 'sort' => '16',
277 + 'learn_more_button' => 'https://jetpack.com/features/security/spam-filtering/',
278 + 'configure_url' => admin_url( 'admin.php?page=akismet-key-config' ),
312 279 ),
313 280 );
314 281 }
315 282
@@ -314,58 +281,45 @@
314 281 }
315 282
316 283 /**
317 284 * Intercept the plugins API response and add in an appropriate card for Jetpack
318 - *
319 - * @param object $result Plugin search results.
320 - * @param string $action unused.
321 - * @param object $args Search args.
322 285 */
323 286 public function inject_jetpack_module_suggestion( $result, $action, $args ) {
324 - /*
325 - * Bail if something else hooks into the Plugins' API response
326 - * and does not return results.
327 - */
328 - if ( empty( $result->plugins ) || is_wp_error( $result ) ) {
329 - return $result;
330 - }
331 -
332 - // Looks like a search query; it's matching time.
287 + // Looks like a search query; it's matching time
333 288 if ( ! empty( $args->search ) ) {
334 289 require_once JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php';
335 - $tracking = new Tracking();
290 + $tracking = new Tracking();
336 291 $jetpack_modules_list = array_intersect_key(
337 292 array_merge( $this->get_extra_features(), Jetpack_Admin::init()->get_modules() ),
338 - array_flip(
339 - array(
340 - 'contact-form',
341 - 'monitor',
342 - 'photon',
343 - 'photon-cdn',
344 - 'protect',
345 - 'publicize',
346 - 'related-posts',
347 - 'sharedaddy',
348 - 'akismet',
349 - 'vaultpress',
350 - 'videopress',
351 - 'search',
352 - )
353 - )
293 + array_flip( array(
294 + 'contact-form',
295 + 'lazy-images',
296 + 'monitor',
297 + 'photon',
298 + 'photon-cdn',
299 + 'protect',
300 + 'publicize',
301 + 'related-posts',
302 + 'sharedaddy',
303 + 'akismet',
304 + 'vaultpress',
305 + 'videopress',
306 + 'search',
307 + ) )
354 308 );
355 309 uasort( $jetpack_modules_list, array( $this, 'by_sorting_option' ) );
356 310
357 - // Record event when user searches for a term over 3 chars (less than 3 is not very useful).
311 + // Record event when user searches for a term over 3 chars (less than 3 is not very useful.)
358 312 if ( strlen( $args->search ) >= 3 ) {
359 313 $tracking->record_user_event( 'wpa_plugin_search_term', array( 'search_term' => $args->search ) );
360 314 }
361 315
362 - // Lowercase, trim, remove punctuation/special chars, decode url, remove 'jetpack'.
316 + // Lowercase, trim, remove punctuation/special chars, decode url, remove 'jetpack'
363 317 $normalized_term = $this->sanitize_search_term( $args->search );
364 318
365 319 $matching_module = null;
366 320
367 - // Try to match a passed search term with module's search terms.
321 + // Try to match a passed search term with module's search terms
368 322 foreach ( $jetpack_modules_list as $module_slug => $module_opts ) {
369 323 /*
370 324 * Does the site's current plan support the feature?
371 325 * We don't use Jetpack_Plan::supports() here because
@@ -384,25 +338,24 @@
384 338 }
385 339 }
386 340
387 341 if ( isset( $matching_module ) && $this->should_display_hint( $matching_module ) ) {
388 - // Record event when a matching feature is found.
342 + // Record event when a matching feature is found
389 343 $tracking->record_user_event( 'wpa_plugin_search_match_found', array( 'feature' => $matching_module ) );
390 344
391 - $inject = (array) self::get_jetpack_plugin_data();
345 + $inject = (array) self::get_jetpack_plugin_data();
392 346 $image_url = plugins_url( 'modules/plugin-search/psh', JETPACK__PLUGIN_FILE );
393 347 $overrides = array(
394 - 'plugin-search' => true, // Helps to determine if that an injected card.
395 - 'name' => sprintf( // Supplement name/description so that they clearly indicate this was added.
396 - /* translators: Jetpack module name */
348 + 'plugin-search' => true, // Helps to determine if that an injected card.
349 + 'name' => sprintf( // Supplement name/description so that they clearly indicate this was added.
397 350 esc_html_x( 'Jetpack: %s', 'Jetpack: Module Name', 'jetpack' ),
398 351 $jetpack_modules_list[ $matching_module ]['name']
399 352 ),
400 - 'short_description' => $jetpack_modules_list[ $matching_module ]['short_description'],
353 + 'short_description' => $jetpack_modules_list[ $matching_module ]['short_description'],
401 354 'requires_connection' => (bool) $jetpack_modules_list[ $matching_module ]['requires_connection'],
402 - 'slug' => self::$slug,
403 - 'version' => JETPACK__VERSION,
404 - 'icons' => array(
355 + 'slug' => self::$slug,
356 + 'version' => JETPACK__VERSION,
357 + 'icons' => array(
405 358 '1x' => "$image_url-128.png",
406 359 '2x' => "$image_url-256.png",
407 360 'svg' => "$image_url.svg",
408 361 ),
@@ -407,12 +360,12 @@
407 360 'svg' => "$image_url.svg",
408 361 ),
409 362 );
410 363
411 - // Splice in the base module data.
364 + // Splice in the base module data
412 365 $inject = array_merge( $inject, $jetpack_modules_list[ $matching_module ], $overrides );
413 366
414 - // Add it to the top of the list.
367 + // Add it to the top of the list
415 368 $result->plugins = array_filter( $result->plugins, array( $this, 'filter_cards' ) );
416 369 array_unshift( $result->plugins, $inject );
417 370 }
418 371 }
@@ -425,28 +378,14 @@
425 378 * @since 7.1.0
426 379 * @since 7.2.0 Only remove Jetpack.
427 380 * @since 7.4.0 Simplify for WordPress 5.1+.
428 381 *
429 - * @param array|object $plugin WordPress search result card.
382 + * @param array|object $plugin
430 383 *
431 384 * @return bool
432 385 */
433 - public function filter_cards( $plugin ) {
434 - /*
435 - * $plugin is normally an array.
436 - * However, since the response data can be filtered,
437 - * we cannot fully trust its format.
438 - * Let's handle both arrays and objects, and bail if it's neither.
439 - */
440 - if ( is_array( $plugin ) && ! empty( $plugin['slug'] ) ) {
441 - $slug = $plugin['slug'];
442 - } elseif ( is_object( $plugin ) && ! empty( $plugin->slug ) ) {
443 - $slug = $plugin->slug;
444 - } else {
445 - return false;
446 - }
447 -
448 - return ! in_array( $slug, array( 'jetpack' ), true );
386 + function filter_cards( $plugin ) {
387 + return ! in_array( $plugin['slug'], array( 'jetpack' ), true );
449 388 }
450 389
451 390 /**
452 391 * Take a raw search query and return something a bit more standardized and
@@ -451,10 +390,10 @@
451 390 /**
452 391 * Take a raw search query and return something a bit more standardized and
453 392 * easy to work with.
454 393 *
455 - * @param string $term The raw search term.
456 - * @return string A simplified/sanitized version.
394 + * @param String $term The raw search term
395 + * @return String A simplified/sanitized version.
457 396 */
458 397 private function sanitize_search_term( $term ) {
459 398 $term = strtolower( urldecode( $term ) );
460 399
@@ -468,11 +407,8 @@
468 407 }
469 408
470 409 /**
471 410 * Callback function to sort the array of modules by the sort option.
472 - *
473 - * @param array $m1 Array 1 to sort.
474 - * @param array $m2 Array 2 to sort.
475 411 */
476 412 private function by_sorting_option( $m1, $m2 ) {
477 413 return $m1['sort'] - $m2['sort'];
478 414 }
@@ -477,42 +413,51 @@
477 413 return $m1['sort'] - $m2['sort'];
478 414 }
479 415
480 416 /**
417 + * Builds a URL to purchase and upgrade inserting the site fragment and the affiliate code if it exists.
418 + *
419 + * @param string $feature Module slug (or forged one for extra features).
420 + *
421 + * @since 7.1.0
422 + *
423 + * @return string URL to upgrade.
424 + */
425 + private function get_upgrade_url( $feature ) {
426 + $site_raw_url = Jetpack::build_raw_urls( get_home_url() );
427 + $affiliateCode = Jetpack_Affiliate::init()->get_affiliate_code();
428 + $user = wp_get_current_user()->ID;
429 + return "https://jetpack.com/redirect/?source=plugin-hint-upgrade-$feature&site=$site_raw_url&u=$user" .
430 + ( $affiliateCode ? "&aff=$affiliateCode" : '' );
431 + }
432 +
433 + /**
481 434 * Modify the URL to the feature settings, for example Publicize.
482 435 * Sharing is included here because while we still have a page in WP Admin,
483 436 * we prefer to send users to Calypso.
484 437 *
485 - * @param string $feature Feature.
486 - * @param string $configure_url URL to configure feature.
438 + * @param string $feature
439 + * @param string $configure_url
487 440 *
488 441 * @return string
489 442 * @since 7.1.0
443 + *
490 444 */
491 445 private function get_configure_url( $feature, $configure_url ) {
446 + $siteFragment = Jetpack::build_raw_urls( get_home_url() );
492 447 switch ( $feature ) {
493 448 case 'sharing':
494 449 case 'publicize':
495 - $configure_url = Redirect::get_url( 'calypso-marketing-connections' );
450 + $configure_url = "https://wordpress.com/marketing/connections/$siteFragment";
496 451 break;
497 452 case 'seo-tools':
498 - $configure_url = Redirect::get_url(
499 - 'calypso-marketing-traffic',
500 - array(
501 - 'anchor' => 'seo',
502 - )
503 - );
453 + $configure_url = "https://wordpress.com/marketing/traffic/$siteFragment#seo";
504 454 break;
505 455 case 'google-analytics':
506 - $configure_url = Redirect::get_url(
507 - 'calypso-marketing-traffic',
508 - array(
509 - 'anchor' => 'analytics',
510 - )
511 - );
456 + $configure_url = "https://wordpress.com/marketing/traffic/$siteFragment#analytics";
512 457 break;
513 458 case 'wordads':
514 - $configure_url = Redirect::get_url( 'wpcom-ads-settings' );
459 + $configure_url = "https://wordpress.com/ads/settings/$siteFragment";
515 460 break;
516 461 }
517 462 return $configure_url;
518 463 }
@@ -518,11 +463,8 @@
518 463 }
519 464
520 465 /**
521 466 * Put some more appropriate links on our custom result cards.
522 - *
523 - * @param array $links Related links.
524 - * @param array $plugin Plugin result information.
525 467 */
526 468 public function insert_module_related_links( $links, $plugin ) {
527 469 if ( self::$slug !== $plugin['slug'] ) {
528 470 return $links;
@@ -536,9 +478,9 @@
536 478 if ( 'akismet' === $plugin['module'] || 'vaultpress' === $plugin['module'] ) {
537 479 $links['jp_get_started'] = '<a
538 480 id="plugin-select-settings"
539 481 class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button"
540 - href="' . esc_url( Redirect::get_url( 'plugin-hint-learn-' . $plugin['module'] ) ) . '"
482 + href="https://jetpack.com/redirect/?source=plugin-hint-learn-' . $plugin['module'] . '"
541 483 data-module="' . esc_attr( $plugin['module'] ) . '"
542 484 data-track="get_started"
543 485 >' . esc_html__( 'Get started', 'jetpack' ) . '</a>';
544 486 // Jetpack installed, active, feature not enabled; prompt to enable.
@@ -568,14 +510,14 @@
568 510 href="' . esc_url( $this->get_configure_url( $plugin['module'], $plugin['configure_url'] ) ) . '"
569 511 data-module="' . esc_attr( $plugin['module'] ) . '"
570 512 data-track="configure"
571 513 >' . esc_html__( 'Configure', 'jetpack' ) . '</a>';
572 - // Module is active, doesn't have options to configure.
514 + // Module is active, doesn't have options to configure
573 515 } elseif ( Jetpack::is_module_active( $plugin['module'] ) ) {
574 516 $links['jp_get_started'] = '<a
575 517 id="plugin-select-settings"
576 518 class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button"
577 - href="' . esc_url( Redirect::get_url( 'plugin-hint-learn-' . $plugin['module'] ) ) . '"
519 + href="https://jetpack.com/redirect/?source=plugin-hint-learn-' . $plugin['module'] . '"
578 520 data-module="' . esc_attr( $plugin['module'] ) . '"
579 521 data-track="get_started"
580 522 >' . esc_html__( 'Get started', 'jetpack' ) . '</a>';
581 523 }
@@ -590,9 +532,9 @@
590 532 data-track="learn_more"
591 533 >' . esc_html__( 'Learn more', 'jetpack' ) . '</a>';
592 534 }
593 535
594 - // Dismiss link.
536 + // Dismiss link
595 537 $links[] = '<a
596 538 class="jetpack-plugin-search__dismiss"
597 539 data-module="' . esc_attr( $plugin['module'] ) . '"
598 540 >' . esc_html__( 'Hide this suggestion', 'jetpack' ) . '</a>';
@@ -598,8 +540,9 @@
598 540 >' . esc_html__( 'Hide this suggestion', 'jetpack' ) . '</a>';
599 541
600 542 return $links;
601 543 }
544 +
602 545 }
603 546
604 547 /**
605 548 * Master control that checks if Plugin search hints is active.
@@ -608,13 +551,53 @@
608 551 *
609 552 * @return bool True if PSH is active.
610 553 */
611 554 function jetpack_is_psh_active() {
612 - /**
613 - * Disables the Plugin Search Hints feature found when searching the plugins page.
614 - *
615 - * @since 8.7.0
616 - *
617 - * @param bool Set false to disable the feature.
618 - */
619 - return apply_filters( 'jetpack_psh_active', true );
555 + // false means unset, 1 means active, 0 means inactive.
556 + $status = get_transient( 'jetpack_psh_status' );
557 +
558 + if ( false === $status ) {
559 + $error = false;
560 + $status = jetpack_get_remote_is_psh_active( $error );
561 + set_transient(
562 + 'jetpack_psh_status',
563 + // Cache as int
564 + (int) $status,
565 + // If there was an error, still cache but for a shorter time
566 + ( $error ? 5 : 15 ) * MINUTE_IN_SECONDS
567 + );
568 + }
569 +
570 + return (bool) $status;
571 +}
572 +
573 +/**
574 + * Makes remote request to determine if Plugin search hints is active.
575 + *
576 + * @since 7.1.1
577 + * @internal
578 + *
579 + * @param bool &$error Did the remote request result in an error?
580 + * @return bool True if PSH is active.
581 + */
582 +function jetpack_get_remote_is_psh_active( &$error ) {
583 + $response = wp_remote_get( 'https://jetpack.com/psh-status/' );
584 + if ( is_wp_error( $response ) ) {
585 + $error = true;
586 + return true;
587 + }
588 +
589 + $body = wp_remote_retrieve_body( $response );
590 + if ( empty( $body ) ) {
591 + $error = true;
592 + return true;
593 + }
594 +
595 + $json = json_decode( $body );
596 + if ( ! isset( $json->active ) ) {
597 + $error = true;
598 + return true;
599 + }
600 +
601 + $error = false;
602 + return (bool) $json->active;
620 603 }