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