Completed
Push — update/manage-baked-in ( 20f4a0 )
by
unknown
29:39 queued 19:57
created

Jetpack_JITM::manage_pi_msg()   C

Complexity

Conditions 9
Paths 24

Size

Total Lines 62
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 35
nc 24
nop 0
dl 0
loc 62
rs 6.6867
c 0
b 0
f 0

How to fix   Long Method   

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
/**
4
 * Jetpack just in time messaging through out the admin
5
 *
6
 * @since 3.7.0
7
 */
8
class Jetpack_JITM {
9
10
	/**
11
	 * @var Jetpack_JITM
12
	 **/
13
	private static $instance = null;
14
15
	/**
16
	 * Get user dismissed messages.
17
	 *
18
	 * @var array
19
	 */
20
	private static $jetpack_hide_jitm = null;
21
22
	/**
23
	 * Whether plugin auto updates are allowed in this WordPress installation or not.
24
	 *
25
	 * @var bool
26
	 */
27
	private static $auto_updates_allowed = false;
28
29
	static function init() {
30
		if ( is_null( self::$instance ) ) {
31
			self::$instance = new Jetpack_JITM;
32
		}
33
34
		return self::$instance;
35
	}
36
37
	private function __construct() {
38
		if ( ! Jetpack::is_active() || self::is_jitm_dismissed() ) {
39
			return;
40
		}
41
		add_action( 'current_screen', array( $this, 'prepare_jitms' ) );
42
	}
43
44
	function get_emblem()
45
	{
46
		return '<div class="jp-emblem">' . Jetpack::get_jp_emblem() . '</div>';
47
	}
48
49
	/**
50
	 * Prepare actions according to screen and post type.
51
	 *
52
	 * @since 3.8.2
53
	 *
54
	 * @uses Jetpack_Autoupdate::get_possible_failures()
55
	 *
56
	 * @param object $screen
57
	 */
58
	function prepare_jitms( $screen ) {
59
		if ( ! current_user_can( 'jetpack_manage_modules' ) ) {
60
			return;
61
		}
62
63
		if ( 'edit-comments' == $screen->base && ! Jetpack::is_plugin_active( 'akismet/akismet.php' ) ) {
64
			add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
65
			add_action( 'admin_notices', array( $this, 'akismet_msg' ) );
66
		}
67
		elseif (
68
			'post' == $screen->base
69
			&& ( isset( $_GET['message'] ) && 6 == $_GET['message'] )
70
			&& ! Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' )
71
		) {
72
			add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
73
			add_action( 'edit_form_top', array( $this, 'backups_after_publish_msg' ) );
74
		}
75
		elseif ( 'update-core' == $screen->base && ! Jetpack::is_plugin_active( 'vaultpress/vaultpress.php' ) ) {
76
			add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
77
			add_action( 'admin_notices', array( $this, 'backups_updates_msg' ) );
78
		}
79
		elseif ( ! Jetpack::is_plugin_active( 'woocommerce-services/woocommerce-services.php' ) ) {
80
			 $pages_to_display = array(
81
				 'woocommerce_page_wc-settings', // WooCommerce > Settings
82
				 'edit-shop_order', // WooCommerce > Orders
83
				 'shop_order', // WooCommerce > Edit Order
84
			 );
85
86
			if ( in_array( $screen->id, $pages_to_display ) ) {
87
				add_action( 'admin_enqueue_scripts', array( $this, 'jitm_enqueue_files' ) );
88
				add_action( 'admin_notices', array( $this, 'woocommerce_services_msg' ) );
89
			}
90
		}
91
	}
92
93
	/*
94
	 * Present Manage just in time activation msg on update-core.php
95
	 *
96
	 */
97
	function manage_msg() {
98
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
99
		?>
100
		<div class="jp-jitm">
101
			<a href="#" data-module="manage" class="dismiss"><span class="genericon genericon-close"></span></a>
102
103
			<?php echo self::get_emblem(); ?>
104
105
			<p class="msg">
106
				<?php esc_html_e( 'Reduce security risks with automated plugin updates.', 'jetpack' ); ?>
107
			</p>
108
109
			<p>
110
				<img class="j-spinner hide" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="<?php echo esc_attr__( 'Loading...', 'jetpack' ); ?>" />
111
				<a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com to try these features', 'jetpack' ); ?>" id="jetpack-wordpressdotcom" class="button button-jetpack">
112
					<?php esc_html_e( 'Go to WordPress.com', 'jetpack' ); ?>
113
				</a>
114
			</p>
115
		</div>
116
		<?php
117
		//jitm is being viewed, track it
118
		$jetpack = Jetpack::init();
119
		$jetpack->stat( 'jitm', 'manage-viewed-' . JETPACK__VERSION );
120
		$jetpack->do_stats( 'server_side' );
121
	}
122
123
	/*
124
	 * Present Photon just in time activation msg
125
	 *
126
	 */
127
	function photon_msg() {
128
		?>
129
		<div class="jp-jitm">
130
			<a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a>
131
132
			<?php echo self::get_emblem(); ?>
133
134
			<p class="msg">
135
				<?php esc_html_e( 'Speed up your photos and save bandwidth costs by using a free content delivery network.', 'jetpack' ); ?>
136
			</p>
137
138
			<p>
139
				<img class="j-spinner hide" style="margin-top: 13px;" width="17" height="17" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="<?php echo esc_attr__( 'Loading...', 'jetpack' ); ?>" /><a href="#" data-module="photon" class="activate button button-jetpack"><?php esc_html_e( 'Activate Photon', 'jetpack' ); ?></a>
140
			</p>
141
		</div>
142
		<?php
143
		//jitm is being viewed, track it
144
		$jetpack = Jetpack::init();
145
		$jetpack->stat( 'jitm', 'photon-viewed-' . JETPACK__VERSION );
146
		$jetpack->do_stats( 'server_side' );
147
	}
148
149
	/**
150
	 * Display Photon JITM template in Media Library after user uploads an image.
151
	 *
152
	 * @since 3.9.0
153
	 */
154
	function photon_tmpl() {
155
		?>
156
		<script id="tmpl-jitm-photon" type="text/html">
157
			<div class="jp-jitm" data-track="photon-modal">
158
				<a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a>
159
160
				<?php echo self::get_emblem(); ?>
161
162
				<p class="msg">
163
					<?php esc_html_e( 'Let Jetpack deliver your images optimized and faster than ever.', 'jetpack' ); ?>
164
				</p>
165
166
				<p>
167
					<img class="j-spinner hide" style="margin-top: 13px;" width="17" height="17" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="<?php echo esc_attr__( 'Loading...', 'jetpack' ); ?>" /><a href="#" data-module="photon" class="activate button button-jetpack"><?php esc_html_e( 'Activate Photon', 'jetpack' ); ?></a>
168
				</p>
169
			</div>
170
		</script>
171
		<?php
172
	}
173
174
	/**
175
	 * Display message prompting user to enable auto-updates in WordPress.com.
176
	 *
177
	 * @since 3.8.2
178
	 */
179
	function manage_pi_msg() {
180
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
181
182
		// Check if plugin has auto update already enabled in WordPress.com and don't show JITM in such case.
183
		$active_before = get_option( 'jetpack_temp_active_plugins_before', array() );
184
		delete_option( 'jetpack_temp_active_plugins_before' );
185
		$active_now                  = get_option( 'active_plugins', array() );
186
		$activated                   = array_diff( $active_now, $active_before );
187
		$auto_update_plugin_list     = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
188
		$plugin_auto_update_disabled = false;
189
		foreach ( $activated as $plugin ) {
190
			if ( ! in_array( $plugin, $auto_update_plugin_list ) ) {
191
192
				// Plugin doesn't have auto updates enabled in WordPress.com yet.
193
				$plugin_auto_update_disabled = true;
194
195
				// We don't need to continue checking, it's ok to show JITM for this plugin.
196
				break;
197
			}
198
		}
199
200
		// Check if the activated plugin is in the WordPress.org repository
201
		$plugin_can_auto_update = false;
202
		$plugin_updates 		= get_site_transient( 'update_plugins' );
203
		if ( false === $plugin_updates ) {
204
205
			// If update_plugins doesn't exist, display message anyway
206
			$plugin_can_auto_update = true;
207
		} else {
208
			$plugin_updates = array_merge( $plugin_updates->response, $plugin_updates->no_update );
209
			foreach ( $activated as $plugin ) {
210
				if ( isset( $plugin_updates[ $plugin ] ) ) {
211
212
					// There's at least one plugin set cleared for auto updates
213
					$plugin_can_auto_update = true;
214
215
					// We don't need to continue checking, it's ok to show JITM for this round.
216
					break;
217
				}
218
			}
219
		}
220
221
		if ( $plugin_auto_update_disabled && $plugin_can_auto_update && self::$auto_updates_allowed ) :
222
			?>
223
			<div class="jp-jitm">
224
				<a href="#" data-module="manage-pi" class="dismiss"><span class="genericon genericon-close"></span></a>
225
226
			<?php echo self::get_emblem(); ?>
227
				<p>
228
					<?php esc_html_e( 'Save time with auto updates on WordPress.com', 'jetpack' ); ?>
229
				</p>
230
				<p class="show-after-enable">
231
					<a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com to enable auto-updates for plugins', 'jetpack' ); ?>" data-module="manage-pi" class="button button-jetpack launch show-after-enable"><?php esc_html_e( 'Enable auto-updates', 'jetpack' ); ?></a>
232
				</p>
233
			</div>
234
			<?php
235
			//jitm is being viewed, track it
236
			$jetpack = Jetpack::init();
237
			$jetpack->stat( 'jitm', 'manage-pi-viewed-' . JETPACK__VERSION );
238
			$jetpack->do_stats( 'server_side' );
239
		endif; // manage inactive
240
	}
241
242
	/**
243
	 * Display message in editor prompting user to compose entry in WordPress.com.
244
	 *
245
	 * @since 3.8.2
246
	 */
247
	function editor_msg() {
248
		global $typenow;
249
		if ( current_user_can( 'manage_options' ) ) {
250
			$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
251
			$editor_dismissed = isset( self::$jetpack_hide_jitm['editor'] );
252
			if ( ! $editor_dismissed ) :
253
			?>
254
			<div class="jp-jitm">
255
				<a href="#"  data-module="editor" class="dismiss"><span class="genericon genericon-close"></span></a>
256
				<?php echo self::get_emblem(); ?>
257
				<p class="msg">
258
					<?php esc_html_e( 'Try the brand new editor.', 'jetpack' ); ?>
259
				</p>
260
				<p>
261
					<a href="<?php echo esc_url( 'https://wordpress.com/' . $typenow . '/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Write on WordPress.com', 'jetpack' ); ?>" data-module="editor" class="button button-jetpack launch show-after-enable"><?php esc_html_e( 'Write on WordPress.com', 'jetpack' ); ?></a>
262
				</p>
263
			</div>
264
			<?php
265
			//jitm is being viewed, track it
266
			$jetpack = Jetpack::init();
267
			$jetpack->stat( 'jitm', 'editor-viewed-' . JETPACK__VERSION );
268
			$jetpack->do_stats( 'server_side' );
269
			endif; // manage or editor inactive
270
		}
271
	}
272
273
	/**
274
	 * Display message in editor prompting user to enable stats.
275
	 *
276
	 * @since 3.9.0
277
	 */
278
	function stats_msg() {
279
		$stats_active        = Jetpack::is_module_active( 'stats' );
280
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
281
		?>
282
		<div class="jp-jitm">
283
			<a href="#" data-module="stats" class="dismiss"><span class="genericon genericon-close"></span></a>
284
			<?php echo self::get_emblem(); ?>
285
			<p class="msg">
286
				<?php esc_html_e( 'Track detailed stats on this post and the rest of your site.', 'jetpack' ); ?>
287
			</p>
288
			<?php if ( ! $stats_active ) : ?>
289
				<p>
290
					<img class="j-spinner hide" src="<?php echo esc_url( includes_url( 'images/spinner-2x.gif' ) ); ?>" alt="<?php echo esc_attr__( 'Loading...', 'jetpack' ); ?>" /><a href="#" data-module="stats" data-module-success="<?php esc_attr_e( 'Success! Jetpack Stats is now activated.', 'jetpack' ); ?>" class="activate button"><?php esc_html_e( 'Enable Jetpack Stats', 'jetpack' ); ?></a>
291
				</p>
292
			<?php endif; // stats inactive
293
			?>
294
			<p class="show-after-enable <?php echo $stats_active ? '' : 'hide'; ?>">
295
				<a href="<?php echo esc_url( 'https://wordpress.com/stats/insights/' . $normalized_site_url ); ?>" target="_blank" title="<?php esc_attr_e( 'Go to WordPress.com', 'jetpack' ); ?>" data-module="stats" class="button button-jetpack launch show-after-enable"><?php esc_html_e( 'Go to WordPress.com', 'jetpack' ); ?></a>
296
			</p>
297
		</div>
298
		<?php
299
		//jitm is being viewed, track it
300
		$jetpack = Jetpack::init();
301
		$jetpack->stat( 'jitm', 'post-stats-viewed-' . JETPACK__VERSION );
302
		$jetpack->do_stats( 'server_side' );
303
	}
304
305
	/**
306
	 * Display JITM in Updates screen prompting user to enable Backups.
307
	 *
308
	 * @since 3.9.5
309
	 */
310 View Code Duplication
	function backups_updates_msg() {
311
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
312
		$url = 'https://jetpack.com/redirect/?source=jitm-backup-updates&site=' . $normalized_site_url;
313
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'vaultpress' ) );
314
		?>
