Completed
Push — try/full-sync-send-immediately ( 69933c...d3ce76 )
by
unknown
08:52
created

JITM::delete_user_update_connection_owner_notice()   C

Complexity

Conditions 14
Paths 33

Size

Total Lines 161

Duplication

Lines 5
Ratio 3.11 %

Importance

Changes 0
Metric Value
cc 14
nc 33
nop 0
dl 5
loc 161
rs 5.0133
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Jetpack's JITM class.
4
 *
5
 * @package automattic/jetpack-jitm
6
 */
7
8
namespace Automattic\Jetpack;
9
10
use Automattic\Jetpack\Assets;
11
use Automattic\Jetpack\Connection\Manager as Jetpack_Connection;
12
use Automattic\Jetpack\Connection\Client;
13
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
14
use Automattic\Jetpack\Tracking;
15
use Automattic\Jetpack\Connection\Manager;
16
17
/**
18
 * Jetpack just in time messaging through out the admin
19
 *
20
 * @since 5.6.0
21
 */
22
class JITM {
23
24
	const PACKAGE_VERSION = '1.0'; // TODO: Keep in sync with version specified in composer.json.
25
26
	/**
27
	 * Tracking object.
28
	 *
29
	 * @var Automattic\Jetpack\Tracking
30
	 *
31
	 * @access private
32
	 */
33
	private $tracking;
34
35
	/**
36
	 * JITM constructor.
37
	 */
38
	public function __construct() {
39
		$this->tracking = new Tracking();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Automattic\Jetpack\Tracking() of type object<Automattic\Jetpack\Tracking> is incompatible with the declared type object<Automattic\Jetpac...attic\Jetpack\Tracking> of property $tracking.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
	}
41
42
	/**
43
	 * Determines if JITMs are enabled.
44
	 *
45
	 * @return bool Enable JITMs.
46
	 */
47
	public function register() {
48
		/**
49
		 * Filter to turn off all just in time messages
50
		 *
51
		 * @since 3.7.0
52
		 * @since 5.4.0 Correct docblock to reflect default arg value
53
		 *
54
		 * @param bool false Whether to show just in time messages.
55
		 */
56
		if ( ! apply_filters( 'jetpack_just_in_time_msgs', false ) ) {
57
			return false;
58
		}
59
		add_action( 'current_screen', array( $this, 'prepare_jitms' ) );
60
		return true;
61
	}
62
63
	/**
64
	 * Prepare actions according to screen and post type.
65
	 *
66
	 * @since 3.8.2
67
	 *
68
	 * @uses Jetpack_Autoupdate::get_possible_failures()
69
	 *
70
	 * @param \WP_Screen $screen WP Core's screen object.
71
	 */
72
	public function prepare_jitms( $screen ) {
73
		if ( ! in_array(
74
			$screen->id,
75
			array(
76
				'jetpack_page_stats',
77
				'jetpack_page_akismet-key-config',
78
				'admin_page_jetpack_modules',
79
			),
80
			true
81
		) ) {
82
			add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
83
			add_action( 'admin_notices', array( $this, 'ajax_message' ) );
84
			add_action( 'edit_form_top', array( $this, 'ajax_message' ) );
85
86
			// Not really a JITM. Don't know where else to put this :) .
87
			add_action( 'admin_notices', array( $this, 'delete_user_update_connection_owner_notice' ) );
88
		}
89
	}
90
91
	/**
92
	 * A special filter for WooCommerce, to set a message based on local state.
93
	 *
94
	 * @param string $content The current message.
95
	 *
96
	 * @return array The new message.
97
	 */
98
	public static function jitm_woocommerce_services_msg( $content ) {
99
		if ( ! function_exists( 'wc_get_base_location' ) ) {
100
			return $content;
101
		}
102
103
		$base_location = wc_get_base_location();
104
105
		switch ( $base_location['country'] ) {
106
			case 'US':
107
				$content->message = esc_html__( 'New free service: Show USPS shipping rates on your store! Added bonus: print shipping labels without leaving WooCommerce.', 'jetpack' );
108
				break;
109
			case 'CA':
110
				$content->message = esc_html__( 'New free service: Show Canada Post shipping rates on your store!', 'jetpack' );
111
				break;
112
			default:
113
				$content->message = '';
114
		}
115
116
		return $content;
117
	}
118
119
	/**
120
	 * A special filter for WooCommerce Call To Action button
121
	 *
122
	 * @return string The new CTA
123
	 */
124
	public static function jitm_jetpack_woo_services_install() {
125
		return wp_nonce_url(
126
			add_query_arg(
127
				array(
128
					'wc-services-action' => 'install',
129
				),
130
				admin_url( 'admin.php?page=wc-settings' )
131
			),
132
			'wc-services-install'
133
		);
134
	}
135
136
	/**
137
	 * A special filter for WooCommerce Call To Action button.
138
	 *
139
	 * @return string The new CTA
140
	 */
141
	public static function jitm_jetpack_woo_services_activate() {
142
		return wp_nonce_url(
143
			add_query_arg(
144
				array(
145
					'wc-services-action' => 'activate',
146
				),
147
				admin_url( 'admin.php?page=wc-settings' )
148
			),
149
			'wc-services-install'
150
		);
151
	}
152
153
	/**
154
	 * This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
155
	 * the connection owner.
156
	 */
157
	public function delete_user_update_connection_owner_notice() {
158
		global $current_screen;
159
160
		/*
161
		 * phpcs:disable WordPress.Security.NonceVerification.Recommended
162
		 *
163
		 * This function is firing within wp-admin and checks (below) if it is in the midst of a deletion on the users
164
		 * page. Nonce will be already checked by WordPress, so we do not need to check ourselves.
165
		 */
166
167
		if ( ! isset( $current_screen->base ) || 'users' !== $current_screen->base ) {
168
			return;
169
		}
170
171
		if ( ! isset( $_REQUEST['action'] ) || 'delete' !== $_REQUEST['action'] ) {
172
			return;
173
		}
174
175
		// Get connection owner or bail.
176
		$connection_manager  = new Manager();
177
		$connection_owner_id = $connection_manager->get_connection_owner_id();
178
		if ( ! $connection_owner_id ) {
179
			return;
180
		}
181
		$connection_owner_userdata = get_userdata( $connection_owner_id );
182
183
		// Bail if we're not trying to delete connection owner.
184
		$user_ids_to_delete = array();
185 View Code Duplication
		if ( isset( $_REQUEST['users'] ) ) {
186
			$user_ids_to_delete = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['users'] ) );
187
		} elseif ( isset( $_REQUEST['user'] ) ) {
188
			$user_ids_to_delete[] = sanitize_text_field( wp_unslash( $_REQUEST['user'] ) );
189
		}
