@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | public function __construct() { |
29 | 29 | |
30 | 30 | // Authentication Actions |
31 | - add_action( 'wp_ajax_monsterinsights_maybe_authenticate', array( $this, 'maybe_authenticate' ) ); |
|
32 | - add_action( 'wp_ajax_monsterinsights_maybe_reauthenticate', array( $this, 'maybe_reauthenticate' ) ); |
|
33 | - add_action( 'wp_ajax_monsterinsights_maybe_verify', array( $this, 'maybe_verify' ) ); |
|
34 | - add_action( 'wp_ajax_monsterinsights_maybe_delete', array( $this, 'maybe_delete' ) ); |
|
31 | + add_action( 'wp_ajax_monsterinsights_maybe_authenticate', array( $this, 'maybe_authenticate' ) ); |
|
32 | + add_action( 'wp_ajax_monsterinsights_maybe_reauthenticate', array( $this, 'maybe_reauthenticate' ) ); |
|
33 | + add_action( 'wp_ajax_monsterinsights_maybe_verify', array( $this, 'maybe_verify' ) ); |
|
34 | + add_action( 'wp_ajax_monsterinsights_maybe_delete', array( $this, 'maybe_delete' ) ); |
|
35 | 35 | |
36 | - add_action( 'admin_init', array( $this, 'authenticate_listener' ) ); |
|
37 | - add_action( 'admin_init', array( $this, 'reauthenticate_listener' ) ); |
|
36 | + add_action( 'admin_init', array( $this, 'authenticate_listener' ) ); |
|
37 | + add_action( 'admin_init', array( $this, 'reauthenticate_listener' ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | - public function get_tt(){ |
|
40 | + public function get_tt() { |
|
41 | 41 | $tt = is_network_admin() ? get_site_option( 'monsterinsights_network_tt', '' ) : get_option( 'monsterinsights_site_tt', '' ); |
42 | 42 | if ( empty( $tt ) ) { |
43 | 43 | // if TT is empty, generate a new one, save it and then return it |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | return $tt; |
48 | 48 | } |
49 | 49 | |
50 | - public function rotate_tt(){ |
|
50 | + public function rotate_tt() { |
|
51 | 51 | $tt = $this->generate_tt(); |
52 | 52 | is_network_admin() ? update_site_option( 'monsterinsights_network_tt', $tt ) : update_option( 'monsterinsights_site_tt', $tt ); |
53 | 53 | } |
54 | 54 | |
55 | - public function generate_tt(){ |
|
55 | + public function generate_tt() { |
|
56 | 56 | return hash( 'sha512', wp_generate_password( 128, true, true ) . AUTH_SALT . uniqid( "", true ) ); |
57 | 57 | } |
58 | 58 | |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | return hash_equals( $tt, $passed_tt ); |
62 | 62 | } |
63 | 63 | |
64 | - public function maybe_authenticate(){ |
|
64 | + public function maybe_authenticate() { |
|
65 | 65 | |
66 | 66 | // Check nonce |
67 | 67 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
68 | 68 | |
69 | 69 | // current user can authenticate |
70 | 70 | if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { |
71 | - wp_send_json_error( array( 'message' => __( "You don't have permission to authenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
71 | + wp_send_json_error( array( 'message' => __( "You don't have permission to authenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | if ( ! empty( $_REQUEST['isnetwork'] ) && $_REQUEST['isnetwork'] ) { |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | // Only for Pro users, require a license key to be entered first so we can link to things. |
79 | 79 | $valid = is_network_admin() ? MonsterInsights()->license->is_network_licensed() : MonsterInsights()->license->is_site_licensed(); |
80 | 80 | if ( monsterinsights_is_pro_version() && ! $valid ) { |
81 | - wp_send_json_error( array( 'message' => __( "Cannot authenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
81 | + wp_send_json_error( array( 'message' => __( "Cannot authenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // we do not have a current auth |
85 | 85 | if ( ! $this->is_network_admin() && MonsterInsights()->auth->is_authed() ) { |
86 | - wp_send_json_error( array( 'message' => __( "Cannot authenticate. Please re-authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
86 | + wp_send_json_error( array( 'message' => __( "Cannot authenticate. Please re-authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
87 | 87 | } else if ( $this->is_network_admin() && MonsterInsights()->auth->is_network_authed() ) { |
88 | - wp_send_json_error( array( 'message' => __( "Cannot network authenticate. Please re-authenticate on the network settings panel.", 'google-analytics-for-wordpress' ) ) ); |
|
88 | + wp_send_json_error( array( 'message' => __( "Cannot network authenticate. Please re-authenticate on the network settings panel.", 'google-analytics-for-wordpress' ) ) ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $siteurl = add_query_arg( array( |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | - public function authenticate_listener(){ |
|
109 | + public function authenticate_listener() { |
|
110 | 110 | // Make sure it's for us |
111 | 111 | if ( empty( $_REQUEST['mi-oauth-action'] ) || $_REQUEST['mi-oauth-action'] !== 'auth' ) { |
112 | 112 | return; |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | // Make sure has required params |
127 | - if ( empty( $_REQUEST['key'] ) || |
|
128 | - empty( $_REQUEST['token'] ) || |
|
129 | - empty( $_REQUEST['ua'] ) || |
|
127 | + if ( empty( $_REQUEST['key'] ) || |
|
128 | + empty( $_REQUEST['token'] ) || |
|
129 | + empty( $_REQUEST['ua'] ) || |
|
130 | 130 | empty( $_REQUEST['viewname'] ) || |
131 | - empty( $_REQUEST['a'] ) || |
|
132 | - empty( $_REQUEST['w'] ) || |
|
131 | + empty( $_REQUEST['a'] ) || |
|
132 | + empty( $_REQUEST['w'] ) || |
|
133 | 133 | empty( $_REQUEST['p'] ) |
134 | 134 | ) { |
135 | 135 | return; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $where = $this->is_network_admin() ? 'network' : 'site'; |
167 | 167 | MonsterInsights()->reporting->delete_aggregate_data( $where ); |
168 | 168 | |
169 | - $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network' ) : admin_url( 'admin.php?page=monsterinsights_settings' ) ; |
|
169 | + $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network' ) : admin_url( 'admin.php?page=monsterinsights_settings' ); |
|
170 | 170 | $url = add_query_arg( array( |
171 | 171 | 'mi_action' => 'auth', |
172 | 172 | 'success' => 'true', |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | exit; |
176 | 176 | } |
177 | 177 | |
178 | - public function maybe_reauthenticate(){ |
|
178 | + public function maybe_reauthenticate() { |
|
179 | 179 | |
180 | 180 | // Check nonce |
181 | 181 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
182 | 182 | |
183 | 183 | // current user can authenticate |
184 | 184 | if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { |
185 | - wp_send_json_error( array( 'message' => __( "You don't have permission to re-authenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
185 | + wp_send_json_error( array( 'message' => __( "You don't have permission to re-authenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | if ( ! empty( $_REQUEST['isnetwork'] ) && $_REQUEST['isnetwork'] ) { |
@@ -192,14 +192,14 @@ discard block |
||
192 | 192 | // Only for Pro users, require a license key to be entered first so we can link to things. |
193 | 193 | $valid = is_network_admin() ? MonsterInsights()->license->is_network_licensed() : MonsterInsights()->license->is_site_licensed(); |
194 | 194 | if ( monsterinsights_is_pro_version() && ! $valid ) { |
195 | - wp_send_json_error( array( 'message' => __( "Cannot re-authenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
195 | + wp_send_json_error( array( 'message' => __( "Cannot re-authenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // we do have a current auth |
199 | 199 | if ( ! $this->is_network_admin() && ! MonsterInsights()->auth->is_authed() ) { |
200 | - wp_send_json_error( array( 'message' => __( "Cannot re-authenticate. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
200 | + wp_send_json_error( array( 'message' => __( "Cannot re-authenticate. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
201 | 201 | } else if ( $this->is_network_admin() && ! MonsterInsights()->auth->is_network_authed() ) { |
202 | - wp_send_json_error( array( 'message' => __( "Cannot re-authenticate the network. Please authenticate on the network settings panel.", 'google-analytics-for-wordpress' ) ) ); |
|
202 | + wp_send_json_error( array( 'message' => __( "Cannot re-authenticate the network. Please authenticate on the network settings panel.", 'google-analytics-for-wordpress' ) ) ); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | $siteurl = add_query_arg( array( |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | wp_send_json_success( array( 'redirect' => $siteurl ) ); |
223 | 223 | } |
224 | 224 | |
225 | - public function reauthenticate_listener(){ |
|
225 | + public function reauthenticate_listener() { |
|
226 | 226 | // Make sure it's for us |
227 | 227 | if ( empty( $_REQUEST['mi-oauth-action'] ) || $_REQUEST['mi-oauth-action'] !== 'reauth' ) { |
228 | 228 | return; |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | |
241 | 241 | // Make sure has required params |
242 | 242 | if ( |
243 | - empty( $_REQUEST['ua'] ) || |
|
243 | + empty( $_REQUEST['ua'] ) || |
|
244 | 244 | empty( $_REQUEST['viewname'] ) || |
245 | - empty( $_REQUEST['a'] ) || |
|
246 | - empty( $_REQUEST['w'] ) || |
|
245 | + empty( $_REQUEST['a'] ) || |
|
246 | + empty( $_REQUEST['w'] ) || |
|
247 | 247 | empty( $_REQUEST['p'] ) |
248 | 248 | ) { |
249 | 249 | return; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $where = $this->is_network_admin() ? 'network' : 'site'; |
282 | 282 | MonsterInsights()->reporting->delete_aggregate_data( $where ); |
283 | 283 | |
284 | - $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network' ) : admin_url( 'admin.php?page=monsterinsights_settings' ) ; |
|
284 | + $url = $this->is_network_admin() ? network_admin_url( 'admin.php?page=monsterinsights_network' ) : admin_url( 'admin.php?page=monsterinsights_settings' ); |
|
285 | 285 | $url = add_query_arg( array( |
286 | 286 | 'mi_action' => 'reauth', |
287 | 287 | 'success' => 'true', |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | exit; |
291 | 291 | } |
292 | 292 | |
293 | - public function maybe_verify(){ |
|
293 | + public function maybe_verify() { |
|
294 | 294 | |
295 | 295 | // Check nonce |
296 | 296 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
297 | 297 | |
298 | 298 | // current user can verify |
299 | 299 | if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { |
300 | - wp_send_json_error( array( 'message' => __( "You don't have permission to verify MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
300 | + wp_send_json_error( array( 'message' => __( "You don't have permission to verify MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | if ( ! empty( $_REQUEST['isnetwork'] ) && $_REQUEST['isnetwork'] ) { |
@@ -306,25 +306,25 @@ discard block |
||
306 | 306 | |
307 | 307 | // we have an auth to verify |
308 | 308 | if ( $this->is_network_admin() && ! MonsterInsights()->auth->is_network_authed() ) { |
309 | - wp_send_json_error( array( 'message' => __( "Cannot verify. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
309 | + wp_send_json_error( array( 'message' => __( "Cannot verify. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
310 | 310 | } else if ( ! $this->is_network_admin() && ! MonsterInsights()->auth->is_authed() ) { |
311 | - wp_send_json_error( array( 'message' => __( "Cannot verify. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
311 | + wp_send_json_error( array( 'message' => __( "Cannot verify. Please authenticate.", 'google-analytics-for-wordpress' ) ) ); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | $valid = is_network_admin() ? MonsterInsights()->license->is_network_licensed() : MonsterInsights()->license->is_site_licensed(); |
315 | 315 | if ( monsterinsights_is_pro_version() && ! $valid ) { |
316 | - wp_send_json_error( array( 'message' => __( "Cannot verify. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
316 | + wp_send_json_error( array( 'message' => __( "Cannot verify. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $worked = $this->verify_auth(); |
320 | - if ( $worked && ! is_wp_error( $worked ) ) { |
|
320 | + if ( $worked && ! is_wp_error( $worked ) ) { |
|
321 | 321 | wp_send_json_success( array( 'message' => __( "Successfully verified.", 'google-analytics-for-wordpress' ) ) ); |
322 | 322 | } else { |
323 | 323 | wp_send_json_error( array( 'message' => __( "Could not verify.", 'google-analytics-for-wordpress' ) ) ); |
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | - public function verify_auth( $credentials = array() ){ |
|
327 | + public function verify_auth( $credentials = array() ) { |
|
328 | 328 | $creds = ! empty( $credentials ) ? $credentials : ( $this->is_network_admin() ? MonsterInsights()->auth->get_network_analytics_profile( true ) : MonsterInsights()->auth->get_analytics_profile( true ) ); |
329 | 329 | |
330 | 330 | if ( empty( $creds['key'] ) ) { |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
344 | - public function maybe_delete(){ |
|
344 | + public function maybe_delete() { |
|
345 | 345 | |
346 | 346 | // Check nonce |
347 | 347 | check_ajax_referer( 'mi-admin-nonce', 'nonce' ); |
348 | 348 | |
349 | 349 | // current user can delete |
350 | 350 | if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { |
351 | - wp_send_json_error( array( 'message' => __( "You don't have permission to deauthenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
351 | + wp_send_json_error( array( 'message' => __( "You don't have permission to deauthenticate MonsterInsights.", 'google-analytics-for-wordpress' ) ) ); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | if ( ! empty( $_REQUEST['isnetwork'] ) && $_REQUEST['isnetwork'] ) { |
@@ -357,20 +357,20 @@ discard block |
||
357 | 357 | |
358 | 358 | // we have an auth to delete |
359 | 359 | if ( $this->is_network_admin() && ! MonsterInsights()->auth->is_network_authed() ) { |
360 | - wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. You are not currently authed.", 'google-analytics-for-wordpress' ) ) ); |
|
360 | + wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. You are not currently authed.", 'google-analytics-for-wordpress' ) ) ); |
|
361 | 361 | } else if ( ! $this->is_network_admin() && ! MonsterInsights()->auth->is_authed() ) { |
362 | - wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. You are not currently authed.", 'google-analytics-for-wordpress' ) ) ); |
|
362 | + wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. You are not currently authed.", 'google-analytics-for-wordpress' ) ) ); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | $valid = is_network_admin() ? MonsterInsights()->license->is_network_licensed() : MonsterInsights()->license->is_site_licensed(); |
366 | 366 | if ( monsterinsights_is_pro_version() && ! $valid ) { |
367 | - wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
367 | + wp_send_json_error( array( 'message' => __( "Cannot deauthenticate. Please enter a valid, active license key for MonsterInsights Pro into the settings.", 'google-analytics-for-wordpress' ) ) ); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $force = ! empty( $_REQUEST['forcedelete'] ) && $_REQUEST['forcedelete'] === 'true'; |
371 | 371 | |
372 | 372 | $worked = $this->delete_auth( $force ); |
373 | - if ( $worked && ! is_wp_error( $worked ) ) { |
|
373 | + if ( $worked && ! is_wp_error( $worked ) ) { |
|
374 | 374 | wp_send_json_success( array( 'message' => __( "Successfully deauthenticated.", 'google-analytics-for-wordpress' ) ) ); |
375 | 375 | } else { |
376 | 376 | if ( $force ) { |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - public function delete_auth( $force = false ){ |
|
384 | + public function delete_auth( $force = false ) { |
|
385 | 385 | if ( $this->is_network_admin() && ! MonsterInsights()->auth->is_network_authed() ) { |
386 | 386 | return false; |
387 | 387 | } else if ( ! $this->is_network_admin() && ! MonsterInsights()->auth->is_authed() ) { |
@@ -425,6 +425,6 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | public function get_sitei() { |
428 | - return mb_strimwidth( rtrim( ltrim( sanitize_text_field( preg_replace('/[^a-zA-Z0-9]/', '', AUTH_KEY . SECURE_AUTH_KEY . LOGGED_IN_KEY ) ) ) ), 0, 30 ); |
|
428 | + return mb_strimwidth( rtrim( ltrim( sanitize_text_field( preg_replace( '/[^a-zA-Z0-9]/', '', AUTH_KEY . SECURE_AUTH_KEY . LOGGED_IN_KEY ) ) ) ), 0, 30 ); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | \ No newline at end of file |