Completed
Push — enhance/new-jitm-styles ( ae633f...ca7a45 )
by
unknown
09:46
created

Jetpack_JITM::backups_updates_msg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 62
rs 9.4743
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' ); ?>" /><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
	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="jitm-card jitm-banner has-call-to-action" data-track="vaultpress-updates" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
329
			<div class="jitm-banner__icon-plan">
330
				<?php echo self::get_emblem(); ?>
331
			</div>
332
			<div class="jitm-banner__content">
333
				<div class="jitm-banner__info">
334
					<div class="jitm-banner__title"><?php esc_html_e( 'Backups are recommended to protect your site before you make any changes.', 'jetpack' ); ?></div>
335
				</div>
336
				<div class="jitm-banner__action">
337
					<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" class="jitm-button is-compact launch jptracks"><?php esc_html_e( 'Enable Backups', 'jetpack' ); ?></a>
338
				</div>
339
				<a href="#" data-module="vaultpress" class="jitm-banner__dismiss"></a>
340
			</div>
341
		</div>
342
343
		<? /* ===========   Begin new JITM style EXAMPLES */ ?>
0 ignored issues
show
Security Best Practice introduced by
It is not recommend to use PHP's short opening tag <?, better use <?php, or <?= in case of outputting.

Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.

As a precaution to avoid these problems better use the long opening tag <?php.

Loading history...
344
345
		<div class="jitm-card jitm-banner has-call-to-action">
346
			<div class="jitm-banner__icon-plan">
347
				<?php echo self::get_emblem(); ?>
348
			</div>
349
			<div class="jitm-banner__content">
350
				<div class="jitm-banner__info">
351
					<div class="jitm-banner__title"><?php esc_html_e( 'This is a JITM title. Messages go here', 'jetpack' ); ?></div>
352
				</div>
353
				<div class="jitm-banner__action">
354
					<a href="#" type="button" class="jitm-button is-compact">Upgrade</a>
355
				</div>
356
				<a href="#" data-module="" class="jitm-banner__dismiss"></a>
357
			</div>
358
		</div>
359
360
		<div class="jitm-card jitm-banner has-call-to-action is-upgrade-premium">
361
			<div class="jitm-banner__icon-plan">
362
				<?php echo self::get_emblem(); ?>
363
			</div>
364
			<div class="jitm-banner__content">
365
				<div class="jitm-banner__info">
366
					<div class="jitm-banner__title"><?php esc_html_e( 'This is a JITM title.', 'jetpack' ); ?></div>
367
					<div class="jitm-banner__description"><?php esc_html_e( 'This is a optional JITM description. Super cool, right? We can enter longer strings of text here and it shall flow nicely on all screen sizes.', 'jetpack' ); ?></div>
368
				</div>
369
				<div class="jitm-banner__action">
370
					<a href="#" type="button" class="jitm-button is-compact is-primary">Upgrade</a>
371
				</div>
372
				<a href="#" data-module="" class="jitm-banner__dismiss"></a>
373
			</div>
374
		</div>
375
376
		<? /* ===========   End new JITM style EXAMPLES */ ?>
377
378
379
		<?php
380
		//jitm is being viewed, track it
381
		$jetpack = Jetpack::init();
382
		$jetpack->stat( 'jitm', 'vaultpress-updates-viewed-' . JETPACK__VERSION );
383
		$jetpack->do_stats( 'server_side' );
384
	}
385
386
	/**
387
	 * Display JITM in Comments screen prompting user to enable Akismet.
388
	 *
389
	 * @since 3.9.5
390
	 */
391 View Code Duplication
	function akismet_msg() {
392
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
393
		$url = 'https://jetpack.com/redirect/?source=jitm-akismet&site=' . $normalized_site_url;
394
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'akismet' ) );
395
		?>
396
		<div class="jp-jitm" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
397
			<a href="#" data-module="akismet" class="dismiss"><span class="genericon genericon-close"></span></a>
398
			<?php echo self::get_emblem(); ?>
399
			<p class="msg">
