Completed
Push — enhance/new-jitm-styles ( 637132...9ecf09 )
by
unknown
08:21
created

Jetpack_JITM::backups_updates_msg()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 15

Duplication

Lines 21
Ratio 56.76 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 21
loc 37
rs 8.8571
c 0
b 0
f 0
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' ); ?>" /><a href="#" data-module="manage" class="activate button <?php if ( Jetpack::is_module_active( 'manage' ) ) {
111
					echo 'hide';
112
				} ?>"><?php esc_html_e( 'Activate Now', 'jetpack' ); ?></a><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 <?php if ( ! Jetpack::is_module_active( 'manage' ) ) {
113
					echo 'hide';
114
				} ?>"><?php esc_html_e( 'Go to WordPress.com', 'jetpack' ); ?></a>
115
			</p>
116
		</div>
117
		<?php
118
		//jitm is being viewed, track it
119
		$jetpack = Jetpack::init();
120
		$jetpack->stat( 'jitm', 'manage-viewed-' . JETPACK__VERSION );
121
		$jetpack->do_stats( 'server_side' );
122
	}
123
124
	/*
125
	 * Present Photon just in time activation msg
126
	 *
127
	 */
128
	function photon_msg() {
129
		?>
130
		<div class="jp-jitm">
131
			<a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a>
132
133
			<?php echo self::get_emblem(); ?>
134
135
			<p class="msg">
136
				<?php esc_html_e( 'Speed up your photos and save bandwidth costs by using a free content delivery network.', 'jetpack' ); ?>
137
			</p>
138
139
			<p>
140
				<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>
141
			</p>
142
		</div>
143
		<?php
144
		//jitm is being viewed, track it
145
		$jetpack = Jetpack::init();
146
		$jetpack->stat( 'jitm', 'photon-viewed-' . JETPACK__VERSION );
147
		$jetpack->do_stats( 'server_side' );
148
	}
149
150
	/**
151
	 * Display Photon JITM template in Media Library after user uploads an image.
152
	 *
153
	 * @since 3.9.0
154
	 */
155
	function photon_tmpl() {
156
		?>
157
		<script id="tmpl-jitm-photon" type="text/html">
158
			<div class="jp-jitm" data-track="photon-modal">
159
				<a href="#" data-module="photon" class="dismiss"><span class="genericon genericon-close"></span></a>
160
161
				<?php echo self::get_emblem(); ?>
162
163
				<p class="msg">
164
					<?php esc_html_e( 'Let Jetpack deliver your images optimized and faster than ever.', 'jetpack' ); ?>
165
				</p>
166
167
				<p>
168
					<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>
169
				</p>
170
			</div>
171
		</script>
172
		<?php
173
	}
174
175
	/**
176
	 * Display message prompting user to enable auto-updates in WordPress.com.
177
	 *
178
	 * @since 3.8.2
179
	 */
