Completed
Push — update/import-sync-detection ( 0bf98c...8808a0 )
by
unknown
25:48 queued 17:49
created

Jetpack_Plugin_Search   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 489
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 489
rs 4.5599
c 0
b 0
f 0
wmc 58
lcom 1
cbo 6

21 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 2
A __construct() 0 3 1
A start() 0 8 4
A plugin_details() 0 5 2
A register_endpoints() 0 15 1
A can_request() 0 3 1
A is_hint_id() 0 5 2
A dismiss() 0 5 2
A get_dismissed_hints() 0 6 3
A add_to_dismissed_hints() 0 3 1
A is_not_dismissed() 0 3 1
A load_plugins_search_script() 0 24 1
A get_jetpack_plugin_data() 0 21 3
A get_extra_features() 0 14 1
B inject_jetpack_module_suggestion() 0 76 7
A filter_cards() 0 6 2
A sanitize_search_term() 0 11 1
A by_sorting_option() 0 3 1
A get_upgrade_url() 0 7 2
A get_configure_url() 0 19 6
C insert_module_related_links() 0 82 14

How to fix   Complexity   

Complex Class

Complex classes like Jetpack_Plugin_Search often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Jetpack_Plugin_Search, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Disable direct access and execution.
4
 */
5
if ( ! defined( 'ABSPATH' ) ) {
6
	exit;
7
}
8
9
10
if (
11
	is_admin() &&
12
	Jetpack::is_active() &&
13
	/** This filter is documented in _inc/lib/admin-pages/class.jetpack-react-page.php */
14
	apply_filters( 'jetpack_show_promotions', true ) &&
15
	jetpack_is_psh_active()
16
) {
17
	Jetpack_Plugin_Search::init();
18
}
19
20
// Register endpoints when WP REST API is initialized.
21
add_action( 'rest_api_init', array( 'Jetpack_Plugin_Search', 'register_endpoints' ) );
22
23
/**
24
 * Class that includes cards in the plugin search results when users enter terms that match some Jetpack feature.
25
 * Card can be dismissed and includes a title, description, button to enable the feature and a link for more information.
26
 *
27
 * @since 7.1.0
28
 */
29
class Jetpack_Plugin_Search {
30
31
	static $slug = 'jetpack-plugin-search';
32
33
	public static function init() {
34
		static $instance = null;
35
36
		if ( ! $instance ) {
37
			jetpack_require_lib( 'tracks/client' );
38
			$instance = new Jetpack_Plugin_Search();
39
		}
40
41
		return $instance;
42
	}
43
44
	public function __construct() {
45
		add_action( 'current_screen', array( $this, 'start' ) );
46
	}
47
48
	/**
49
	 * Add actions and filters only if this is the plugin installation screen and it's the first page.
50
	 *
51
	 * @param object $screen
52
	 *
53
	 * @since 7.1.0
54
	 */
55
	public function start( $screen ) {
56
		if ( 'plugin-install' === $screen->base && ( ! isset( $_GET['paged'] ) || 1 == $_GET['paged'] ) ) {
57
			add_action( 'admin_enqueue_scripts', array( $this, 'load_plugins_search_script' ) );
58
			add_filter( 'plugins_api_result', array( $this, 'inject_jetpack_module_suggestion' ), 10, 3 );
59
			add_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
60
			add_filter( 'plugin_install_action_links', array( $this, 'insert_module_related_links' ), 10, 2 );
61
		}
62
	}
63
64
	/**
65
	 * Modify URL used to fetch to plugin information so it pulls Jetpack plugin page.
66
	 *
67
	 * @param string $url URL to load in dialog pulling the plugin page from wporg.
68
	 *
69
	 * @since 7.1.0
70
	 *
71
	 * @return string The URL with 'jetpack' instead of 'jetpack-plugin-search'.
72
	 */
73
	public function plugin_details( $url ) {
74
		return false !== stripos( $url, 'tab=plugin-information&amp;plugin=' . self::$slug )
75
			? 'plugin-install.php?tab=plugin-information&amp;plugin=jetpack&amp;TB_iframe=true&amp;width=600&amp;height=550'
76
			: $url;
77
	}
78
79
	/**
80
	 * Register REST API endpoints.
81
	 *
82
	 * @since 7.1.0
83
	 */
84
	public static function register_endpoints() {
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',
95
				),
96
			)
97
		) );
98
	}
99
100
	/**
101
	 * A WordPress REST API permission callback method that accepts a request object and
102
	 * decides if the current user has enough privileges to act.
103
	 *
104
	 * @since 7.1.0
105
	 *
106
	 * @return bool does a current user have enough privileges.
107
	 */