315
		<div class="jp-jitm" data-track="vaultpress-updates" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
316
			<a href="#" data-module="vaultpress" class="dismiss"><span class="genericon genericon-close"></span></a>
317
			<?php echo self::get_emblem(); ?>
318
			<p class="msg">
319
				<?php esc_html_e( 'Backups are recommended to protect your site before you make any changes.', 'jetpack' ); ?>
320
			</p>
321
			<p>
322
				<a href="<?php echo esc_url( $url ); ?>" target="_blank" title="<?php esc_attr_e( 'Enable VaultPress Backups', 'jetpack' ); ?>" data-module="vaultpress" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-vault" class="button button-jetpack launch jptracks"><?php esc_html_e( 'Enable VaultPress Backups', 'jetpack' ); ?></a>
323
			</p>
324
		</div>
325
		<?php
326
		//jitm is being viewed, track it
327
		$jetpack = Jetpack::init();
328
		$jetpack->stat( 'jitm', 'vaultpress-updates-viewed-' . JETPACK__VERSION );
329
		$jetpack->do_stats( 'server_side' );
330
	}
331
332
	/**
333
	 * Display JITM in Comments screen prompting user to enable Akismet.
334
	 *
335
	 * @since 3.9.5
336
	 */
337 View Code Duplication
	function akismet_msg() {
338
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
339
		$url = 'https://jetpack.com/redirect/?source=jitm-akismet&site=' . $normalized_site_url;
340
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'akismet' ) );
341
		?>
