Completed
Push — update/use-identity-crisis-pac... ( 2d591b...c4c647 )
by
unknown
156:24 queued 146:50
created

Jetpack_IDC::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Deprecated since 9.8.0.
4
 * Functionality moved to the automattic/identity-crisis package.
5
 */
6
7
use Automattic\Jetpack\Assets;
8
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
9
use Automattic\Jetpack\Redirect;
10
11
/**
12
 * This class will handle everything involved with fixing an Identity Crisis.
13
 *
14
 * @since 4.4.0
15
 */
16
class Jetpack_IDC {
17
18
	/**
19
	 * @var Jetpack_IDC
20
	 **/
21
	private static $instance = null;
22
23
	/**
24
	 * The wpcom value of the home URL
25
	 *
26
	 * @var string
27
	 */
28
	static $wpcom_home_url;
29
30
	/**
31
	 * Has safe mode been confirmed?
32
	 *
33
	 * @var bool
34
	 */
35
	static $is_safe_mode_confirmed;
36
37
	/**
38
	 * The current screen, which is set if the current user is a non-admin and this is an admin page.
39
	 *
40
	 * @var WP_Screen
41
	 */
42
	static $current_screen;
43
44
	static function init() {
45
		if ( is_null( self::$instance ) ) {
46
			self::$instance = new Jetpack_IDC();
47
		}
48
49
		return self::$instance;
50
	}
51
52 View Code Duplication
	private function __construct() {
53
		add_action( 'jetpack_sync_processed_actions', array( $this, 'maybe_clear_migrate_option' ) );
54
		if ( false === $urls_in_crisis = Jetpack::check_identity_crisis() ) {
55
			return;
56
		}
57
58
		self::$wpcom_home_url = $urls_in_crisis['wpcom_home'];
59
		add_action( 'init', array( $this, 'wordpress_init' ) );
60
	}
61
62
	/**
63
	 * Gets the link to the support document used to explain Safe Mode to users
64
	 *
65
	 * @return string
66
	 */
67
	public static function get_safe_mod_doc_url() {
68
		return Redirect::get_url( 'jetpack-support-safe-mode' );
69
	}
70
71
	/**
72
	 * This method loops through the array of processed items from sync and checks if one of the items was the
73
	 * home_url or site_url callable. If so, then we delete the jetpack_migrate_for_idc option.
74
	 *
75
	 * @param $processed_items array Array of processed items that were synced to WordPress.com
76
	 */
77 View Code Duplication
	function maybe_clear_migrate_option( $processed_items ) {
78
		foreach ( (array) $processed_items as $item ) {
79
80
			// First, is this item a jetpack_sync_callable action? If so, then proceed.
81
			$callable_args = ( is_array( $item ) && isset( $item[0], $item[1] ) && 'jetpack_sync_callable' === $item[0] )
82
				? $item[1]
83
				: null;
84
85
			// Second, if $callable_args is set, check if the callable was home_url or site_url. If so,
86
			// clear the migrate option.
87
			if (
88
				isset( $callable_args, $callable_args[0] )
89
				&& ( 'home_url' === $callable_args[0] || 'site_url' === $callable_args[1] )
90
			) {
91
				Jetpack_Options::delete_option( 'migrate_for_idc' );
92
				break;
93
			}
94
		}
95
	}
96
97 View Code Duplication
	function wordpress_init() {
98
		if ( ! current_user_can( 'jetpack_disconnect' ) && is_admin() ) {
99
			add_action( 'admin_notices', array( $this, 'display_non_admin_idc_notice' ) );
100
			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_idc_notice_files' ) );
101
			add_action( 'current_screen', array( $this, 'non_admins_current_screen_check' ) );
102
			return;
103
		}
104
105
		if (
106
			isset( $_GET['jetpack_idc_clear_confirmation'], $_GET['_wpnonce'] ) &&
107
			wp_verify_nonce( $_GET['_wpnonce'], 'jetpack_idc_clear_confirmation' )
108
		) {
109
			Jetpack_Options::delete_option( 'safe_mode_confirmed' );
110
			self::$is_safe_mode_confirmed = false;
111
		} else {
112
			self::$is_safe_mode_confirmed = (bool) Jetpack_Options::get_option( 'safe_mode_confirmed' );
113
		}
114
115
		// 121 Priority so that it's the most inner Jetpack item in the admin bar.
116
		add_action( 'admin_bar_menu', array( $this, 'display_admin_bar_button' ), 121 );
117
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_bar_css' ) );
118
119
		if ( is_admin() && ! self::$is_safe_mode_confirmed ) {
120
			add_action( 'admin_notices', array( $this, 'display_idc_notice' ) );
121
			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_idc_notice_files' ) );
122
		}
123
	}
124
125 View Code Duplication
	function non_admins_current_screen_check( $current_screen ) {
126
		self::$current_screen = $current_screen;
127
		if ( isset( $current_screen->id ) && 'toplevel_page_jetpack' == $current_screen->id ) {
128
			return null;
129
		}
130
131
		// If the user has dismissed the notice, and we're not currently on a Jetpack page,
132
		// then do not show the non-admin notice.
133
		if ( isset( $_COOKIE, $_COOKIE['jetpack_idc_dismiss_notice'] ) ) {
134
			remove_action( 'admin_notices', array( $this, 'display_non_admin_idc_notice' ) );
135
			remove_action( 'admin_enqueue_scripts', array( $this, 'enqueue_idc_notice_files' ) );
136
		}
137
	}
138
139 View Code Duplication
	function display_admin_bar_button() {
140
		global $wp_admin_bar;
141
142
		$href = is_admin()
143
			? add_query_arg( 'jetpack_idc_clear_confirmation', '1' )
144
			: add_query_arg( 'jetpack_idc_clear_confirmation', '1', admin_url() );
145
146
		$href = wp_nonce_url( $href, 'jetpack_idc_clear_confirmation' );
147
148
		$title = sprintf(
149
			'<span class="jp-idc-admin-bar">%s %s</span>',
150
			'<span class="dashicons dashicons-warning"></span>',
151
			esc_html__( 'Jetpack Safe Mode', 'jetpack' )
152
		);
153
154
		$menu = array(
155
			'id'     => 'jetpack-idc',
156
			'title'  => $title,
157
			'href'   => esc_url( $href ),
158
			'parent' => 'top-secondary',
159
		);
160
161
		if ( ! self::$is_safe_mode_confirmed ) {
162
			$menu['meta'] = array(
163
				'class' => 'hide',
164
			);
165
		}
166
167
		$wp_admin_bar->add_node( $menu );
168
	}
169
170
	static function prepare_url_for_display( $url ) {
171
		return untrailingslashit( Jetpack::normalize_url_protocol_agnostic( $url ) );
172
	}
173
174
	/**
175
	 * Clears all IDC specific options. This method is used on disconnect and reconnect.
176
	 */
177 View Code Duplication
	static function clear_all_idc_options() {
178
		// If the site is currently in IDC, let's also clear the VaultPress connection options.
179
		// We have to check if the site is in IDC, otherwise we'd be clearing the VaultPress
180
		// connection any time the Jetpack connection is cycled.
181
		if ( Jetpack::validate_sync_error_idc_option() ) {
182
			delete_option( 'vaultpress' );
183
			delete_option( 'vaultpress_auto_register' );
184
		}
185
186
		Jetpack_Options::delete_option(
187
			array(
188
				'sync_error_idc',
189
				'safe_mode_confirmed',
190
				'migrate_for_idc',
191
			)
192
		);
193
	}
194
195
	/**
196
	 * Does the current admin page have help tabs?
197
	 *
198
	 * @return bool
199
	 */
200 View Code Duplication
	function admin_page_has_help_tabs() {
201
		if ( ! function_exists( 'get_current_screen' ) ) {
202
			return false;
203
		}
204
205
		$current_screen = get_current_screen();
206
		$tabs           = $current_screen->get_help_tabs();
207
208
		return ! empty( $tabs );
209
	}
210
211
	function display_non_admin_idc_notice() {
212
		$classes = 'jp-idc-notice inline is-non-admin notice notice-warning';
213
		if ( isset( self::$current_screen ) && 'toplevel_page_jetpack' != self::$current_screen->id ) {
214
			$classes .= ' is-dismissible';
215
		}
216
217
		if ( $this->admin_page_has_help_tabs() ) {
218
			$classes .= ' has-help-tabs';
219
		}
220
		?>
221
222
		<div class="<?php echo $classes; ?>">
223
			<?php $this->render_notice_header(); ?>
224
			<div class="jp-idc-notice__content-header">
225
				<h3 class="jp-idc-notice__content-header__lead">
226
					<?php echo $this->get_non_admin_notice_text(); ?>
227
				</h3>
228
229
				<p class="jp-idc-notice__content-header__explanation">
230
					<?php echo $this->get_non_admin_contact_admin_text(); ?>
231
				</p>
232
			</div>
233
		</div>
234
		<?php
235
	}
236
237
	/**
238
	 * First "step" of the IDC mitigation. Will provide some messaging and two options/buttons.
239
	 * "Confirm Staging" - Dismiss the notice and continue on with our lives in staging mode.
240
	 * "Fix Jetpack Connection" - Will disconnect the site and start the mitigation...
241
	 */
242 View Code Duplication
	function display_idc_notice() {
243
		$classes = 'jp-idc-notice inline notice notice-warning';
244
		if ( $this->admin_page_has_help_tabs() ) {
245
			$classes .= ' has-help-tabs';
246
		}
247
		?>
248
		<div class="<?php echo $classes; ?>">
249
			<?php $this->render_notice_header(); ?>
250
			<?php $this->render_notice_first_step(); ?>
251
			<?php $this->render_notice_second_step(); ?>
252
		</div>
253
		<?php
254
	}
255
256
	function enqueue_admin_bar_css() {
257
		wp_enqueue_style(
258
			'jetpack-idc-admin-bar-css',
259
			plugins_url( 'css/jetpack-idc-admin-bar.css', JETPACK__PLUGIN_FILE ),
260
			array( 'dashicons' ),
261
			JETPACK__VERSION
262
		);
263
	}
264
265
	/**
266
	 * Enqueue scripts for the notice
267
	 */
268
	function enqueue_idc_notice_files() {
269
270
		wp_enqueue_script(
271
			'jetpack-idc-js',
272
			Assets::get_file_url_for_environment( '_inc/build/idc-notice.min.js', '_inc/idc-notice.js' ),
273
			array( 'jquery' ),
274
			JETPACK__VERSION,
275
			true
276
		);
277
278
		wp_localize_script(
279
			'jetpack-idc-js',
280
			'idcL10n',
281
			array(
282
				'apiRoot'         => esc_url_raw( rest_url() ),
283
				'nonce'           => wp_create_nonce( 'wp_rest' ),
284
				'tracksUserData'  => Jetpack_Tracks_Client::get_connected_user_tracks_identity(),
285
				'currentUrl'      => remove_query_arg( '_wpnonce', remove_query_arg( 'jetpack_idc_clear_confirmation' ) ),
286
				'tracksEventData' => array(
287
					'isAdmin'       => current_user_can( 'jetpack_disconnect' ),
288
					'currentScreen' => self::$current_screen ? self::$current_screen->id : false,
289
				),
290
			)
291
		);
292
293
		if ( ! wp_style_is( 'jetpack-dops-style' ) ) {
294
			wp_register_style(
295
				'jetpack-dops-style',
296
				plugins_url( '_inc/build/admin.css', JETPACK__PLUGIN_FILE ),
297
				array(),
298
				JETPACK__VERSION
299
			);
300
		}
301
302
		wp_enqueue_style(
303
			'jetpack-idc-css',
304
			plugins_url( 'css/jetpack-idc.css', JETPACK__PLUGIN_FILE ),
305
			array( 'jetpack-dops-style' ),
306
			JETPACK__VERSION
307
		);
308
309
		// Required for Tracks
310
		wp_enqueue_script(
311
			'jp-tracks',
312
			'//stats.wp.com/w.js',
313
			array(),
314
			gmdate( 'YW' ),
315
			true
316
		);
317
318
		wp_enqueue_script(
319
			'jp-tracks-functions',
320
			plugins_url( '_inc/lib/tracks/tracks-callables.js', JETPACK__PLUGIN_FILE ),
321
			array(),
322
			JETPACK__VERSION,
323
			false
324
		);
325
	}
326
327
	function render_notice_header() {
328
		?>
329
		<div class="jp-idc-notice__header">
330
			<div class="jp-idc-notice__header__emblem">
331
				<?php
332
				$jetpack_logo = new Jetpack_Logo();
333
				echo $jetpack_logo->get_jp_emblem();
334
				?>
335
			</div>
336
			<p class="jp-idc-notice__header__text">
337
				<?php esc_html_e( 'Jetpack Safe Mode', 'jetpack' ); ?>
338
			</p>
339
		</div>
340
341
		<div class="jp-idc-notice__separator"></div>
342
		<?php
343
	}
344
345
	/**
346
	 * Is a container for the error notices.
347
	 * Will be shown/controlled by jQuery in idc-notice.js
348
	 */
349
	function render_error_notice() {
350
		?>
351
		<div class="jp-idc-error__notice dops-notice is-error">
352
			<svg class="gridicon gridicons-notice dops-notice__icon" height="24" width="24" viewBox="0 0 24 24">
353
				<g>
354
					<path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2l-.5-6h3l-.5 6z"></path>
355
				</g>
356
			</svg>
357
			<div class="dops-notice__content">
358
				<span class="dops-notice__text">
359
					<?php esc_html_e( 'Something went wrong:', 'jetpack' ); ?>
360
					<span class="jp-idc-error__desc"></span>
361
				</span>
362
				<a class="dops-notice__action" href="javascript:void(0);">
363
					<span id="jp-idc-error__action">
364
						<?php esc_html_e( 'Try Again', 'jetpack' ); ?>
365
					</span>
366
				</a>
367
			</div>
368
		</div>
369
		<?php
370
	}
371
372
	function render_notice_first_step() {
373
		?>
374
		<div class="jp-idc-notice__first-step">
375
			<div class="jp-idc-notice__content-header">
376
				<h3 class="jp-idc-notice__content-header__lead">
377
					<?php echo $this->get_first_step_header_lead(); ?>
378
				</h3>
379
380
				<p class="jp-idc-notice__content-header__explanation">
381
					<?php echo $this->get_first_step_header_explanation(); ?>
382
				</p>
383
			</div>
384
385
			<?php $this->render_error_notice(); ?>
386
387
			<div class="jp-idc-notice__actions">
388
				<div class="jp-idc-notice__action">
389
					<p class="jp-idc-notice__action__explanation">
390
						<?php echo $this->get_confirm_safe_mode_action_explanation(); ?>
391
					</p>
392
					<button id="jp-idc-confirm-safe-mode-action" class="dops-button">
393
						<?php echo $this->get_confirm_safe_mode_button_text(); ?>
394
					</button>
395
				</div>
396
397
				<div class="jp-idc-notice__action">
398
					<p class="jp-idc-notice__action__explanation">
399
						<?php echo $this->get_first_step_fix_connection_action_explanation(); ?>
400
					</p>
401
					<button id="jp-idc-fix-connection-action" class="dops-button">
402
						<?php echo $this->get_first_step_fix_connection_button_text(); ?>
403
					</button>
404
				</div>
405
			</div>
406
		</div>
407
		<?php
408
	}
409
410
	function render_notice_second_step() {
411
		?>
412
		<div class="jp-idc-notice__second-step">
413
			<div class="jp-idc-notice__content-header">
414
				<h3 class="jp-idc-notice__content-header__lead">
415
					<?php echo $this->get_second_step_header_lead(); ?>
416
				</h3>
417
			</div>
418
419
			<?php $this->render_error_notice(); ?>
420
421
			<div class="jp-idc-notice__actions">
422
				<div class="jp-idc-notice__action">
423
					<p class="jp-idc-notice__action__explanation">
424
						<?php echo $this->get_migrate_site_action_explanation(); ?>
425
					</p>
426
					<button id="jp-idc-migrate-action" class="dops-button">
427
						<?php echo $this->get_migrate_site_button_text(); ?>
428
					</button>
429
				</div>
430
431
				<div class="jp-idc-notice__action">
432
					<p class="jp-idc-notice__action__explanation">
433
						<?php echo $this->get_start_fresh_action_explanation(); ?>
434
					</p>
435
					<button id="jp-idc-reconnect-site-action" class="dops-button">
436
						<?php echo $this->get_start_fresh_button_text(); ?>
437
					</button>
438
				</div>
439
440
			</div>
441
442
			<p class="jp-idc-notice__unsure-prompt">
443
				<?php echo $this->get_unsure_prompt(); ?>
444
			</p>
445
		</div>
446
		<?php
447
	}
448
449 View Code Duplication
	function get_first_step_header_lead() {
450
		$html = wp_kses(
451
			sprintf(
452
				__(
453
					'Jetpack has been placed into <a href="%1$s">Safe mode</a> because we noticed this is an exact copy of <a href="%2$s">%3$s</a>.',
454
					'jetpack'
455
				),
456
				esc_url( self::get_safe_mod_doc_url() ),
457
				esc_url( self::$wpcom_home_url ),
458
				self::prepare_url_for_display( esc_url_raw( self::$wpcom_home_url ) )
459
			),
460
			array( 'a' => array( 'href' => array() ) )
461
		);
462
463
		/**
464
		 * Allows overriding of the default header text in the first step of the Safe Mode notice.
465
		 *
466
		 * @since 4.4.0
467
		 *
468
		 * @param string $html The HTML to be displayed
469
		 */
470
		return apply_filters( 'jetpack_idc_first_step_header_lead', $html );
471
	}
472
473 View Code Duplication
	function get_first_step_header_explanation() {
474
		$html = wp_kses(
475
			sprintf(
476
				__(
477
					'Please confirm Safe Mode or fix the Jetpack connection. Select one of the options below or <a href="%1$s">learn
478
					more about Safe Mode</a>.',
479
					'jetpack'
480
				),
481
				esc_url( self::get_safe_mod_doc_url() )
482
			),
483
			array( 'a' => array( 'href' => array() ) )
484
		);
485
486
		/**
487
		 * Allows overriding of the default header explanation text in the first step of the Safe Mode notice.
488
		 *
489
		 * @since 4.4.0
490
		 *
491
		 * @param string $html The HTML to be displayed
492
		 */
493
		return apply_filters( 'jetpack_idc_first_step_header_explanation', $html );
494
	}
495
496 View Code Duplication
	function get_confirm_safe_mode_action_explanation() {
497
		$html = wp_kses(
498
			sprintf(
499
				__(
500
					'Is this website a temporary duplicate of <a href="%1$s">%2$s</a> for the purposes
501
					of testing, staging or development? If so, we recommend keeping it in Safe Mode.',
502
					'jetpack'
503
				),
504
				esc_url( untrailingslashit( self::$wpcom_home_url ) ),
505
				self::prepare_url_for_display( esc_url( self::$wpcom_home_url ) )
506
			),
507
			array( 'a' => array( 'href' => array() ) )
508
		);
509
510
		/**
511
		 * Allows overriding of the default text used to explain the confirm safe mode action.
512
		 *
513
		 * @since 4.4.0
514
		 *
515
		 * @param string $html The HTML to be displayed
516
		 */
517
		return apply_filters( 'jetpack_idc_confirm_safe_mode_explanation', $html );
518
	}
519
520
	function get_confirm_safe_mode_button_text() {
521
		$string = esc_html__( 'Confirm Safe Mode', 'jetpack' );
522
523
		/**
524
		 * Allows overriding of the default text used for the confirm safe mode action button.
525
		 *
526
		 * @since 4.4.0
527
		 *
528
		 * @param string $string The string to be displayed
529
		 */
530
		return apply_filters( 'jetpack_idc_confirm_safe_mode_button_text', $string );
531
	}
532
533 View Code Duplication
	function get_first_step_fix_connection_action_explanation() {
534
		$html = wp_kses(
535
			sprintf(
536
				__(
537
					'If this is a separate and new website, or the new home of <a href="%1$s">%2$s</a>,
538
					we recommend turning Safe Mode off, and re-establishing your connection to WordPress.com.',
539
					'jetpack'
540
				),
541
				esc_url( untrailingslashit( self::$wpcom_home_url ) ),
542
				self::prepare_url_for_display( esc_url( self::$wpcom_home_url ) )
543
			),
544
			array( 'a' => array( 'href' => array() ) )
545
		);
546
547
		/**
548
		 * Allows overriding of the default text used to explain the fix Jetpack connection action.
549
		 *
550
		 * @since 4.4.0
551
		 *
552
		 * @param string $html The HTML to be displayed
553
		 */
554
		return apply_filters( 'jetpack_idc_first_fix_connection_explanation', $html );
555
	}
556
557
	function get_first_step_fix_connection_button_text() {
558
		$string = esc_html__( "Fix Jetpack's Connection", 'jetpack' );
559
560
		/**
561
		 * Allows overriding of the default text used for the fix Jetpack connection action button.
562
		 *
563
		 * @since 4.4.0
564
		 *
565
		 * @param string $string The string to be displayed
566
		 */
567
		return apply_filters( 'jetpack_idc_first_step_fix_connection_button_text', $string );
568
	}
569
570 View Code Duplication
	function get_second_step_header_lead() {
571
		$string = sprintf(
572
			esc_html__(
573
				'Is %1$s the new home of %2$s?',
574
				'jetpack'
575
			),
576
			untrailingslashit( Jetpack::normalize_url_protocol_agnostic( get_home_url() ) ),
577
			untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) )
578
		);