180
	function manage_pi_msg() {
181
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
182
		$manage_active       = Jetpack::is_module_active( 'manage' );
183
184
		// Check if plugin has auto update already enabled in WordPress.com and don't show JITM in such case.
185
		$active_before = get_option( 'jetpack_temp_active_plugins_before', array() );
186
		delete_option( 'jetpack_temp_active_plugins_before' );
187
		$active_now                  = get_option( 'active_plugins', array() );
188
		$activated                   = array_diff( $active_now, $active_before );
189
		$auto_update_plugin_list     = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
190
		$plugin_auto_update_disabled = false;
191
		foreach ( $activated as $plugin ) {
192
			if ( ! in_array( $plugin, $auto_update_plugin_list ) ) {
193
194
				// Plugin doesn't have auto updates enabled in WordPress.com yet.
195
				$plugin_auto_update_disabled = true;
196
197
				// We don't need to continue checking, it's ok to show JITM for this plugin.
198
				break;
199
			}
200
		}
201
202
		// Check if the activated plugin is in the WordPress.org repository
203
		$plugin_can_auto_update = false;
204
		$plugin_updates 		= get_site_transient( 'update_plugins' );
205
		if ( false === $plugin_updates ) {
206
207
			// If update_plugins doesn't exist, display message anyway
208
			$plugin_can_auto_update = true;
209
		} else {
210
			$plugin_updates = array_merge( $plugin_updates->response, $plugin_updates->no_update );
211
			foreach ( $activated as $plugin ) {
212
				if ( isset( $plugin_updates[ $plugin ] ) ) {
213
214
					// There's at least one plugin set cleared for auto updates
215
					$plugin_can_auto_update = true;
216
217
					// We don't need to continue checking, it's ok to show JITM for this round.
218
					break;
219
				}
220
			}
221
		}
222
223
		if ( ! $manage_active && $plugin_auto_update_disabled && $plugin_can_auto_update && self::$auto_updates_allowed ) :
224
			?>
225
			<div class="jp-jitm">
226
				<a href="#" data-module="manage-pi" class="dismiss"><span class="genericon genericon-close"></span></a>
227
228
			<?php echo self::get_emblem(); ?>
229
230
				<?php if ( ! $manage_active ) : ?>
231
					<p class="msg">
232
						<?php esc_html_e( 'Save time with automated plugin updates.', 'jetpack' ); ?>
233
					</p>
234
					<p>
235
						<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="manage" data-module-success="<?php esc_attr_e( 'Success!', 'jetpack' ); ?>" class="activate button"><?php esc_html_e( 'Activate remote management', 'jetpack' ); ?></a>
236
					</p>
237
				<?php elseif ( $manage_active ) : ?>
238
					<p>
239
						<?php esc_html_e( 'Save time with auto updates on WordPress.com', 'jetpack' ); ?>
240
					</p>
241
				<?php endif; // manage inactive
242
				?>
243
				<p class="show-after-enable <?php echo $manage_active ? '' : 'hide'; ?>">
244
					<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 if ( ! $manage_active ) : ?><?php esc_html_e( 'Enable auto-updates on WordPress.com', 'jetpack' ); ?><?php elseif ( $manage_active ) : ?><?php esc_html_e( 'Enable auto-updates', 'jetpack' ); ?><?php endif; // manage inactive ?></a>
245
				</p>
246
			</div>
247
			<?php
248
			//jitm is being viewed, track it
249
			$jetpack = Jetpack::init();
250
			$jetpack->stat( 'jitm', 'manage-pi-viewed-' . JETPACK__VERSION );
251
			$jetpack->do_stats( 'server_side' );
252
		endif; // manage inactive
253
	}
254
255
	/**
256
	 * Display message in editor prompting user to compose entry in WordPress.com.
257
	 *
258
	 * @since 3.8.2
259
	 */
260
	function editor_msg() {
261
		global $typenow;
262
		if ( current_user_can( 'manage_options' ) ) {
263
			$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
264
			$editor_dismissed = isset( self::$jetpack_hide_jitm['editor'] );
265
			if ( ! $editor_dismissed ) :
266
			?>
267
			<div class="jp-jitm">
268
				<a href="#"  data-module="editor" class="dismiss"><span class="genericon genericon-close"></span></a>
269
				<?php echo self::get_emblem(); ?>
270
				<p class="msg">
271
					<?php esc_html_e( 'Try the brand new editor.', 'jetpack' ); ?>
272
				</p>
273
				<p>
274
					<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>
275
				</p>
276
			</div>
277
			<?php
278
			//jitm is being viewed, track it
279
			$jetpack = Jetpack::init();
280
			$jetpack->stat( 'jitm', 'editor-viewed-' . JETPACK__VERSION );
281
			$jetpack->do_stats( 'server_side' );
282
			endif; // manage or editor inactive
283
		}
284
	}
285
286
	/**
287
	 * Display message in editor prompting user to enable stats.
288
	 *
289
	 * @since 3.9.0
290
	 */
291
	function stats_msg() {
292
		$stats_active        = Jetpack::is_module_active( 'stats' );
293
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
294
		?>
295
		<div class="jp-jitm">
296
			<a href="#" data-module="stats" class="dismiss"><span class="genericon genericon-close"></span></a>
297
			<?php echo self::get_emblem(); ?>
298
			<p class="msg">
299
				<?php esc_html_e( 'Track detailed stats on this post and the rest of your site.', 'jetpack' ); ?>
300
			</p>
301
			<?php if ( ! $stats_active ) : ?>
302
				<p>
303
					<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>
304
				</p>
305
			<?php endif; // stats inactive
306
			?>
307
			<p class="show-after-enable <?php echo $stats_active ? '' : 'hide'; ?>">
308
				<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>
309
			</p>
310
		</div>
311
		<?php
312
		//jitm is being viewed, track it
313
		$jetpack = Jetpack::init();
314
		$jetpack->stat( 'jitm', 'post-stats-viewed-' . JETPACK__VERSION );
315
		$jetpack->do_stats( 'server_side' );
316
	}
317
318
	/**
319
	 * Display JITM in Updates screen prompting user to enable Backups.
320
	 *
321
	 * @since 3.9.5
322
	 */
323 View Code Duplication
	function backups_updates_msg() {
324
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
325
		$url = 'https://jetpack.com/redirect/?source=jitm-backup-updates&site=' . $normalized_site_url;
326
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'vaultpress' ) );
327
		?>
