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