579
580
		/**
581
		 * Allows overriding of the default header text in the second step of the Safe Mode notice.
582
		 *
583
		 * @since 4.4.0
584
		 *
585
		 * @param string $html The HTML to be displayed
586
		 */
587
		return apply_filters( 'jetpack_idc_second_step_header_lead', $string );
588
	}
589
590 View Code Duplication
	function get_migrate_site_action_explanation() {
591
		$html = wp_kses(
592
			sprintf(
593
				__(
594
					'Yes. <a href="%1$s">%2$s</a> is replacing <a href="%3$s">%4$s</a>. I would like to
595
					migrate my stats and subscribers from <a href="%3$s">%4$s</a> to <a href="%1$s">%2$s</a>.',
596
					'jetpack'
597
				),
598
				esc_url( get_home_url() ),
599
				self::prepare_url_for_display( get_home_url() ),
600
				esc_url( self::$wpcom_home_url ),
601
				untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) )
602
			),
603
			array( 'a' => array( 'href' => array() ) )
604
		);
605
606
		/**
607
		 * Allows overriding of the default text for explaining the migrate site action.
608
		 *
609
		 * @since 4.4.0
610
		 *
611
		 * @param string $html The HTML to be displayed
612
		 */
613
		return apply_filters( 'jetpack_idc_migrate_site_explanation', $html );