108
	public static function can_request() {
109
		return current_user_can( 'jetpack_admin_page' );
110
	}
111
112
	/**
113
	 * Validates that the ID of the hint to dismiss is a string.
114
	 *
115
	 * @since 7.1.0
116
	 *
117
	 * @param string|bool $value Value to check.
118
	 * @param WP_REST_Request $request The request sent to the WP REST API.
119
	 * @param string $param Name of the parameter passed to endpoint holding $value.
120
	 *
121
	 * @return bool|WP_Error
122
	 */
123
	public static function is_hint_id( $value, $request, $param ) {
124
		return in_array( $value, Jetpack::get_available_modules(), true )
125
			? true
126
			: new WP_Error( 'invalid_param', sprintf( esc_html__( '%s must be an alphanumeric string.', 'jetpack' ), $param ) );
127
	}
128
129
	/**
130
	 * A WordPress REST API callback method that accepts a request object and decides what to do with it.
131
	 *
132
	 * @param WP_REST_Request $request {
133
	 *     Array of parameters received by request.
134
	 *
135
	 *     @type string $hint Slug of card to dismiss.
136
	 * }
137
	 *
138
	 * @since 7.1.0
139
	 *
140
	 * @return bool|array|WP_Error a resulting value or object, or an error.
141
	 */
142
	public static function dismiss( WP_REST_Request $request ) {
143
		return self::add_to_dismissed_hints( $request['hint'] )
144
			? rest_ensure_response( array( 'code' => 'success' ) )
145
			: new WP_Error( 'not_dismissed', esc_html__( 'The card could not be dismissed', 'jetpack' ), array( 'status' => 400 ) );
146
	}
147
148
	/**
149
	 * Returns a list of previously dismissed hints.
150
	 *
151
	 * @since 7.1.0
152
	 *
153
	 * @return array List of dismissed hints.
154
	 */
155
	protected static function get_dismissed_hints() {
156
		$dismissed_hints = Jetpack_Options::get_option( 'dismissed_hints' );
157
		return isset( $dismissed_hints ) && is_array( $dismissed_hints )
158
			? $dismissed_hints
159
			: array();
160
	}
161
162
	/**
163
	 * Save the hint in the list of dismissed hints.
164
	 *
165
	 * @since 7.1.0
166
	 *
167
	 * @param string $hint The hint id, which is a Jetpack module slug.
168
	 *
169
	 * @return bool Whether the card was added to the list and hence dismissed.
170
	 */
171
	protected static function add_to_dismissed_hints( $hint ) {
172
		return Jetpack_Options::update_option( 'dismissed_hints', array_merge( self::get_dismissed_hints(), array( $hint ) ) );
173
	}
174
175
	/**
176
	 * Checks that the module slug passed, the hint, is not in the list of previously dismissed hints.
177
	 *
178
	 * @since 7.1.0
179
	 *
180
	 * @param string $hint The hint id, which is a Jetpack module slug.
181
	 *
182
	 * @return bool True if $hint wasn't already dismissed.
183
	 */
184
	protected function is_not_dismissed( $hint ) {
185
		return ! in_array( $hint, $this->get_dismissed_hints(), true );
186
	}
187
188
	public function load_plugins_search_script() {
189
		wp_enqueue_script( self::$slug, plugins_url( 'modules/plugin-search/plugin-search.js', JETPACK__PLUGIN_FILE ), array( 'jquery' ), JETPACK__VERSION, true );
190
		wp_localize_script(
191
			self::$slug,
192
			'jetpackPluginSearch',
193
			array(
194
				'nonce'          => wp_create_nonce( 'wp_rest' ),
195
				'base_rest_url'  => rest_url( '/jetpack/v4' ),
196
				'manageSettings' => esc_html__( 'Configure', 'jetpack' ),
197
				'activateModule' => esc_html__( 'Activate Module', 'jetpack' ),
198
				'getStarted'     => esc_html__( 'Get started', 'jetpack' ),
199
				'activated'      => esc_html__( 'Activated', 'jetpack' ),
200
				'activating'     => esc_html__( 'Activating', 'jetpack' ),
201
				'logo'           => 'https://ps.w.org/jetpack/assets/icon.svg?rev=1791404',
202
				'legend'         => esc_html__(
203
					'Jetpack is trusted by millions to help secure and speed up their WordPress site. Make the most of it today.',
204
					'jetpack'
205
				),
206
				'hideText'       => esc_html__( 'Hide this suggestion', 'jetpack' ),
207
			)
208
		);
209
210
		wp_enqueue_style( self::$slug, plugins_url( 'modules/plugin-search/plugin-search.css', JETPACK__PLUGIN_FILE ) );
211
	}
