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