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
|
|
|
<?php } |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Enqueue scripts for the notice |
107
|
|
|
*/ |
108
|
|
|
function enqueue_idc_notice_files() { |
109
|
|
|
wp_enqueue_script( |
110
|
|
|
'jetpack-idc-js', |
111
|
|
|
plugins_url( '_inc/idc-notice.js', JETPACK__PLUGIN_FILE ), |
112
|
|
|
array( 'jquery' ), |
113
|
|
|
JETPACK__VERSION, |
114
|
|
|
true |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
wp_localize_script( |
118
|
|
|
'jetpack-idc-js', |
119
|
|
|
'idc', |
120
|
|
|
array( |
121
|
|
|
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
122
|
|
|
'idc_nonce' => wp_create_nonce( 'jetpack-idc-nonce' ), |
123
|
|
|
) |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
wp_enqueue_style( |
127
|
|
|
'jetpack-idc-css', |
128
|
|
|
plugins_url( 'css/jetpack-idc.css', JETPACK__PLUGIN_FILE ), |
129
|
|
|
array(), |
130
|
|
|
JETPACK__VERSION |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
Jetpack_IDC::init(); |
136
|
|
|
|
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.