328
		<div class="jp-jitm" data-track="vaultpress-updates" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
329
			<a href="#" data-module="vaultpress" class="dismiss"><span class="genericon genericon-close"></span></a>
330
			<?php echo self::get_emblem(); ?>
331
			<p class="msg">
332
				<?php esc_html_e( 'Backups are recommended to protect your site before you make any changes.', 'jetpack' ); ?>
333
			</p>
334
			<p>
335
				<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>
336
			</p>
337
		</div>
338
339
		<div class="jitm-card dops-banner has-call-to-action is-upgrade-premium">
340
			<div class="dops-banner__icon-plan">
341
342
			</div>
343
			<div class="dops-banner__content">
344
				<div class="dops-banner__info">
345
					<div class="dops-banner__title">Testing the new JITM styles.</div>
346
				</div>
347
				<div class="dops-banner__action">
348
					<a href="https://jetpack.com/redirect/?source=settings-video-premium&amp;site=golenskijetpack.mystagingwebsite.com" type="button" class="dops-button is-compact is-primary">Upgrade</a>
349
				</div>
350
			</div>
351
		</div>
352
353
354
		<?php
355
		//jitm is being viewed, track it
356
		$jetpack = Jetpack::init();
357
		$jetpack->stat( 'jitm', 'vaultpress-updates-viewed-' . JETPACK__VERSION );
358
		$jetpack->do_stats( 'server_side' );
359
	}
360
361
	/**
362
	 * Display JITM in Comments screen prompting user to enable Akismet.
363
	 *
364
	 * @since 3.9.5
365
	 */
366 View Code Duplication
	function akismet_msg() {
367
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
368
		$url = 'https://jetpack.com/redirect/?source=jitm-akismet&site=' . $normalized_site_url;
369
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'akismet' ) );
370
		?>
371
		<div class="jp-jitm" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
372
			<a href="#" data-module="akismet" class="dismiss"><span class="genericon genericon-close"></span></a>
373
			<?php echo self::get_emblem(); ?>
374
			<p class="msg">
375
				<?php esc_html_e( "Spam affects your site's legitimacy, protect your site with Akismet.", 'jetpack' ); ?>
376
			</p>
377
			<p>
378
				<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>
379
			</p>
380
		</div>
381
		<?php
382
		//jitm is being viewed, track it
383
		$jetpack = Jetpack::init();
384
		$jetpack->stat( 'jitm', 'akismet-viewed-' . JETPACK__VERSION );
385
		$jetpack->do_stats( 'server_side' );
386
	}
387
388
	/**
389
	 * Display JITM after a post is published prompting user to enable Backups.
390
	 *
391
	 * @since 3.9.5
392
	 */
393 View Code Duplication
	function backups_after_publish_msg() {
394
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
395
		$url = 'https://jetpack.com/redirect/?source=jitm-backup-publish&site=' . $normalized_site_url;
396
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'vaultpress' ) );
397
		?>
398
		<div class="jp-jitm" data-track="vaultpress-publish" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
399
			<a href="#" data-module="vaultpress" class="dismiss"><span class="genericon genericon-close"></span></a>
400
401
			<?php echo self::get_emblem(); ?>
402
403
			<p class="msg">
404
				<?php esc_html_e( "Great job! Now let's make sure your hard work is never lost, backup everything with VaultPress.", 'jetpack' ); ?>
405
			</p>
406
			<p>
407
				<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>
408
			</p>
409
		</div>
410
		<?php
411
		//jitm is being viewed, track it
412
		$jetpack = Jetpack::init();
413
		$jetpack->stat( 'jitm', 'vaultpress-publish-viewed-' . JETPACK__VERSION );
414
		$jetpack->do_stats( 'server_side' );
415
	}
416
417
	/**
418
	 * Display a JITM style message for the media-new page.
419
	 *
420
	 * @since 4.5
421
	 */
422
	function videopress_media_upload_warning_msg() {
423
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'videopress' ) );
424
425
		$upload_url   = add_query_arg( 'mode', 'grid', admin_url( 'upload.php' ) );
426
		$new_post_url = admin_url( 'post-new.php' );
427
428
		$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 ) );
429
		?>
430
        <div class="jp-jitm" data-track="videopress-upload-warning" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
431
            <!-- <a href="#" data-module="videopress" class="dismiss"><span class="genericon genericon-close"></span></a>-->
432
433
			<?php echo self::get_emblem(); ?>
434
435
            <p class="msg">
436
				<?php echo $msg; ?>
437
            </p>
438
            <p>
439
                <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>
440
            </p>
441
        </div>
442
		<?php
443
	}