342
		<div class="jp-jitm" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
343
			<a href="#" data-module="akismet" class="dismiss"><span class="genericon genericon-close"></span></a>
344
			<?php echo self::get_emblem(); ?>
345
			<p class="msg">
346
				<?php esc_html_e( "Spam affects your site's legitimacy, protect your site with Akismet.", 'jetpack' ); ?>
347
			</p>
348
			<p>
349
				<a href="<?php echo esc_url( $url ); ?>" target="_blank" title="<?php esc_attr_e( 'Automate Spam Blocking', 'jetpack' ); ?>" data-module="akismet" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-akismet" class="button button-jetpack launch jptracks"><?php esc_html_e( 'Automate Spam Blocking', 'jetpack' ); ?></a>
350
			</p>
351
		</div>
352
		<?php
353
		//jitm is being viewed, track it
354
		$jetpack = Jetpack::init();
355
		$jetpack->stat( 'jitm', 'akismet-viewed-' . JETPACK__VERSION );
356
		$jetpack->do_stats( 'server_side' );
357
	}
358
359
	/**
360
	 * Display JITM after a post is published prompting user to enable Backups.
361
	 *
362
	 * @since 3.9.5
363
	 */
364 View Code Duplication
	function backups_after_publish_msg() {
365
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
366
		$url = 'https://jetpack.com/redirect/?source=jitm-backup-publish&site=' . $normalized_site_url;
367
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'vaultpress' ) );
368
		?>
