|
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
|
|
|
/** |
|
22
|
|
|
* The link to the support document used to explain Safe Mode to users |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
const SAFE_MODE_DOC_LINK = 'https://jetpack.com/support/safe-mode'; |
|
26
|
|
|
|
|
27
|
|
|
static function init() { |
|
28
|
|
|
if ( is_null( self::$instance ) ) { |
|
29
|
|
|
self::$instance = new Jetpack_IDC; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
return self::$instance; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private function __construct() { |
|
36
|
|
|
if ( false === $urls_in_crisis = Jetpack::check_identity_crisis() ) { |
|
37
|
|
|
return; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
self::$wpcom_home_url = $urls_in_crisis['wpcom_home']; |
|
41
|
|
|
|
|
42
|
|
|
add_action( 'admin_notices', array( $this, 'display_idc_notice' ) ); |
|
43
|
|
|
add_action( 'admin_enqueue_scripts', array( $this,'enqueue_idc_notice_files' ) ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function should_show_idc_notice() { |
|
47
|
|
|
return current_user_can( 'jetpack_disconnect' ) && Jetpack::is_active() && ! Jetpack::is_development_mode(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* First "step" of the IDC mitigation. Will provide some messaging and two options/buttons. |
|
52
|
|
|
* "Confirm Staging" - Dismiss the notice and continue on with our lives in staging mode. |
|
53
|
|
|
* "Fix Jetpack Connection" - Will disconnect the site and start the mitigation... |
|
54
|
|
|
*/ |
|
55
|
|
|
function display_idc_notice() { |
|
56
|
|
|
if ( ! $this->should_show_idc_notice() ) { |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
?> |
|
61
|
|
|
<div class="jp-idc-notice notice notice-warning"> |
|
62
|
|
|
<div class="jp-idc-notice__header"> |
|
63
|
|
|
<div class="jp-idc-notice__header__emblem"> |
|
64
|
|
|
<?php echo Jetpack::get_jp_emblem(); ?> |
|
65
|
|
|
</div> |
|
66
|
|
|
<p class="jp-idc-notice__header__text"> |
|
67
|
|
|
<?php esc_html_e( 'Jetpack Safe Mode', 'jetpack' ); ?> |
|
68
|
|
|
</p> |
|
69
|
|
|
</div> |
|
70
|
|
|
|
|
71
|
|
|
<?php $this->render_notice_first_step(); ?> |
|
72
|
|
|
<?php $this->render_notice_second_step(); ?> |
|
73
|
|
|
</div> |
|
74
|
|
|
<?php } |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Enqueue scripts for the notice |
|
78
|
|
|
*/ |
|
79
|
|
|
function enqueue_idc_notice_files() { |
|
80
|
|
|
if ( ! $this->should_show_idc_notice() ) { |
|
81
|
|
|
return; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
wp_enqueue_script( |
|
85
|
|
|
'jetpack-idc-js', |
|
86
|
|
|
plugins_url( '_inc/idc-notice.js', JETPACK__PLUGIN_FILE ), |
|
87
|
|
|
array( 'jquery' ), |
|
88
|
|
|
JETPACK__VERSION, |
|
89
|
|
|
true |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
wp_localize_script( |
|
93
|
|
|
'jetpack-idc-js', |
|
94
|
|
|
'idcL10n', |
|
95
|
|
|
array( |
|
96
|
|
|
'apiRoot' => esc_url_raw( rest_url() ), |
|
97
|
|
|
'nonce' => wp_create_nonce( 'wp_rest' ), |
|
98
|
|
|
) |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
wp_register_style( |
|
102
|
|
|
'jetpack-dops-style', |
|
103
|
|
|
plugins_url( '_inc/build/admin.dops-style.css', JETPACK__PLUGIN_FILE ), |
|
104
|
|
|
array(), |
|
105
|
|
|
JETPACK__VERSION |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
wp_enqueue_style( |
|
109
|
|
|
'jetpack-idc-css', |
|
110
|
|
|
plugins_url( 'css/jetpack-idc.css', JETPACK__PLUGIN_FILE ), |
|
111
|
|
|
array( 'jetpack-dops-style' ), |
|
112
|
|
|
JETPACK__VERSION |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
function render_notice_first_step() { ?> |
|
117
|
|
|
<div class="jp-idc-notice__first-step"> |
|
118
|
|
|
<div class="jp-idc-notice__content-header"> |
|
119
|
|
|
<h3 class="jp-idc-notice__content-header__lead"> |
|
120
|
|
|
<?php |
|
121
|
|
|
echo wp_kses( |
|
122
|
|
|
sprintf( |
|
123
|
|
|
__( |
|
124
|
|
|
'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">%2$s</a>.', |
|
125
|
|
|
'jetpack' |
|
126
|
|
|
), |
|
127
|
|
|
esc_url( self::SAFE_MODE_DOC_LINK ), |
|
128
|
|
|
esc_url( untrailingslashit( self::$wpcom_home_url ) ) |
|
129
|
|
|
), |
|
130
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
131
|
|
|
); |
|
132
|
|
|
?> |
|
133
|
|
|
</h3> |
|
134
|
|
|
|
|
135
|
|
|
<p class="jp-idc-notice__content-header__explanation"> |
|
136
|
|
|
<?php |
|
137
|
|
|
echo wp_kses( |
|
138
|
|
|
sprintf( |
|
139
|
|
|
__( |
|
140
|
|
|
'Please confirm Safe Mode or fix the Jetpack connection. Select one of the options below or <a href="%1$s">learn |
|
141
|
|
|
more about Safe Mode</a>.', |
|
142
|
|
|
'jetpack' |
|
143
|
|
|
), |
|
144
|
|
|
esc_url( self::SAFE_MODE_DOC_LINK ) |
|
145
|
|
|
), |
|
146
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
147
|
|
|
); |
|
148
|
|
|
?> |
|
149
|
|
|
</p> |
|
150
|
|
|
</div> |
|
151
|
|
|
|
|
152
|
|
|
<div class="jp-idc-notice__actions"> |
|
153
|
|
|
<div class="jp-idc-notice__action"> |
|
154
|
|
|
<p class="jp-idc-notice__action__explanation"> |
|
155
|
|
|
<?php |
|
156
|
|
|
echo wp_kses( |
|
157
|
|
|
sprintf( |
|
158
|
|
|
__( |
|
159
|
|
|
'Is this website a temporary duplicate of <a href="%1$s">%1$s</a> for the purposes |
|
160
|
|
|
of testing, staging or development? If so, we recommend keeping it in Safe Mode.', |
|
161
|
|
|
'jetpack' |
|
162
|
|
|
), |
|
163
|
|
|
esc_url( untrailingslashit( self::$wpcom_home_url ) ) |
|
164
|
|
|
), |
|
165
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
166
|
|
|
); |
|
167
|
|
|
?> |
|
168
|
|
|
</p> |
|
169
|
|
|
<button id="jp-idc-confirm-safe-mode-action" class="dops-button"> |
|
170
|
|
|
<?php esc_html_e( 'Confirm Safe Mode' ); ?> |
|
171
|
|
|
</button> |
|
172
|
|
|
</div> |
|
173
|
|
|
|
|
174
|
|
|
<div class="jp-idc-notice__action"> |
|
175
|
|
|
<p class="jp-idc-notice__action__explanation"> |
|
176
|
|
|
<?php |
|
177
|
|
|
echo wp_kses( |
|
178
|
|
|
sprintf( |
|
179
|
|
|
__( |
|
180
|
|
|
'If this is a separate and new website, or the new home of <a href="%1$s">%1$s</a>, |
|
181
|
|
|
we recommend turning Safe Mode off, and re-establishing your connection to WordPress.com.', |
|
182
|
|
|
'jetpack' |
|
183
|
|
|
), |
|
184
|
|
|
esc_url( untrailingslashit( self::$wpcom_home_url ) ) |
|
185
|
|
|
), |
|
186
|
|
|
array( 'a' => array( 'href' => array() ) ) |
|
187
|
|
|
); |
|
188
|
|
|
?> |
|
189
|
|
|
</p> |
|
190
|
|
|
<button id="jp-idc-fix-connection-action" class="dops-button"> |
|
191
|
|
|
<?php esc_html_e( "Fix Jetpack's Connection" ); ?> |
|
192
|
|
|
</button> |
|
193
|
|
|
</div> |
|
194
|
|
|
</div> |
|
195
|
|
|
</div> |
|
196
|
|
|
<?php } |
|
197
|
|
|
|
|
198
|
|
|
function render_notice_second_step() { ?> |
|
199
|
|
|
<div class="jp-idc-notice__second-step"> |
|
200
|
|
|
<div class="jp-idc-notice__content-header"> |
|
201
|
|
|
<h3 class="jp-idc-notice__content-header__lead"> |
|
202
|
|
|
<?php |
|
203
|
|
|
printf( |
|
204
|
|
|
esc_html__( |
|
205
|
|
|
'Is %1$s the new home of %2$s?', |
|
206
|
|
|
'jetpack' |
|
207
|
|
|
), |
|
208
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( get_home_url() ) ), |
|
209
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) ) |
|
210
|
|
|
) |
|
211
|
|
|
?> |
|
212
|
|
|
</h3> |
|
213
|
|
|
</div> |
|
214
|
|
|
|
|
215
|
|
|
<div class="jp-idc-notice__actions"> |
|
216
|
|
|
<div class="jp-idc-notice__action"> |
|
217
|
|
|
<p class="jp-idc-notice__action__explanation"> |
|
218
|
|
|
<?php |
|
219
|
|
|
printf( |
|
220
|
|
|
esc_html__( |
|
221
|
|
|
'Yes. %1$s is replacing %2$s. I would like to migrate my stats and subscribers from |
|
222
|
|
|
%2$s to %1$s.', |
|
223
|
|
|
'jetpack' |
|
224
|
|
|
), |
|
225
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( get_home_url() ) ), |
|
226
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) ) |
|
227
|
|
|
) |
|
228
|
|
|
?> |
|
229
|
|
|
</p> |
|
230
|
|
|
<button id="jp-idc-migrate-action" class="dops-button"> |
|
231
|
|
|
<?php esc_html_e( 'Migrate stats & and Subscribers' ); ?> |
|
232
|
|
|
</button> |
|
233
|
|
|
</div> |
|
234
|
|
|
|
|
235
|
|
|
<div class="jp-idc-notice__action"> |
|
236
|
|
|
<p class="jp-idc-notice__action__explanation"> |
|
237
|
|
|
<?php |
|
238
|
|
|
printf( |
|
239
|
|
|
esc_html__( |
|
240
|
|
|
'No. %1$s is a new and different website that\'s separate from %2$s. It requires |
|
241
|
|
|
a new connection to WordPress.com for new stats and subscribers.', |
|
242
|
|
|
'jetpack' |
|
243
|
|
|
), |
|
244
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( get_home_url() ) ), |
|
245
|
|
|
untrailingslashit( Jetpack::normalize_url_protocol_agnostic( esc_url_raw( self::$wpcom_home_url ) ) ) |
|
246
|
|
|
) |
|
247
|
|
|
?> |
|
248
|
|
|
</p> |
|
249
|
|
|
<button id="jp-idc-reconnect-site-action" class="dops-button"> |
|
250
|
|
|
<?php esc_html_e( 'Start fresh & create new connection' ); ?> |
|
251
|
|
|
</button> |
|
252
|
|
|
</div> |
|
253
|
|
|
</div> |
|
254
|
|
|
</div> |
|
255
|
|
|
<?php } |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
Jetpack_IDC::init(); |
|
259
|
|
|
|
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.