190
191
		// phpcs:enable
192
		$user_ids_to_delete        = array_map( 'absint', $user_ids_to_delete );
193
		$deleting_connection_owner = in_array( $connection_owner_id, (array) $user_ids_to_delete, true );
194
		if ( ! $deleting_connection_owner ) {
195
			return;
196
		}
197
198
		// Bail if they're trying to delete themselves to avoid confusion.
199
		if ( get_current_user_id() === $connection_owner_id ) {
200
			return;
201
		}
202
203
		// Track it!
204
		if ( method_exists( $this->tracking, 'record_user_event' ) ) {
205
			$this->tracking->record_user_event( 'delete_connection_owner_notice_view' );
206
		}
207
208
		$connection_manager = new Manager();
209
		$connected_admins   = $connection_manager->get_connected_users( 'jetpack_disconnect' );
210
		$user               = is_a( $connection_owner_userdata, 'WP_User' ) ? esc_html( $connection_owner_userdata->data->user_login ) : '';
211
212
		echo "<div class='notice notice-warning' id='jetpack-notice-switch-connection-owner'>";
213
		echo '<h2>' . esc_html__( 'Important notice about your Jetpack connection:', 'jetpack' ) . '</h2>';
214
		echo '<p>' . sprintf(
215
			/* translators: WordPress User, if available. */
216
			esc_html__( 'Warning! You are about to delete the Jetpack connection owner (%s) for this site, which may cause some of your Jetpack features to stop working.', 'jetpack' ),
217
			esc_html( $user )
218
		) . '</p>';
