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