212
213
	/**
214
	 * Get the plugin repo's data for Jetpack to populate the fields with.
215
	 *
216
	 * @return array|mixed|object|WP_Error
217
	 */
218
	public static function get_jetpack_plugin_data() {
219
		$data = get_transient( 'jetpack_plugin_data' );
220
221
		if ( false === $data || is_wp_error( $data ) ) {
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
			) );
234
			set_transient( 'jetpack_plugin_data', $data, DAY_IN_SECONDS );
235
		}
236
237
		return $data;
238
	}
239
240
	/**
241
	 * Create a list with additional features for those we don't have a module, like Akismet.
242
	 *
243
	 * @since 7.1.0
244
	 *
245
	 * @return array List of features.
246
	 */
247
	public function get_extra_features() {
248
		return array(
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' ),
253
				'requires_connection' => true,
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' ),
258
			),
259
		);
260
	}
261
262
	/**
263
	 * Intercept the plugins API response and add in an appropriate card for Jetpack
264
	 */
265
	public function inject_jetpack_module_suggestion( $result, $action, $args ) {
266
267
		// Looks like a search query; it's matching time
268
		if ( ! empty( $args->search ) ) {
269
			require_once JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php';
270
			$jetpack_modules_list = array_intersect_key(
271
				array_merge( $this->get_extra_features(), Jetpack_Admin::init()->get_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
				) )
287
			);
288
			uasort( $jetpack_modules_list, array( $this, 'by_sorting_option' ) );
289
290
			// Record event when user searches for a term over 3 chars (less than 3 is not very useful.)
291
			if ( strlen( $args->search ) >= 3 ) {
292
				JetpackTracking::record_user_event( 'wpa_plugin_search_term', array( 'search_term' => $args->search ) );
293
			}
294
295
			// Lowercase, trim, remove punctuation/special chars, decode url, remove 'jetpack'
296
			$normalized_term = $this->sanitize_search_term( $args->search );
297
298
			$matching_module = null;
299
300
			// Try to match a passed search term with module's search terms
301
			foreach ( $jetpack_modules_list as $module_slug => $module_opts ) {
302
				if ( false !== stripos( $module_opts['search_terms'] . ', ' . $module_opts['name'], $normalized_term ) ) {
303
					$matching_module = $module_slug;
304
					break;
305
				}
306
			}
307
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 ) );
311
312
				$inject = (array) self::get_jetpack_plugin_data();
313
				$image_url = plugins_url( 'modules/plugin-search/psh', JETPACK__PLUGIN_FILE );
314
				$overrides = array(
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.
317
						esc_html_x( 'Jetpack: %s', 'Jetpack: Module Name', 'jetpack' ),
318
						$jetpack_modules_list[ $matching_module ]['name']
319
					),
320
					'short_description' => $jetpack_modules_list[ $matching_module ]['short_description'],
321
					'requires_connection' => (bool) $jetpack_modules_list[ $matching_module ]['requires_connection'],
322
					'slug'    => self::$slug,
323
					'version' => JETPACK__VERSION,
324
					'icons' => array(
325
						'1x'  => "$image_url-128.png",
326
						'2x'  => "$image_url-256.png",
327
						'svg' => "$image_url.svg",
328
					),
329
				);
330
331
				// Splice in the base module data
332
				$inject = array_merge( $inject, $jetpack_modules_list[ $matching_module ], $overrides );
333
334
				// Add it to the top of the list
335
				$result->plugins = array_filter( $result->plugins, array( $this, 'filter_cards' ) );
336
				array_unshift( $result->plugins, $inject );
337
			}
338
		}
339
		return $result;
340
	}
341
342
	/**
343
	 * Remove cards for Akismet, Jetpack and VaultPress plugins since we don't want duplicates.
344
	 *
345
	 * @param array|object $plugin
346
	 *
347
	 * @return bool
348
	 */
349
	function filter_cards( $plugin ) {
350
		// Take in account that before WordPress 5.1, the list of plugins is an array of objects.
351
		// With WordPress 5.1 the list of plugins is an array of arrays.
352
		$slug = is_array( $plugin ) ? $plugin['slug'] : $plugin->slug;
353
		return ! in_array( $slug, array( 'akismet', 'jetpack', 'vaultpress' ), true );
354
	}