400
				<?php esc_html_e( "Spam affects your site's legitimacy, protect your site with Akismet.", 'jetpack' ); ?>
401
			</p>
402
			<p>
403
				<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>
404
			</p>
405
		</div>
406
		<?php
407
		//jitm is being viewed, track it
408
		$jetpack = Jetpack::init();
409
		$jetpack->stat( 'jitm', 'akismet-viewed-' . JETPACK__VERSION );
410
		$jetpack->do_stats( 'server_side' );
411
	}
412
413
	/**
414
	 * Display JITM after a post is published prompting user to enable Backups.
415
	 *
416
	 * @since 3.9.5
417
	 */
418 View Code Duplication
	function backups_after_publish_msg() {
419
		$normalized_site_url = Jetpack::build_raw_urls( get_home_url() );
420
		$url = 'https://jetpack.com/redirect/?source=jitm-backup-publish&site=' . $normalized_site_url;
421
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'vaultpress' ) );
422
		?>
423
		<div class="jp-jitm" data-track="vaultpress-publish" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
424
			<a href="#" data-module="vaultpress" class="dismiss"><span class="genericon genericon-close"></span></a>
425
426
			<?php echo self::get_emblem(); ?>
427
428
			<p class="msg">
429
				<?php esc_html_e( "Great job! Now let's make sure your hard work is never lost, backup everything with VaultPress.", 'jetpack' ); ?>
430
			</p>
431
			<p>
432
				<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>
433
			</p>
434
		</div>
435
		<?php
436
		//jitm is being viewed, track it
437
		$jetpack = Jetpack::init();
438
		$jetpack->stat( 'jitm', 'vaultpress-publish-viewed-' . JETPACK__VERSION );
439
		$jetpack->do_stats( 'server_side' );
440
	}
441
442
	/**
443
	 * Display a JITM style message for the media-new page.
444
	 *
445
	 * @since 4.5
446
	 */
447
	function videopress_media_upload_warning_msg() {
448
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'videopress' ) );
449
450
		$upload_url   = add_query_arg( 'mode', 'grid', admin_url( 'upload.php' ) );
451
		$new_post_url = admin_url( 'post-new.php' );
452
453
		$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 ) );
454
		?>
455
        <div class="jp-jitm" data-track="videopress-upload-warning" data-stats_url="<?php echo esc_url( $jitm_stats_url ); ?>">
456
            <!-- <a href="#" data-module="videopress" class="dismiss"><span class="genericon genericon-close"></span></a>-->
457
458
			<?php echo self::get_emblem(); ?>
459
460
            <p class="msg">
461
				<?php echo $msg; ?>
462
            </p>
463
            <p>
464
                <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>
465
            </p>
466
        </div>
467
		<?php
468
	}
469
470
	/**
471
	 * Display message prompting user to install WooCommerce Services.
472
	 *
473
	 * @since 4.6
474
	 */
475
	function woocommerce_services_msg() {
476
		if ( ! current_user_can( 'manage_woocommerce' ) || ! current_user_can( 'install_plugins' ) ) {
477
			return;
478
		}
479
480
		if ( isset( self::$jetpack_hide_jitm['woocommerce_services'] ) ) {
481
			return;
482
		}
483
484
		if ( ! function_exists( 'wc_get_base_location' ) ) {
485
			return;
486
		}
487
488
		$base_location = wc_get_base_location();
489
490
		switch ( $base_location['country'] ) {
491
			case 'US':
492
				$message = __( 'New free service: Show USPS shipping rates on your store! Added bonus: print shipping labels without leaving WooCommerce.', 'jetpack' );
493
				break;
494
			case 'CA':
495
				$message = __( 'New free service: Show Canada Post shipping rates on your store!', 'jetpack' );
496
				break;
497
			default:
498
				return;
499
		}
500
501
		// If plugin dir exists, means it's installed but not activated
502
		$already_installed = ( 0 === validate_plugin( 'woocommerce-services/woocommerce-services.php' ) );
503
504
		$install_url = wp_nonce_url( add_query_arg( array( 'wc-services-action' => $already_installed ? 'activate' : 'install' ) ), 'wc-services-install' );
505
506
		?>
507
		<div class="jp-jitm woo-jitm">
508
			<a href="#"  data-module="wooservices" class="dismiss"><span class="genericon genericon-close"></span></a>
509
			<div class="jp-emblem">
510
				<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">
511
					<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" />
512
				</svg>
513
			</div>
514
			<p class="msg">
515
				<?php echo esc_html( $message ); ?>
516
			</p>
517
			<p>
518
				<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">
519
					<?php $already_installed ? esc_html_e( 'Activate WooCommerce Services', 'jetpack' ) : esc_html_e( 'Install WooCommerce Services', 'jetpack' ); ?>
520
				</a>
521
			</p>
522
		</div>
523
		<?php
524
		//jitm is being viewed, track it
525
		$jetpack = Jetpack::init();
526
		$jetpack->stat( 'jitm', 'wooservices-viewed-' . JETPACK__VERSION );
527
	}
