Completed
Push — add/identity-crisis-package ( 055944...cfc822 )
by
unknown
88:03 queued 77:56
created

get_confirm_safe_mode_action_explanation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
1
<?php
2
/**
3
 * Identity_Crisis package.
4
 *
5
 * @package  automattic/jetpack-identity-crisis
6
 */
7
8
namespace Automattic\Jetpack;
9
10
use Automattic\Jetpack\Assets\Logo as Jetpack_Logo;
11
use Jetpack;
12
use Jetpack_Options;
13
use Jetpack_Tracks_Client;
14
15
/**
16
 * This class will handle everything involved with fixing an Identity Crisis.
17
 *
18
 * @since 4.4.0
19
 */
20
class Identity_Crisis {
21
22
	/**
23
	 * Instance of the object.
24
	 *
25
	 * @var Identity_Crisis
26
	 **/
27
	private static $instance = null;
28
29
	/**
30
	 * The wpcom value of the home URL.
31
	 *
32
	 * @var string
33
	 */
34
	public static $wpcom_home_url;
35
36
	/**
37
	 * Has safe mode been confirmed?
38
	 *
39
	 * @var bool
40
	 */
41
	public static $is_safe_mode_confirmed;
42
43
	/**
44
	 * The current screen, which is set if the current user is a non-admin and this is an admin page.
45
	 *
46
	 * @var WP_Screen
47
	 */
48
	public static $current_screen;
49
50
	/**
51
	 * Initializer.
52
	 *
53
	 * @return object
54
	 */
55
	public static function init() {
56
		if ( is_null( self::$instance ) ) {
57
			self::$instance = new Identity_Crisis();
58
		}
59
60
		return self::$instance;
61
	}
62
63
	/**
64
	 * Class constructor.
65
	 *
66
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

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