|
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, 'prepare_idc_notice' ) ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function prepare_idc_notice() { |
|
40
|
|
|
if ( ! current_user_can( 'jetpack_disconnect' ) || ! Jetpack::is_active() || Jetpack::is_development_mode() ) { |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->enqueue_idc_notice_files(); |
|
45
|
|
|
$this->idc_notice_step_one(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* First "step" of the IDC mitigation. Will provide some messaging and two options/buttons. |
|
50
|
|
|
* "Confirm Staging" - Dismiss the notice and continue on with our lives in staging mode. |
|
51
|
|
|
* "Fix Jetpack Connection" - Will disconnect the site and start the mitigation... |
|
52
|
|
|
*/ |
|
53
|
|
|
function idc_notice_step_one() { |
|
54
|
|
|
$safe_mode_doc_link = 'https://jetpack.com/support/safe-mode'; |
|
55
|
|
|
$old_url = esc_url( self::$wpcom_home_url ); |
|
56
|
|
|
?> |
|
57
|
|
|
<div class="jp-idc notice notice-warning"> |
|
58
|
|
|
<div class="jp-emblem"> |
|
59
|
|
|
<?php echo Jetpack::get_jp_emblem(); ?> |
|
60
|
|
|
</div> |
|
61
|
|
|
<p class="msg-top"> |
|
62
|
|
|
<?php esc_html_e( 'Jetpack Safe Mode.', 'jetpack' ); ?> |
|
63
|
|
|
</p> |
|
64
|
|
|
<hr /> |
|
65
|
|
|
<div class="msg-bottom-head"> |
|
66
|
|
|
<?php |
|
67
|
|
|
_e( |
|
68
|
|
|
sprintf( |
|
69
|
|
|
'Jetpack has been placed into %1$sSafe Mode%2$s because we noticed this is an exact copy of %3$s. |
|
70
|
|
|
Please confirm Safe Mode or fix the Jetpack connection. Select one of the options below or %1$slearn more about Safe Mode%2$s.', |
|
71
|
|
|
'<a href="' . esc_url( $safe_mode_doc_link ) . '">', |
|
72
|
|
|
'</a>', |
|
73
|
|
|
'<a href="' . $old_url . '">' . $old_url . '</a>' |
|
74
|
|
|
), 'jetpack' |
|
75
|
|
|
) |
|
76
|
|
|
?> |
|
77
|
|
|
</div> |
|
78
|
|
|
<div style="width: 49%; display: inline-block;"> |
|
79
|
|
|
<?php |
|
80
|
|
|
_e( |
|
81
|
|
|
sprintf( |
|
82
|
|
|
'Is this website a temporaray duplicate of %s for the purposes of testing, staging or development? |
|
83
|
|
|
If so, we recommend keeping it in Safe Mode.', |
|
84
|
|
|
'<a href="' . $old_url . '">' . $old_url . '</a>' |
|
85
|
|
|
), 'jetpack' |
|
86
|
|
|
); |
|
87
|
|
|
?> |
|
88
|
|
|
<button><?php _e( 'Confirm Safe Mode' ); ?></button> |
|
89
|
|
|
</div> |
|
90
|
|
|
<div style="width: 49%; display: inline-block;"> |
|
91
|
|
|
<?php |
|
92
|
|
|
_e( |
|
93
|
|
|
sprintf( |
|
94
|
|
|
'If this is a separate and new website, or the new home of %s, we recommend turning Safe Mode off, |
|
95
|
|
|
and re-establishing your connection to WordPress.com.', |
|
96
|
|
|
'<a href="' . $old_url . '">' . $old_url . '</a>' |
|
97
|
|
|
), 'jetpack' |
|
98
|
|
|
); |
|
99
|
|
|
?> |
|
100
|
|
|
<button><?php _e( "Fix Jetpack's Connection" ); ?></button> |
|
101
|
|
|
</div> |
|
102
|
|
|
</div> |
|
103
|
|
|
<style> |
|
104
|
|
|
.jp-emblem { |
|
105
|
|
|
width: 25px; |
|
106
|
|
|
height: 25px; |
|
107
|
|
|
margin: .40em 1em 0 auto; |
|
108
|
|
|
float: left; |
|
109
|
|
|
} |
|
110
|
|
|
</style> |
|
111
|
|
|
<?php } |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Enqueue scripts for the notice |
|
115
|
|
|
*/ |
|
116
|
|
View Code Duplication |
function enqueue_idc_notice_files() { |
|
117
|
|
|
wp_enqueue_script( 'jetpack-idc-js', plugins_url( '_inc/idc-notice.js', JETPACK__PLUGIN_FILE ), |
|
118
|
|
|
array( 'jquery' ), JETPACK__VERSION, true ); |
|
119
|
|
|
wp_localize_script( |
|
120
|
|
|
'jetpack-idc-js', |
|
121
|
|
|
'idc', |
|
122
|
|
|
array( |
|
123
|
|
|
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
124
|
|
|
'jitm_nonce' => wp_create_nonce( 'jetpack-jitm-nonce' ), |
|
125
|
|
|
) |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
Jetpack_IDC::init(); |
|
131
|
|
|
|
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.