614
	}
615
616
	function get_migrate_site_button_text() {
617
		$string = esc_html__( 'Migrate Stats &amp; Subscribers', 'jetpack' );
618
619
		/**
620
		 * Allows overriding of the default text used for the migrate site action button.
621
		 *
622
		 * @since 4.4.0
623
		 *
624
		 * @param string $string The string to be displayed
625
		 */
626
		return apply_filters( 'jetpack_idc_migrate_site_button_text', $string );
627
	}
628
629 View Code Duplication
	function get_start_fresh_action_explanation() {
630
		$html = wp_kses(
631
			sprintf(
632
				__(
633
					'No. <a href="%1$s">%2$s</a> is a new and different website that\'s separate from
634
					<a href="%3$s">%4$s</a>. It requires  a new connection to WordPress.com for new stats and subscribers.',
635
					'jetpack'
636
				),
637
				esc_url( get_home_url() ),
638
				self::prepare_url_for_display( get_home_url() ),
639
				esc_url( self::$wpcom_home_url ),
640
				untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) )
641
			),
642
			array( 'a' => array( 'href' => array() ) )
643
		);
644
645
		/**
646
		 * Allows overriding of the default text for explaining the start fresh action.
647
		 *
648
		 * @since 4.4.0
649
		 *
650
		 * @param string $html The HTML to be displayed
651
		 */