355
356
	/**
357
	 * Take a raw search query and return something a bit more standardized and
358
	 * easy to work with.
359
	 *
360
	 * @param  String $term The raw search term
361
	 * @return String A simplified/sanitized version.
362
	 */
363
	private function sanitize_search_term( $term ) {
364
		$term = strtolower( urldecode( $term ) );
365
366
		// remove non-alpha/space chars.
367
		$term = preg_replace( '/[^a-z ]/', '', $term );
368
369
		// remove strings that don't help matches.
370
		$term = trim( str_replace( array( 'jetpack', 'jp', 'free', 'wordpress' ), '', $term ) );
371
372
		return $term;
373
	}
374
375
	/**
376
	 * Callback function to sort the array of modules by the sort option.
377
	 */
378
	private function by_sorting_option( $m1, $m2 ) {
379
		return $m1['sort'] - $m2['sort'];
380
	}
381
382
	/**
383
	 * Builds a URL to purchase and upgrade inserting the site fragment and the affiliate code if it exists.
384
	 *
385
	 * @param string $feature Module slug (or forged one for extra features).
386
	 *
387
	 * @since 7.1.0
388
	 *
389
	 * @return string URL to upgrade.
390
	 */
391
	private function get_upgrade_url( $feature ) {
392
		$site_raw_url = Jetpack::build_raw_urls( get_home_url() );
393
		$affiliateCode = Jetpack_Affiliate::init()->get_affiliate_code();
394
		$user = wp_get_current_user()->ID;
395
		return "https://jetpack.com/redirect/?source=plugin-hint-upgrade-$feature&site=$site_raw_url&u=$user" .
396
		       ( $affiliateCode ? "&aff=$affiliateCode" : '' );
397
	}
398
399
	/**
400
	 * Modify the URL to the feature settings, for example Publicize.
401
	 * Sharing is included here because while we still have a page in WP Admin,
402
	 * we prefer to send users to Calypso.
403
	 *
404
	 * @param string $feature
405
	 * @param string $configure_url
406
	 *
407
	 * @return string
408
	 * @since 7.1.0
409
	 *
410
	 */
411
	private function get_configure_url( $feature, $configure_url ) {
412
		$siteFragment = Jetpack::build_raw_urls( get_home_url() );
413
		switch ( $feature ) {
414
			case 'sharing':
415
			case 'publicize':
416
				$configure_url = "https://wordpress.com/sharing/$siteFragment";
417
				break;
418
			case 'seo-tools':
419
				$configure_url = "https://wordpress.com/settings/traffic/$siteFragment#seo";
420
				break;
421
			case 'google-analytics':
422
				$configure_url = "https://wordpress.com/settings/traffic/$siteFragment#analytics";
423
				break;
424
			case 'wordads':
425
				$configure_url = "https://wordpress.com/ads/settings/$siteFragment";
426
				break;
427
		}
428
		return $configure_url;
429
	}
430
431
	/**
432
	 * Put some more appropriate links on our custom result cards.
433
	 */
