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