652
		return apply_filters( 'jetpack_idc_start_fresh_explanation', $html );
653
	}
654
655
	function get_start_fresh_button_text() {
656
		$string = esc_html__( 'Start Fresh &amp; Create New Connection', 'jetpack' );
657
658
		/**
659
		 * Allows overriding of the default text used for the start fresh action button.
660
		 *
661
		 * @since 4.4.0
662
		 *
663
		 * @param string $string The string to be displayed
664
		 */
665
		return apply_filters( 'jetpack_idc_start_fresh_button_text', $string );
666
	}
667
668 View Code Duplication
	function get_unsure_prompt() {
669
		$html = wp_kses(
670
			sprintf(
671
				__(
672
					'Unsure what to do? <a href="%1$s">Read more about Jetpack Safe Mode</a>',
673
					'jetpack'
674
				),
675
				esc_url( self::get_safe_mod_doc_url() )
676
			),
677
			array( 'a' => array( 'href' => array() ) )
678
		);
679
680
		/**
681
		 * Allows overriding of the default text using in the "Unsure what to do?" prompt.
682
		 *
683
		 * @since 4.4.0
684
		 *
685
		 * @param string $html The HTML to be displayed
686
		 */
687
		return apply_filters( 'jetpack_idc_unsure_prompt', $html );
688
	}