369
		<div class="jp-jitm" data-track="vaultpress-publish" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
370
			<a href="#" data-module="vaultpress" class="dismiss"><span class="genericon genericon-close"></span></a>
371
372
			<?php echo self::get_emblem(); ?>
373
374
			<p class="msg">
375
				<?php esc_html_e( "Great job! Now let's make sure your hard work is never lost, backup everything with VaultPress.", 'jetpack' ); ?>
376
			</p>
377
			<p>
378
				<a href="<?php echo esc_url( $url ); ?>" target="_blank" title="<?php esc_attr_e( 'Enable Backups', 'jetpack' ); ?>" data-module="vaultpress" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-vault-post" class="button button-jetpack launch jptracks"><?php esc_html_e( 'Enable Backups', 'jetpack' ); ?></a>
379
			</p>
380
		</div>
381
		<?php
382
		//jitm is being viewed, track it
383
		$jetpack = Jetpack::init();
384
		$jetpack->stat( 'jitm', 'vaultpress-publish-viewed-' . JETPACK__VERSION );
385
		$jetpack->do_stats( 'server_side' );
386
	}
387
388
	/**
389
	 * Display a JITM style message for the media-new page.
390
	 *
391
	 * @since 4.5
392
	 */
393
	function videopress_media_upload_warning_msg() {
394
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'videopress' ) );
395
396
		$upload_url   = add_query_arg( 'mode', 'grid', admin_url( 'upload.php' ) );