528
529
	/*
530
	* Function to enqueue jitm css and js
531
	*/
532
	function jitm_enqueue_files( $hook ) {
533
534
		$wp_styles = new WP_Styles();
535
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
536
		wp_enqueue_style( 'jetpack-jitm-css', plugins_url( "css/jetpack-admin-jitm{$min}.css", JETPACK__PLUGIN_FILE ), false, JETPACK__VERSION . '-201243242' );
537
		$wp_styles->add_data( 'jetpack-jitm-css', 'rtl', true );
538
539
		//Build stats url for tracking manage button
540
		$jitm_stats_url = Jetpack::build_stats_url( array( 'x_jetpack-jitm' => 'wordpresstools' ) );
541
542
		// Enqueue javascript to handle jitm notice events
543
		wp_enqueue_script( 'jetpack-jitm-js', plugins_url( '_inc/jetpack-jitm.js', JETPACK__PLUGIN_FILE ),
544
			array( 'jquery' ), JETPACK__VERSION, true );
545
		wp_localize_script(
546
			'jetpack-jitm-js',
547
			'jitmL10n',
548
			array(
549
				'ajaxurl'     => admin_url( 'admin-ajax.php' ),
550
				'jitm_nonce'  => wp_create_nonce( 'jetpack-jitm-nonce' ),
551
				'photon_msgs' => array(
552
					'success' => esc_html__( 'Success! Photon is now actively optimizing and serving your images for free.', 'jetpack' ),
553
					'fail'    => esc_html__( 'We are sorry but unfortunately Photon did not activate.', 'jetpack' )
554
				),
555
				'manage_msgs' => array(
556
					'success' => esc_html__( 'Success! WordPress.com tools are now active.', 'jetpack' ),
557
					'fail'    => esc_html__( 'We are sorry but unfortunately Manage did not activate.', 'jetpack' )
558
				),
559
				'stats_msgs' => array(
560
					'success' => esc_html__( 'Success! Stats are now active.', 'jetpack' ),
561
					'fail'    => esc_html__( 'We are sorry but unfortunately Stats did not activate.', 'jetpack' )
562
				),
563
				'jitm_stats_url' => $jitm_stats_url
564
			)
565
		);
566
	}
567
568
	/**
569
	 * Check if a JITM was dismissed or not. Currently, dismissing one JITM will dismiss all of them.
570
	 *
571
	 * @since 3.8.2
572
	 *
573
	 * @return bool
574
	 */
575
	function is_jitm_dismissed() {
576
		if ( empty( self::$jetpack_hide_jitm ) ) {
577
578
			// The option returns false when nothing was dismissed
579
			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...
580
		}
581
582
		// so if it's not an array, it means no JITM was dismissed
583
		return is_array( self::$jetpack_hide_jitm );
584
	}
585
}
586
if (
587
	/**
588
	 * Filter to turn off all just in time messages
589
	 *
590
	 * @since 3.7.0
591
	 *
592
	 * @param bool true Whether to show just in time messages.
593
	 */
594
	apply_filters( 'jetpack_just_in_time_msgs', false )
595
) {
596
	Jetpack_JITM::init();
597
}
598