|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This class will handle everything involved with fixing an Identity Crisis. |
|
5
|
|
|
* |
|
6
|
|
|
* @since 4.4.0 |
|
7
|
|
|
*/ |
|
8
|
|
|
class Jetpack_IDC { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @var Jetpack_IDC |
|
12
|
|
|
**/ |
|
13
|
|
|
private static $instance = null; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The wpcom value of the home URL |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
static $wpcom_home_url; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
static function init() { |
|
22
|
|
|
if ( is_null( self::$instance ) ) { |
|
23
|
|
|
self::$instance = new Jetpack_IDC; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
return self::$instance; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function __construct() { |
|
30
|
|
|
if ( false === $urls_in_crisis = Jetpack::check_identity_crisis() ) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
self::$wpcom_home_url = $urls_in_crisis['wpcom_home']; |
|
35
|
|
|
|
|
36
|
|
|
add_action( 'admin_notices', array( $this, 'display_idc_notice' ) ); |
|
37
|
|
|
add_action( 'admin_enqueue_scripts', array( $this,'enqueue_idc_notice_files' ) ); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function should_show_idc_notice() { |
|
41
|
|
|
return current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() && ! Jetpack::is_development_mode(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* First "step" of the IDC mitigation. Will provide some messaging and two options/buttons. |
|
46
|
|
|
* "Confirm Staging" - Dismiss the notice and continue on with our lives in staging mode. |
|
47
|
|
|
* "Fix Jetpack Connection" - Will disconnect the site and start the mitigation... |
|
48
|
|
|
*/ |
|
49
|
|
|
function display_idc_notice() { |
|
50
|
|
|
if ( ! $this->should_show_idc_notice() ) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$safe_mode_doc_link = 'https://jetpack.com/support/safe-mode'; |
|
55
|
|
|
?> |
|
56
|
|
|
<div class="jp-idc notice notice-warning"> |
|
57
|
|
|
<div class="jp-emblem"> |
|
58
|
|
|
<?php echo Jetpack::get_jp_emblem(); ?> |
|
59
|
|
|
</div> |
|
60
|
|
|
<p class="msg-top"> |
|
61
|
|
|
<?php esc_html_e( 'Jetpack Safe Mode.', 'jetpack' ); ?> |
|
62
|
|
|
</p> |
|
63
|
|
|
<hr /> |
|
64
|
|
|
<div class="msg-bottom-head"> |
|
65
|
|
|
<?php |
|
66
|
|
|
echo wp_kses( |
|
67
|
|
|
sprintf( |
|
68
|
|
|
__( |
|
69
|
|
|
'Jetpack has been placed into <a href="%1$s">Safe mode</a> because we noticed this is an exact copy of %2$s. |
|
70
|
|
|
Please confirm Safe Mode or fix the Jetpack connection. Select one of the options below or <a href="%1$s">learn |
|
71
|
|
|
more about Safe Mode</a>.', |
|
72
|
|
|
'jetpack' |
|
73
|
|
|
), |
|
74
|
|
|
esc_url( $safe_mode_doc_link ), |
|
75
|
|
|
Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) |
|
76
|
|
|
), |
|
77
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
78
|
|
|
); |
|
79
|
|
|
?> |
|
80
|
|
|
</div> |
|
81
|
|
|
<div style="width: 49%; display: inline-block;"> |
|
82
|
|
|
<?php |
|
83
|
|
|
echo wp_kses( |
|
84
|
|
|
sprintf( |
|
85
|
|
|
__( |
|
86
|
|
|
'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.', |
|
87
|
|
|
'jetpack' |
|
88
|
|
|
), |
|
89
|
|
|
esc_url( self::$wpcom_home_url ), |
|
90
|
|
|
Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) |
|
91
|
|
|
), |
|
92
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
93
|
|
|
); |
|
94
|
|
|
?> |
|
95
|
|
|
<button id="idc-confirm-safe-mode"><?php esc_html_e( 'Confirm Safe Mode' ); ?></button> |
|
96
|
|
|
</div> |
|
97
|
|
|
<div style="width: 49%; display: inline-block;"> |
|
98
|
|
|
<?php |
|
99
|
|
|
echo wp_kses( |
|
100
|
|
|
sprintf( |
|
101
|
|
|
__( |
|
102
|
|
|
'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, |
|
103
|
|
|
and re-establishing your connection to WordPress.com.', |
|
104
|
|
|
'jetpack' |
|
105
|
|
|
), |
|
106
|
|
|
esc_url( $safe_mode_doc_link ), |
|
107
|
|
|
Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) |
|
108
|
|
|
), |
|
109
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
110
|
|
|
); |
|
111
|
|
|
?> |
|
112
|
|
|
<button id="idc-fix-connection"><?php esc_html_e( "Fix Jetpack's Connection" ); ?></button> |
|
113
|
|
|
</div> |
|
114
|
|
|
</div> |
|
115
|
|
|
<?php } |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Enqueue scripts for the notice |
|
119
|
|
|
*/ |
|
120
|
|
|
function enqueue_idc_notice_files() { |
|
121
|
|
|
if ( ! $this->should_show_idc_notice() ) { |
|
122
|
|
|
return; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
wp_enqueue_script( |
|
126
|
|
|
'jetpack-idc-js', |
|
127
|
|
|
plugins_url( '_inc/idc-notice.js', JETPACK__PLUGIN_FILE ), |
|
128
|
|
|
array( 'jquery' ), |
|
129
|
|
|
JETPACK__VERSION, |
|
130
|
|
|
true |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
wp_localize_script( |
|
134
|
|
|
'jetpack-idc-js', |
|
135
|
|
|
'idcL10n', |
|
136
|
|
|
array( |
|
137
|
|
|
'apiRoot' => esc_url_raw( rest_url() ), |
|
138
|
|
|
'nonce' => wp_create_nonce( 'wp_rest' ), |
|
139
|
|
|
) |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
wp_enqueue_style( |
|
143
|
|
|
'jetpack-idc-css', |
|
144
|
|
|
plugins_url( 'css/jetpack-idc.css', JETPACK__PLUGIN_FILE ), |
|
145
|
|
|
array(), |
|
146
|
|
|
JETPACK__VERSION |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
Jetpack_IDC::init(); |
|
152
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.