689
690 View Code Duplication
	function get_non_admin_notice_text() {
691
		$html = wp_kses(
692
			sprintf(
693
				__(
694
					'Jetpack has been placed into Safe Mode. Learn more about <a href="%1$s">Safe Mode</a>.',
695
					'jetpack'
696
				),
697
				esc_url( self::get_safe_mod_doc_url() )
698
			),
699
			array( 'a' => array( 'href' => array() ) )
700
		);
701
702
		/**
703
		 * Allows overriding of the default text that is displayed to non-admin on the Jetpack admin page.
704
		 *
705
		 * @since 4.4.0
706
		 *
707
		 * @param string $html The HTML to be displayed
708
		 */
709
		return apply_filters( 'jetpack_idc_non_admin_notice_text', $html );
710
	}
711
712
	function get_non_admin_contact_admin_text() {
713
		$string = esc_html__( 'An administrator of this site can take Jetpack out of Safe Mode.', 'jetpack' );
714
715
		/**
716
		 * Allows overriding of the default text that is displayed to non-admins prompting them to contact an admin.
717
		 *
718
		 * @since 4.4.0
719
		 *
720
		 * @param string $string The string to be displayed
721
		 */
722
		return apply_filters( 'jetpack_idc_non_admin_contact_admin_text', $string );
723
	}
724
}
725
726
add_action( 'plugins_loaded', array( 'Jetpack_IDC', 'init' ) );
727