444
445
	/**
446
	 * Display message prompting user to install WooCommerce Services.
447
	 *
448
	 * @since 4.6
449
	 */
450
	function woocommerce_services_msg() {
451
		if ( ! current_user_can( 'manage_woocommerce' ) || ! current_user_can( 'install_plugins' ) ) {
452
			return;
453
		}
454
455
		if ( isset( self::$jetpack_hide_jitm['woocommerce_services'] ) ) {
456
			return;
457
		}
458
459
		if ( ! function_exists( 'wc_get_base_location' ) ) {
460
			return;
461
		}
462
463
		$base_location = wc_get_base_location();
464
465
		switch ( $base_location['country'] ) {
466
			case 'US':
467
				$message = __( 'New free service: Show USPS shipping rates on your store! Added bonus: print shipping labels without leaving WooCommerce.', 'jetpack' );
468
				break;
469
			case 'CA':
470
				$message = __( 'New free service: Show Canada Post shipping rates on your store!', 'jetpack' );
471
				break;
472
			default:
473
				return;
474
		}
475
476
		// If plugin dir exists, means it's installed but not activated
477
		$already_installed = ( 0 === validate_plugin( 'woocommerce-services/woocommerce-services.php' ) );
478
479
		$install_url = wp_nonce_url( add_query_arg( array( 'wc-services-action' => $already_installed ? 'activate' : 'install' ) ), 'wc-services-install' );
480
481
		?>
482
		<div class="jp-jitm woo-jitm">
483
			<a href="#"  data-module="wooservices" class="dismiss"><span class="genericon genericon-close"></span></a>
484
			<div class="jp-emblem">
485
				<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">
486
					<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" />
487
				</svg>
488
			</div>
489
			<p class="msg">
490
				<?php echo esc_html( $message ); ?>
491
			</p>
492
			<p>
493
				<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">
494
					<?php $already_installed ? esc_html_e( 'Activate WooCommerce Services', 'jetpack' ) : esc_html_e( 'Install WooCommerce Services', 'jetpack' ); ?>
495
				</a>
496
			</p>
497
		</div>
498
		<?php
499
		//jitm is being viewed, track it
500
		$jetpack = Jetpack::init();
501
		$jetpack->stat( 'jitm', 'wooservices-viewed-' . JETPACK__VERSION );
502
	}
503
504
	/*
505
	* Function to enqueue jitm css and js
506
	*/
507
	function jitm_enqueue_files( $hook ) {
508
509
		$wp_styles = new WP_Styles();
510
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
511
		wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' );
512
		$wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true );
513
514
		//Build stats url for tracking manage button
515
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) );
516
517
		// Enqueue javascript to handle jitm notice events
518
		wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ),
519
			array( 'jquery' ), JETPACK__VERSION, true );
520
		wp_localize_script(
521
			'jetpack-jitm-js',
522
			'jitmL10n',
523
			array(
524
				'ajaxurl'     => admin_url( 'admin-ajax.php' ),
525
				'jitm_nonce'  => wp_create_nonce( 'jetpack-jitm-nonce' ),
526
				'photon_msgs' => array(
527
					'success' => esc_html__( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ),
528
					'fail'    => esc_html__( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' )
529
				),
530
				'manage_msgs' => array(
531
					'success' => esc_html__( 'Success! WordPress.com tools are now active.', 'jetpack' ),
532
					'fail'    => esc_html__( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' )
533
				),
534
				'stats_msgs' => array(
535
					'success' => esc_html__( 'Success! Stats are now active.', 'jetpack' ),
536
					'fail'    => esc_html__( 'We are sorry but unfortunately Stats did not activate.', 'jetpack' )
537
				),
538
				'jitm_stats_url' => $jitm_stats_url
539
			)
540
		);
541
	}
542
543
	/**
544
	 * Check if a JITM was dismissed or not. Currently, dismissing one JITM will dismiss all of them.
545
	 *
546
	 * @since 3.8.2
547
	 *
548
	 * @return bool
549
	 */
550
	function is_jitm_dismissed() {
551
		if ( empty( self::$jetpack_hide_jitm ) ) {
552
553
			// The option returns false when nothing was dismissed
554
			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...
555
		}
556
557
		// so if it's not an array, it means no JITM was dismissed
558
		return is_array( self::$jetpack_hide_jitm );
559
	}
560
}
561
if (
562
	/**
563
	 * Filter to turn off all just in time messages
564
	 *
565
	 * @since 3.7.0
566
	 *
567
	 * @param bool true Whether to show just in time messages.
568
	 */
569
	apply_filters( 'jetpack_just_in_time_msgs', false )
570
) {
571
	Jetpack_JITM::init();
572
}
573