219
220
		if ( ! empty( $connected_admins ) && count( $connected_admins ) > 1 ) {
221
			echo '<form id="jp-switch-connection-owner" action="" method="post">';
222
			echo "<label for='owner'>" . esc_html__( 'You can choose to transfer connection ownership to one of these already-connected admins:', 'jetpack' ) . ' </label>';
223
224
			$connected_admin_ids = array_map(
225
				function( $connected_admin ) {
226
						return $connected_admin->ID;
227
				},
228
				$connected_admins
229
			);
230
231
			wp_dropdown_users(
232
				array(
233
					'name'    => 'owner',
234
					'include' => array_diff( $connected_admin_ids, array( $connection_owner_id ) ),
235
					'show'    => 'display_name_with_login',
236
				)
237
			);
238
239
			echo '<p>';
240
			submit_button( esc_html__( 'Set new connection owner', 'jetpack' ), 'primary', 'jp-switch-connection-owner-submit', false );
241
			echo '</p>';
242
243
			echo "<div id='jp-switch-user-results'></div>";
244
			echo '</form>';
245
			?>
246
			<script type="text/javascript">
247
				jQuery( document ).ready( function( $ ) {
248
					$( '#jp-switch-connection-owner' ).on( 'submit', function( e ) {
249
						var formData = $( this ).serialize();
250
						var submitBtn = document.getElementById( 'jp-switch-connection-owner-submit' );
251
						var results = document.getElementById( 'jp-switch-user-results' );
252
253
						submitBtn.disabled = true;
254
255
						$.ajax( {
256
							type        : "POST",
257
							url         : "<?php echo esc_url( get_rest_url() . 'jetpack/v4/connection/owner' ); ?>",
258
							data        : formData,
259
							headers     : {
260
								'X-WP-Nonce': "<?php echo esc_js( wp_create_nonce( 'wp_rest' ) ); ?>",
261
							},
262
							success: function() {
263
								results.innerHTML = "<?php esc_html_e( 'Success!', 'jetpack' ); ?>";
264
								setTimeout( function() {
265
									$( '#jetpack-notice-switch-connection-owner' ).hide( 'slow' );
266
								}, 1000 );
267
							}
268
						} ).done( function() {
269
							submitBtn.disabled = false;
270
						} );
271
272
						e.preventDefault();
273
						return false;
274
					} );
275
				} );
276
			</script>
277
			<?php
278
		} else {
279
			echo '<p>' . esc_html__( 'Every Jetpack site needs at least one connected admin for the features to work properly. Please connect to your WordPress.com account via the button below. Once you connect, you may refresh this page to see an option to change the connection owner.', 'jetpack' ) . '</p>';
280
			$connect_url = \Jetpack::init()->build_connect_url( false, false, 'delete_connection_owner_notice' );
281
			echo "<a href='" . esc_url( $connect_url ) . "' target='_blank' rel='noopener noreferrer' class='button-primary'>" . esc_html__( 'Connect to WordPress.com', 'jetpack' ) . '</a>';
282
		}
283
284
		echo '<p>';
285
		printf(
286
			wp_kses(
287
				/* translators: URL to Jetpack support doc regarding the primary user. */
288
				__( "<a href='%s' target='_blank' rel='noopener noreferrer'>Learn more</a> about the connection owner and what will break if you do not have one.", 'jetpack' ),
289
				array(
290
					'a' => array(
291
						'href'   => true,
292
						'target' => true,
293
						'rel'    => true,
294
					),
295
				)
296
			),
297
			'https://jetpack.com/support/primary-user/'
298
		);