397
		$new_post_url = admin_url( 'post-new.php' );
398
399
		$msg = sprintf( __( 'Only videos uploaded from within the <a href="%s">media library</a> or while creating a <a href="%s">new post</a> will be fully hosted by WordPress.com.', 'jetpack' ), esc_url( $upload_url ), esc_url( $new_post_url ) );
400
		?>
401
        <div class="jp-jitm" data-track="videopress-upload-warning" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
402
            <!-- <a href="#" data-module="videopress" class="dismiss"><span class="genericon genericon-close"></span></a>-->
403
404
			<?php echo self::get_emblem(); ?>
405
406
            <p class="msg">
407
				<?php echo $msg; ?>
408
            </p>
409
            <p>
410
                <a href="<?php echo esc_url( $upload_url ); ?>" title="<?php esc_attr_e( 'Upload a Video', 'jetpack' ); ?>" data-module="videopress" data-jptracks-name="nudge_click" data-jptracks-prop="jitm-videopress-upload" class="button button-jetpack launch jptracks"><?php esc_html_e( 'Upload a Video Now', 'jetpack' ); ?></a>
411
            </p>
412
        </div>
413
		<?php
414
	}
415
416
	/**
417
	 * Display message prompting user to install WooCommerce Services.
418
	 *
419
	 * @since 4.6
420
	 */
421
	function woocommerce_services_msg() {
422
		if ( ! current_user_can( 'manage_woocommerce' ) || ! current_user_can( 'install_plugins' ) ) {
423
			return;
424
		}
425
426
		if ( isset( self::$jetpack_hide_jitm['woocommerce_services'] ) ) {
427
			return;
428
		}
429
430
		if ( ! function_exists( 'wc_get_base_location' ) ) {
431
			return;
432
		}
433
434
		$base_location = wc_get_base_location();
435
436
		switch ( $base_location['country'] ) {
437
			case 'US':
438
				$message = __( 'New free service: Show USPS shipping rates on your store! Added bonus: print shipping labels without leaving WooCommerce.', 'jetpack' );
439
				break;
440
			case 'CA':
441
				$message = __( 'New free service: Show Canada Post shipping rates on your store!', 'jetpack' );
442
				break;
443
			default:
444
				return;
445
		}
446
447
		// If plugin dir exists, means it's installed but not activated
448
		$already_installed = ( 0 === validate_plugin( 'woocommerce-services/woocommerce-services.php' ) );
449
450
		$install_url = wp_nonce_url( add_query_arg( array( 'wc-services-action' => $already_installed ? 'activate' : 'install' ) ), 'wc-services-install' );
451
452
		?>
453
		<div class="jp-jitm woo-jitm">
454
			<a href="#"  data-module="wooservices" class="dismiss"><span class="genericon genericon-close"></span></a>
455
			<div class="jp-emblem">
456
				<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0" y="0" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
457
					<path d="M18,8h-2V7c0-1.105-0.895-2-2-2H4C2.895,5,2,5.895,2,7v10h2c0,1.657,1.343,3,3,3s3-1.343,3-3h4c0,1.657,1.343,3,3,3s3-1.343,3-3h2v-5L18,8z M7,18.5c-0.828,0-1.5-0.672-1.5-1.5s0.672-1.5,1.5-1.5s1.5,0.672,1.5,1.5S7.828,18.5,7,18.5z M4,14V7h10v7H4z M17,18.5c-0.828,0-1.5-0.672-1.5-1.5s0.672-1.5,1.5-1.5s1.5,0.672,1.5,1.5S17.828,18.5,17,18.5z" />
458
				</svg>
459
			</div>
460
			<p class="msg">
461
				<?php echo esc_html( $message ); ?>
462
			</p>
463
			<p>
464
				<a href="<?php echo esc_url( $install_url ); ?>" title="<?php $already_installed ? esc_attr_e( 'Activate WooCommerce Services', 'jetpack' ) : esc_attr_e( 'Install WooCommerce Services', 'jetpack' ); ?>" data-module="wooservices" class="button button-jetpack show-after-enable">
465
					<?php $already_installed ? esc_html_e( 'Activate WooCommerce Services', 'jetpack' ) : esc_html_e( 'Install WooCommerce Services', 'jetpack' ); ?>
466
				</a>
467
			</p>
468
		</div>
469
		<?php
470
		//jitm is being viewed, track it
471
		$jetpack = Jetpack::init();
472
		$jetpack->stat( 'jitm', 'wooservices-viewed-' . JETPACK__VERSION );
473
	}