434
	public function insert_module_related_links( $links, $plugin ) {
435
		if ( self::$slug !== $plugin['slug'] ) {
436
			return $links;
437
		}
438
439
		// By the time this filter is applied, self_admin_url was already applied and we don't need it anymore.
440
		remove_filter( 'self_admin_url', array( $this, 'plugin_details' ) );
441
442
		$links = array();
443
444
		if ( 'akismet' === $plugin['module'] || 'vaultpress' === $plugin['module'] ) {
445
			$links['jp_get_started'] = '<a
446
				id="plugin-select-settings"
447
				class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button"
448
				href="https://jetpack.com/redirect/?source=plugin-hint-learn-' . $plugin['module'] . '"
449
				data-module="' . esc_attr( $plugin['module'] ) . '"
450
				data-track="get_started"
451
				>' . esc_html__( 'Get started', 'jetpack' ) . '</a>';
452
			// Jetpack installed, active, feature not enabled; prompt to enable.
453
		} elseif (
454
			current_user_can( 'jetpack_activate_modules' ) &&
455
			! Jetpack::is_module_active( $plugin['module'] )
456
		) {
457
			$links[] = Jetpack_Plan::supports( $plugin['module'] )
458
				? '<button
459
					id="plugin-select-activate"
460
					class="jetpack-plugin-search__primary button"
461
					data-module="' . esc_attr( $plugin['module'] ) . '"
462
					data-configure-url="' . esc_url( $this->get_configure_url( $plugin['module'], $plugin['configure_url'] ) ) . '"
463
					> ' . esc_html__( 'Enable', 'jetpack' ) . '</button>'
464
				: '<a
465
					class="jetpack-plugin-search__primary button"
466
					href="' . esc_url( $this->get_upgrade_url( $plugin['module'] ) ) . '"
467
					data-module="' . esc_attr( $plugin['module'] ) . '"
468
					data-track="purchase"
469
					> ' . esc_html__( 'Purchase', 'jetpack' ) . '</button>';
470
471
			// Jetpack installed, active, feature enabled; link to settings.
472
		} elseif (
473
			! empty( $plugin['configure_url'] ) &&
474
			current_user_can( 'jetpack_configure_modules' ) &&
475
			Jetpack::is_module_active( $plugin['module'] ) &&
476
			/** This filter is documented in class.jetpack-admin.php */
477
			apply_filters( 'jetpack_module_configurable_' . $plugin['module'], false )
478
		) {
479
			$links[] = '<a
480
				id="plugin-select-settings"
481
				class="jetpack-plugin-search__primary button jetpack-plugin-search__configure"
482
				href="' . esc_url( $this->get_configure_url( $plugin['module'], $plugin['configure_url'] ) ) . '"
483
				data-module="' . esc_attr( $plugin['module'] ) . '"
484
				data-track="configure"
485
				>' . esc_html__( 'Configure', 'jetpack' ) . '</a>';
486
			// Module is active, doesn't have options to configure
487
		} elseif ( Jetpack::is_module_active( $plugin['module'] ) ) {
488
			$links['jp_get_started'] = '<a
489
				id="plugin-select-settings"
490
				class="jetpack-plugin-search__primary jetpack-plugin-search__get-started button"
491
				href="https://jetpack.com/redirect/?source=plugin-hint-learn-' . $plugin['module'] . '"
492
				data-module="' . esc_attr( $plugin['module'] ) . '"
493
				data-track="get_started"
494
				>' . esc_html__( 'Get started', 'jetpack' ) . '</a>';
495
		}
496
497
		// Add link pointing to a relevant doc page in jetpack.com only if the Get started button isn't displayed.
498
		if ( ! empty( $plugin['learn_more_button'] ) && ! isset( $links['jp_get_started'] ) ) {
499
			$links[] = '<a
500
				class="jetpack-plugin-search__learn-more"
501
				href="' . esc_url( $plugin['learn_more_button'] ) . '"
502
				target="_blank"
503
				data-module="' . esc_attr( $plugin['module'] ) . '"
504
				data-track="learn_more"
505
				>' . esc_html__( 'Learn more', 'jetpack' ) . '</a>';
506
		}
507
508
		// Dismiss link
509
		$links[] = '<a
510
			class="jetpack-plugin-search__dismiss"
511
			data-module="' . esc_attr( $plugin['module'] ) . '"
512
			>' . esc_html__( 'Hide this suggestion', 'jetpack' ) . '</a>';
513
514
		return $links;
515
	}
516
517
}
518
519
/**
520
 * Master control that checks if Plugin search hints is active.
521
 *
522
 * @since 7.1.1
523
 *
524
 * @return bool True if PSH is active.
525
 */
526
function jetpack_is_psh_active() {
527
	// false means unset, 1 means active, 0 means inactive.
528
	$status = get_transient( 'jetpack_psh_status' );
529
530
	if ( false === $status ) {
531
		$error = false;
532
		$status = jetpack_get_remote_is_psh_active( $error );
533
		set_transient(
534
			'jetpack_psh_status',
535
			// Cache as int
536
			(int) $status,
537
			// If there was an error, still cache but for a shorter time
538
			( $error ? 5 : 15 ) * MINUTE_IN_SECONDS
539
		);
540
	}
541
542
	return (bool) $status;
543
}
544
545
/**
546
 * Makes remote request to determine if Plugin search hints is active.
547
 *
548
 * @since 7.1.1
549
 * @internal
550
 *
551
 * @param bool &$error Did the remote request result in an error?
552
 * @return bool True if PSH is active.
553
 */
554
function jetpack_get_remote_is_psh_active( &$error ) {
555
	$response = wp_remote_get( 'https://jetpack.com/psh-status/' );
556
	if ( is_wp_error( $response ) ) {
557
		$error = true;
558
		return true;
559
	}
560
561
	$body = wp_remote_retrieve_body( $response );
562
	if ( empty( $body ) ) {
563
		$error = true;
564
		return true;
565
	}
566
567
	$json = json_decode( $body );
568
	if ( ! isset( $json->active ) ) {
569
		$error = true;
570
		return true;
571
	}
572
573
	$error = false;
574
	return (bool) $json->active;
575
}
576