299
		echo '</p>';
300
		echo '<p>';
301
		printf(
302
			wp_kses(
303
				/* translators: URL to contact Jetpack support. */
304
				__( 'As always, feel free to <a href="%s" target="_blank" rel="noopener noreferrer">contact our support team</a> if you have any questions.', 'jetpack' ),
305
				array(
306
					'a' => array(
307
						'href'   => true,
308
						'target' => true,
309
						'rel'    => true,
310
					),
311
				)
312
			),
313
			'https://jetpack.com/contact-support'
314
		);
315
		echo '</p>';
316
		echo '</div>';
317
	}
318
319
	/**
320
	 * Injects the dom to show a JITM inside of wp-admin.
321
	 */
322
	public function ajax_message() {
323
		if ( ! is_admin() ) {
324
			return;
325
		}
326
327
		// do not display on Gutenberg pages.
328
		if ( $this->is_gutenberg_page() ) {
329
			return;
330
		}
331
332
		$message_path   = $this->get_message_path();
333
		$query_string   = _http_build_query( $_GET, '', ',' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
334
		$current_screen = wp_unslash( $_SERVER['REQUEST_URI'] );
335
		?>
336
		<div class="jetpack-jitm-message"
337
			data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_rest' ) ); ?>"
338
			data-message-path="<?php echo esc_attr( $message_path ); ?>"
339
			data-query="<?php echo urlencode_deep( $query_string ); ?>"
340
			data-redirect="<?php echo urlencode_deep( $current_screen ); ?>"
341
		></div>
342
		<?php
343
	}
344
345
	/**
346
	 * Get's the current message path for display of a JITM
347
	 *
348
	 * @return string The message path
349
	 */
350
	public function get_message_path() {
351
		$screen = get_current_screen();
352
353
		return 'wp:' . $screen->id . ':' . current_filter();
354
	}
355
356
	/**
357
	 * Function to enqueue jitm css and js
358
	 */
359
	public function jitm_enqueue_files() {
360
		if ( $this->is_gutenberg_page() ) {
361
			return;
362
		}
363
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
364
		wp_register_style(
365
			'jetpack-jitm-css',
366
			plugins_url( "assets/jetpack-admin-jitm{$min}.css", __DIR__ ),
367
			false,
368
			self::PACKAGE_VERSION .
369
			'-201243242'
370
		);
371
		wp_style_add_data( 'jetpack-jitm-css', 'rtl', 'replace' );
372
		wp_style_add_data( 'jetpack-jitm-css', 'suffix', $min );
373
		wp_enqueue_style( 'jetpack-jitm-css' );
374
375
		wp_enqueue_script(
376
			'jetpack-jitm-new',
377
			Assets::get_file_url_for_environment( '_inc/build/jetpack-jitm.min.js', '_inc/jetpack-jitm.js' ),
378
			array( 'jquery' ),
379
			self::PACKAGE_VERSION,
380
			true
381
		);
382
		wp_localize_script(
383
			'jetpack-jitm-new',
384
			'jitm_config',
385
			array(
386
				'api_root'               => esc_url_raw( rest_url() ),
387
				'activate_module_text'   => esc_html__( 'Activate', 'jetpack' ),
388
				'activated_module_text'  => esc_html__( 'Activated', 'jetpack' ),
389
				'activating_module_text' => esc_html__( 'Activating', 'jetpack' ),
390
			)
391
		);
392
	}
393
394
	/**
395
	 * Dismisses a JITM feature class so that it will no longer be shown.
396
	 *
397
	 * @param string $id The id of the JITM that was dismissed.
398
	 * @param string $feature_class The feature class of the JITM that was dismissed.
399
	 *
400
	 * @return bool Always true.
401
	 */
402
	public function dismiss( $id, $feature_class ) {
403
		$this->tracking->record_user_event(
404
			'jitm_dismiss_client',
405
			array(
406
				'jitm_id'       => $id,
407
				'feature_class' => $feature_class,
408
			)
409
		);
410
411
		$hide_jitm = \Jetpack_Options::get_option( 'hide_jitm' );
412
		if ( ! is_array( $hide_jitm ) ) {
413
			$hide_jitm = array();
414
		}
415
416
		if ( isset( $hide_jitm[ $feature_class ] ) ) {
417
			if ( ! is_array( $hide_jitm[ $feature_class ] ) ) {
418
				$hide_jitm[ $feature_class ] = array(
419
					'last_dismissal' => 0,
420
					'number'         => 0,
421
				);
422
			}
423
		} else {
424
			$hide_jitm[ $feature_class ] = array(
425
				'last_dismissal' => 0,
426
				'number'         => 0,
427
			);
428
		}
429
430
		$number = $hide_jitm[ $feature_class ]['number'];
431
432
		$hide_jitm[ $feature_class ] = array(
433
			'last_dismissal' => time(),
434
			'number'         => $number + 1,
435
		);
436
437
		\Jetpack_Options::update_option( 'hide_jitm', $hide_jitm );
438
439
		return true;
440
	}
441
442
	/**
443
	 * Asks the wpcom API for the current message to display keyed on query string and message path
444
	 *
445
	 * @param string $message_path The message path to ask for.
446
	 * @param string $query The query string originally from the front end.
447
	 *
448
	 * @return array The JITM's to show, or an empty array if there is nothing to show
449
	 */
450
	public function get_messages( $message_path, $query ) {
451
		// Custom filters go here.
452
		add_filter( 'jitm_woocommerce_services_msg', array( $this, 'jitm_woocommerce_services_msg' ) );
453
		add_filter( 'jitm_jetpack_woo_services_install', array( $this, 'jitm_jetpack_woo_services_install' ) );
454
		add_filter( 'jitm_jetpack_woo_services_activate', array( $this, 'jitm_jetpack_woo_services_activate' ) );
455
456
		$user = wp_get_current_user();
457
458
		// Unauthenticated or invalid requests just bail.
459
		if ( ! $user ) {
460
			return array();
461
		}
462
463
		$user_roles = implode( ',', $user->roles );
464
		$site_id    = \Jetpack_Options::get_option( 'id' );
465
466
		// Build our jitm request.
467
		$path = add_query_arg(
468
			array(
469
				'external_user_id' => urlencode_deep( $user->ID ),
470
				'user_roles'       => urlencode_deep( $user_roles ),
471
				'query_string'     => urlencode_deep( $query ),
472
				'mobile_browser'   => jetpack_is_mobile( 'smart' ) ? 1 : 0,
473
				'_locale'          => get_user_locale(),
474
			),
475
			sprintf( '/sites/%d/jitm/%s', $site_id, $message_path )
476
		);
477
478
		// Attempt to get from cache.
479
		$envelopes = get_transient( 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ) );
480
481
		// If something is in the cache and it was put in the cache after the last sync we care about, use it.
482
		$use_cache = false;
483
484
		/** This filter is documented in class.jetpack.php */
485
		if ( apply_filters( 'jetpack_just_in_time_msg_cache', false ) ) {
486
			$use_cache = true;
487
		}
488
489
		if ( $use_cache ) {
490
			$last_sync  = (int) get_transient( 'jetpack_last_plugin_sync' );
491
			$from_cache = $envelopes && $last_sync > 0 && $last_sync < $envelopes['last_response_time'];
492
		} else {
493
			$from_cache = false;
494
		}
495
496
		// Otherwise, ask again.
497
		if ( ! $from_cache ) {
498
			$wpcom_response = Client::wpcom_json_api_request_as_blog(
499
				$path,
500
				'2',
501
				array(
502
					'user_id'    => $user->ID,
503
					'user_roles' => implode( ',', $user->roles ),
504
				),
505
				null,
506
				'wpcom'
507
			);
508
509
			// silently fail...might be helpful to track it?
510
			if ( is_wp_error( $wpcom_response ) ) {
511
				return array();
512
			}
513
514
			$envelopes = json_decode( $wpcom_response['body'] );
515
516
			if ( ! is_array( $envelopes ) ) {
517
				return array();
518
			}
519
520
			$expiration = isset( $envelopes[0] ) ? $envelopes[0]->ttl : 300;
521
522
			// Do not cache if expiration is 0 or we're not using the cache.
523
			if ( 0 !== $expiration && $use_cache ) {
524
				$envelopes['last_response_time'] = time();
525
526
				set_transient( 'jetpack_jitm_' . substr( md5( $path ), 0, 31 ), $envelopes, $expiration );
527
			}
528
		}
529
530
		$hidden_jitms = \Jetpack_Options::get_option( 'hide_jitm' );
531
		unset( $envelopes['last_response_time'] );
532
533
		/**
534
		 * Allow adding your own custom JITMs after a set of JITMs has been received.
535
		 *
536
		 * @since 6.9.0
537
		 *
538
		 * @param array $envelopes array of existing JITMs.
539
		 */
540
		$envelopes = apply_filters( 'jetpack_jitm_received_envelopes', $envelopes );
541
542
		foreach ( $envelopes as $idx => &$envelope ) {
543
544
			$dismissed_feature = isset( $hidden_jitms[ $envelope->feature_class ] ) && is_array( $hidden_jitms[ $envelope->feature_class ] ) ? $hidden_jitms[ $envelope->feature_class ] : null;
545
546
			// If the this feature class has been dismissed and the request has not passed the ttl, skip it as it's been dismissed.
547
			if ( is_array( $dismissed_feature ) && ( time() - $dismissed_feature['last_dismissal'] < $envelope->expires || $dismissed_feature['number'] >= $envelope->max_dismissal ) ) {
548
				unset( $envelopes[ $idx ] );
549
				continue;
550
			}
551
552
			$this->tracking->record_user_event(
553
				'jitm_view_client',
554
				array(
555
					'jitm_id' => $envelope->id,
556
				)
557
			);
558
559
			$normalized_site_url = \Jetpack::build_raw_urls( get_home_url() );
560
561
			$url_params = array(
562
				'source' => "jitm-$envelope->id",
563
				'site'   => $normalized_site_url,
564
				'u'      => $user->ID,
565
			);
566
567
			if ( ! class_exists( 'Jetpack_Affiliate' ) ) {
568
				require_once JETPACK__PLUGIN_DIR . 'class.jetpack-affiliate.php';
569
			}
570
			// Get affiliate code and add it to the array of URL parameters.
571
			$aff = \Jetpack_Affiliate::init()->get_affiliate_code();
572
			if ( '' !== $aff ) {
573
				$url_params['aff'] = $aff;
574
			}
575
576
			$envelope->url = add_query_arg( $url_params, 'https://jetpack.com/redirect/' );
577
578
			$envelope->jitm_stats_url = \Jetpack::build_stats_url( array( 'x_jetpack-jitm' => $envelope->id ) );
579
580
			// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
581
			// $CTA is not valid per PHPCS, but it is part of the return from WordPress.com, so allowing.
582
			if ( $envelope->CTA->hook ) {
583
				$envelope->url = apply_filters( 'jitm_' . $envelope->CTA->hook, $envelope->url );
584
				unset( $envelope->CTA->hook );
585
			}
586
			// phpcs:enable
587
588
			if ( isset( $envelope->content->hook ) ) {
589
				$envelope->content = apply_filters( 'jitm_' . $envelope->content->hook, $envelope->content );
590
				unset( $envelope->content->hook );
591
			}
592
593
			// No point in showing an empty message.
594
			if ( empty( $envelope->content->message ) ) {
595
				unset( $envelopes[ $idx ] );
596
				continue;
597
			}
598
599
			switch ( $envelope->content->icon ) {
600
				case 'jetpack':
601
					$jetpack_logo            = new Jetpack_Logo();
602
					$envelope->content->icon = '<div class="jp-emblem">' . $jetpack_logo->get_jp_emblem() . '</div>';
603
					break;
604
				case 'woocommerce':
605
					$envelope->content->icon = '<div class="jp-emblem"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 168 100" xml:space="preserve" enable-background="new 0 0 168 100" width="50" height="30"><style type="text/css">
606
					.st0{clip-path:url(#SVGID_2_);enable-background:new    ;}
607
					.st1{clip-path:url(#SVGID_4_);}
608
					.st2{clip-path:url(#SVGID_6_);}
609
					.st3{clip-path:url(#SVGID_8_);fill:#8F567F;}
610
					.st4{clip-path:url(#SVGID_10_);fill:#FFFFFE;}
611
					.st5{clip-path:url(#SVGID_12_);fill:#FFFFFE;}
612
					.st6{clip-path:url(#SVGID_14_);fill:#FFFFFE;}
613
				</style><g><defs><polygon id="SVGID_1_" points="83.8 100 0 100 0 0.3 83.8 0.3 167.6 0.3 167.6 100 "/></defs><clipPath id="SVGID_2_"><use xlink:href="#SVGID_1_" overflow="visible"/></clipPath><g class="st0"><g><defs><rect id="SVGID_3_" width="168" height="100"/></defs><clipPath id="SVGID_4_"><use xlink:href="#SVGID_3_" overflow="visible"/></clipPath><g class="st1"><defs><path id="SVGID_5_" d="M15.6 0.3H152c8.6 0 15.6 7 15.6 15.6v52c0 8.6-7 15.6-15.6 15.6h-48.9l6.7 16.4L80.2 83.6H15.6C7 83.6 0 76.6 0 67.9v-52C0 7.3 7 0.3 15.6 0.3"/></defs><clipPath id="SVGID_6_"><use xlink:href="#SVGID_5_" overflow="visible"/></clipPath><g class="st2"><defs><rect id="SVGID_7_" width="168" height="100"/></defs><clipPath id="SVGID_8_"><use xlink:href="#SVGID_7_" overflow="visible"/></clipPath><rect x="-10" y="-9.7" class="st3" width="187.6" height="119.7"/></g></g></g></g></g><g><defs><path id="SVGID_9_" d="M8.4 14.5c1-1.3 2.4-2 4.3-2.1 3.5-0.2 5.5 1.4 6 4.9 2.1 14.3 4.4 26.4 6.9 36.4l15-28.6c1.4-2.6 3.1-3.9 5.2-4.1 3-0.2 4.9 1.7 5.6 5.7 1.7 9.1 3.9 16.9 6.5 23.4 1.8-17.4 4.8-30 9-37.7 1-1.9 2.5-2.9 4.5-3 1.6-0.1 3 0.3 4.3 1.4 1.3 1 2 2.3 2.1 3.9 0.1 1.2-0.1 2.3-0.7 3.3 -2.7 5-4.9 13.2-6.6 24.7 -1.7 11.1-2.3 19.8-1.9 26.1 0.1 1.7-0.1 3.2-0.8 4.5 -0.8 1.5-2 2.4-3.7 2.5 -1.8 0.1-3.6-0.7-5.4-2.5C52.4 66.7 47.4 57 43.7 44.1c-4.4 8.8-7.7 15.3-9.9 19.7 -4 7.7-7.5 11.7-10.3 11.9 -1.9 0.1-3.5-1.4-4.8-4.7 -3.5-9-7.3-26.3-11.3-52C7.1 17.3 7.5 15.8 8.4 14.5"/></defs><clipPath id="SVGID_10_"><use xlink:href="#SVGID_9_" overflow="visible"/></clipPath><rect x="-2.7" y="-0.6" class="st4" width="90.6" height="86.4"/></g><g><defs><path id="SVGID_11_" d="M155.6 25.2c-2.5-4.3-6.1-6.9-11-7.9 -1.3-0.3-2.5-0.4-3.7-0.4 -6.6 0-11.9 3.4-16.1 10.2 -3.6 5.8-5.3 12.3-5.3 19.3 0 5.3 1.1 9.8 3.3 13.6 2.5 4.3 6.1 6.9 11 7.9 1.3 0.3 2.5 0.4 3.7 0.4 6.6 0 12-3.4 16.1-10.2 3.6-5.9 5.3-12.4 5.3-19.4C159 33.4 157.9 28.9 155.6 25.2zM147 44.2c-0.9 4.5-2.7 7.9-5.2 10.1 -2 1.8-3.9 2.5-5.5 2.2 -1.7-0.3-3-1.8-4-4.4 -0.8-2.1-1.2-4.2-1.2-6.2 0-1.7 0.2-3.4 0.5-5 0.6-2.8 1.8-5.5 3.6-8.1 2.3-3.3 4.7-4.8 7.1-4.2 1.7 0.3 3 1.8 4 4.4 0.8 2.1 1.2 4.2 1.2 6.2C147.5 40.9 147.3 42.6 147 44.2z"/></defs><clipPath id="SVGID_12_"><use xlink:href="#SVGID_11_" overflow="visible"/></clipPath><rect x="109.6" y="6.9" class="st5" width="59.4" height="71.4"/></g><g><defs><path id="SVGID_13_" d="M112.7 25.2c-2.5-4.3-6.1-6.9-11-7.9 -1.3-0.3-2.5-0.4-3.7-0.4 -6.6 0-11.9 3.4-16.1 10.2 -3.5 5.8-5.3 12.3-5.3 19.3 0 5.3 1.1 9.8 3.3 13.6 2.5 4.3 6.1 6.9 11 7.9 1.3 0.3 2.5 0.4 3.7 0.4 6.6 0 12-3.4 16.1-10.2 3.5-5.9 5.3-12.4 5.3-19.4C116 33.4 114.9 28.9 112.7 25.2zM104.1 44.2c-0.9 4.5-2.7 7.9-5.2 10.1 -2 1.8-3.9 2.5-5.5 2.2 -1.7-0.3-3-1.8-4-4.4 -0.8-2.1-1.2-4.2-1.2-6.2 0-1.7 0.2-3.4 0.5-5 0.6-2.8 1.8-5.5 3.6-8.1 2.3-3.3 4.7-4.8 7.1-4.2 1.7 0.3 3 1.8 4 4.4 0.8 2.1 1.2 4.2 1.2 6.2C104.6 40.9 104.4 42.6 104.1 44.2z"/></defs><clipPath id="SVGID_14_"><use xlink:href="#SVGID_13_" overflow="visible"/></clipPath><rect x="66.7" y="6.9" class="st6" width="59.4" height="71.4"/></g></svg></div>';
614
					break;
615
				default:
616
					$envelope->content->icon = '';
617
					break;
618
			}
619
620
			$jetpack = \Jetpack::init();
621
			$jetpack->stat( 'jitm', $envelope->id . '-viewed-' . JETPACK__VERSION );
622
			$jetpack->do_stats( 'server_side' );
623
		}
624
625
		return $envelopes;
626
	}
627
628
	/**
629
	 * Is the current page a block editor page?
630
	 *
631
	 * @since 8.0.0
632
	 */
633
	private function is_gutenberg_page() {
634
		$current_screen = get_current_screen();
635
		return ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() );
636
	}
637
}
638