474
475
	/*
476
	* Function to enqueue jitm css and js
477
	*/
478
	function jitm_enqueue_files( $hook ) {
479
480
		$wp_styles = new WP_Styles();
481
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
482
		wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' );
483
		$wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true );
484
485
		//Build stats url for tracking manage button
486
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) );
487
488
		// Enqueue javascript to handle jitm notice events
489
		wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ),
490
			array( 'jquery' ), JETPACK__VERSION, true );
491
		wp_localize_script(
492
			'jetpack-jitm-js',
493
			'jitmL10n',
494
			array(
495
				'ajaxurl'     => admin_url( 'admin-ajax.php' ),
496
				'jitm_nonce'  => wp_create_nonce( 'jetpack-jitm-nonce' ),
497
				'photon_msgs' => array(
498
					'success' => esc_html__( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ),
499
					'fail'    => esc_html__( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' )
500
				),
501
				'manage_msgs' => array(
502
					'success' => esc_html__( 'Success! WordPress.com tools are now active.', 'jetpack' ),
503
					'fail'    => esc_html__( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' )
504
				),
505
				'stats_msgs' => array(
506
					'success' => esc_html__( 'Success! Stats are now active.', 'jetpack' ),
507
					'fail'    => esc_html__( 'We are sorry but unfortunately Stats did not activate.', 'jetpack' )
508
				),
509
				'jitm_stats_url' => $jitm_stats_url
510
			)
511
		);
512
	}
513
514
	/**
515
	 * Check if a JITM was dismissed or not. Currently, dismissing one JITM will dismiss all of them.
516
	 *
517
	 * @since 3.8.2
518
	 *
519
	 * @return bool
520
	 */
521
	function is_jitm_dismissed() {
522
		if ( empty( self::$jetpack_hide_jitm ) ) {
523
524
			// The option returns false when nothing was dismissed
525
			self::$jetpack_hide_jitm = Jetpack_Options::get_option( 'hide_jitm' );
0 ignored issues
show
Documentation Bug introduced by
It seems like \Jetpack_Options::get_option('hide_jitm') of type * is incompatible with the declared type array of property $jetpack_hide_jitm.

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...
526
		}
527
528
		// so if it's not an array, it means no JITM was dismissed
529
		return is_array( self::$jetpack_hide_jitm );
530
	}
531
}
532
if (
533
	/**
534
	 * Filter to turn off all just in time messages
535
	 *
536
	 * @since 3.7.0
537
	 *
538
	 * @param bool true Whether to show just in time messages.
539
	 */
540
	apply_filters( 'jetpack_just_in_time_msgs', false )
541
) {
542
	Jetpack_JITM::init();
543
}
544