Version Description
Download this release
Release Info
| Developer | joostdevalk |
| Plugin | |
| Version | 5.0.3 |
| Comparing to | |
| See all releases | |
Code changes from version 5.0.2 to 5.0.3
- admin/class-admin.php +76 -61
- frontend/class-ga-js.php +4 -7
- frontend/class-universal.php +4 -6
- includes/class-options.php +23 -12
admin/class-admin.php
CHANGED
|
@@ -2,9 +2,6 @@
|
|
| 2 |
/**
|
| 3 |
* This class is for the backend, extendable for all child classes
|
| 4 |
*/
|
| 5 |
-
if ( ! function_exists( 'wp_verify_nonce' ) ) {
|
| 6 |
-
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
| 7 |
-
}
|
| 8 |
|
| 9 |
require_once plugin_dir_path( __FILE__ ) . '/wp-gdata/wp-gdata.php';
|
| 10 |
|
|
@@ -49,7 +46,16 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 49 |
}
|
| 50 |
|
| 51 |
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
if ( isset( $_POST['ga-form-settings'] ) && wp_verify_nonce( $_POST['yoast_ga_nonce'], 'save_settings' ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
// Post submitted and verified with our nonce
|
| 54 |
$this->save_settings( $_POST );
|
| 55 |
|
|
@@ -69,7 +75,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 69 |
* Throw a warning if no UA code is set.
|
| 70 |
*/
|
| 71 |
public function config_warning() {
|
| 72 |
-
echo '<div class="error"><p>' . sprintf( __( 'Please configure your %
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
|
@@ -428,18 +434,16 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 428 |
// Eqneue the chosen js file
|
| 429 |
wp_enqueue_script( 'chosen_js', plugins_url( 'js/chosen.jquery.min.js', GAWP_FILE ), array(), false, true );
|
| 430 |
|
| 431 |
-
$option_name = '
|
| 432 |
$options = get_option( $option_name );
|
| 433 |
$return = array();
|
| 434 |
|
| 435 |
if ( ! empty ( $options['ga_token'] ) ) {
|
| 436 |
-
$token = $options['ga_token'];
|
| 437 |
-
|
| 438 |
$args = array(
|
| 439 |
'scope' => 'https://www.googleapis.com/auth/analytics.readonly',
|
| 440 |
'xoauth_displayname' => 'Google Analytics for WordPress by Yoast',
|
| 441 |
);
|
| 442 |
-
$access_token = $options['
|
| 443 |
$gdata = new WP_Gdata( $args, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
|
| 444 |
|
| 445 |
$response = $gdata->get( 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles' );
|
|
@@ -447,50 +451,30 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 447 |
$response = wp_remote_retrieve_body( $response );
|
| 448 |
|
| 449 |
if ( $http_code == 200 ) {
|
| 450 |
-
$options['
|
| 451 |
'response' => array( 'code' => $http_code ),
|
| 452 |
'body' => $response
|
| 453 |
);
|
| 454 |
-
$options
|
| 455 |
-
|
|
|
|
| 456 |
}
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
if ( ! empty( $xml_reader->entry ) ) {
|
| 461 |
|
| 462 |
-
|
| 463 |
|
| 464 |
-
|
| 465 |
-
if ( $xml_reader->link['href'] == 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles' ) {
|
| 466 |
-
foreach ( $xml_reader->entry AS $entry ) {
|
| 467 |
-
$ns = $entry->getNamespaces( true );
|
| 468 |
-
$properties = $entry->children( $ns['dxp'] )->property;
|
| 469 |
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
}
|
| 473 |
-
|
| 474 |
-
if ( isset ( $properties[2]->attributes()->value ) ) {
|
| 475 |
-
$title = (string) trim( $properties[2]->attributes()->value );
|
| 476 |
-
}
|
| 477 |
-
|
| 478 |
-
if ( ! empty( $ua ) && ! empty( $title ) ) {
|
| 479 |
-
$ga_accounts[] = array(
|
| 480 |
-
'ua' => $ua,
|
| 481 |
-
'title' => $title,
|
| 482 |
-
);
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
}
|
| 486 |
-
} else {
|
| 487 |
-
if ( $xml_reader->link['href'] == 'https://www.google.com/analytics/feeds/accounts/default' ) {
|
| 488 |
foreach ( $xml_reader->entry AS $entry ) {
|
| 489 |
$ns = $entry->getNamespaces( true );
|
| 490 |
$properties = $entry->children( $ns['dxp'] )->property;
|
| 491 |
|
| 492 |
-
if ( isset ( $properties[
|
| 493 |
-
$ua = (string) trim( $properties[
|
| 494 |
}
|
| 495 |
|
| 496 |
if ( isset ( $properties[2]->attributes()->value ) ) {
|
|
@@ -505,19 +489,44 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 505 |
}
|
| 506 |
|
| 507 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
}
|
| 509 |
-
}
|
| 510 |
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
|
|
|
| 520 |
}
|
|
|
|
|
|
|
| 521 |
}
|
| 522 |
}
|
| 523 |
|
|
@@ -542,24 +551,24 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 542 |
*/
|
| 543 |
private function connect_with_google_analytics() {
|
| 544 |
|
| 545 |
-
$option_name = '
|
| 546 |
|
| 547 |
if ( isset( $_REQUEST['ga_oauth_callback'] ) ) {
|
| 548 |
$o = get_option( $option_name );
|
| 549 |
-
if ( isset( $o['
|
| 550 |
$gdata = new WP_GData(
|
| 551 |
array(
|
| 552 |
'scope' => 'https://www.google.com/analytics/feeds/',
|
| 553 |
'xoauth_displayname' => 'Google Analytics by Yoast'
|
| 554 |
),
|
| 555 |
-
$o['
|
| 556 |
-
$o['
|
| 557 |
);
|
| 558 |
|
| 559 |
-
$o['
|
| 560 |
-
unset( $o['
|
| 561 |
-
unset( $o['
|
| 562 |
-
$o['ga_token'] = $o['
|
| 563 |
}
|
| 564 |
|
| 565 |
update_option( $option_name, $o );
|
|
@@ -580,10 +589,16 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
| 580 |
$request_token = $gdata->get_request_token( $oauth_callback );
|
| 581 |
|
| 582 |
$options = get_option( $option_name );
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
update_option( $option_name, $options );
|
| 588 |
|
| 589 |
wp_redirect( $gdata->get_authorize_url( $request_token ) );
|
| 2 |
/**
|
| 3 |
* This class is for the backend, extendable for all child classes
|
| 4 |
*/
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
require_once plugin_dir_path( __FILE__ ) . '/wp-gdata/wp-gdata.php';
|
| 7 |
|
| 46 |
}
|
| 47 |
|
| 48 |
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
|
| 49 |
+
|
| 50 |
+
if ( ! function_exists( 'wp_verify_nonce' ) ) {
|
| 51 |
+
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
if ( isset( $_POST['ga-form-settings'] ) && wp_verify_nonce( $_POST['yoast_ga_nonce'], 'save_settings' ) ) {
|
| 55 |
+
if ( ! isset ( $_POST['ignore_users'] ) ) {
|
| 56 |
+
$_POST['ignore_users'] = array();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
// Post submitted and verified with our nonce
|
| 60 |
$this->save_settings( $_POST );
|
| 61 |
|
| 75 |
* Throw a warning if no UA code is set.
|
| 76 |
*/
|
| 77 |
public function config_warning() {
|
| 78 |
+
echo '<div class="error"><p>' . sprintf( __( 'Please configure your %sGoogle Analytics settings%s!', 'google-analytics-for-wordpress' ), '<a href="' . admin_url( 'admin.php?page=yst_ga_settings' ) . '">', '</a>' ) . '</p></div>';
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
| 434 |
// Eqneue the chosen js file
|
| 435 |
wp_enqueue_script( 'chosen_js', plugins_url( 'js/chosen.jquery.min.js', GAWP_FILE ), array(), false, true );
|
| 436 |
|
| 437 |
+
$option_name = 'yst_ga_api';
|
| 438 |
$options = get_option( $option_name );
|
| 439 |
$return = array();
|
| 440 |
|
| 441 |
if ( ! empty ( $options['ga_token'] ) ) {
|
|
|
|
|
|
|
| 442 |
$args = array(
|
| 443 |
'scope' => 'https://www.googleapis.com/auth/analytics.readonly',
|
| 444 |
'xoauth_displayname' => 'Google Analytics for WordPress by Yoast',
|
| 445 |
);
|
| 446 |
+
$access_token = $options['ga_oauth']['access_token'];
|
| 447 |
$gdata = new WP_Gdata( $args, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
|
| 448 |
|
| 449 |
$response = $gdata->get( 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles' );
|
| 451 |
$response = wp_remote_retrieve_body( $response );
|
| 452 |
|
| 453 |
if ( $http_code == 200 ) {
|
| 454 |
+
$options['ga_api_response'] = array(
|
| 455 |
'response' => array( 'code' => $http_code ),
|
| 456 |
'body' => $response
|
| 457 |
);
|
| 458 |
+
update_option( $option_name, $options );
|
| 459 |
+
} else {
|
| 460 |
+
return $return;
|
| 461 |
}
|
| 462 |
|
| 463 |
+
try {
|
| 464 |
+
$xml_reader = new SimpleXMLElement( $options['ga_api_response']['body'] );
|
|
|
|
| 465 |
|
| 466 |
+
if ( ! empty( $xml_reader->entry ) ) {
|
| 467 |
|
| 468 |
+
$ga_accounts = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
|
| 470 |
+
// Check whether the feed output is the new one, first set, or the old one, second set.
|
| 471 |
+
if ( $xml_reader->link['href'] == 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles' ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
foreach ( $xml_reader->entry AS $entry ) {
|
| 473 |
$ns = $entry->getNamespaces( true );
|
| 474 |
$properties = $entry->children( $ns['dxp'] )->property;
|
| 475 |
|
| 476 |
+
if ( isset ( $properties[1]->attributes()->value ) ) {
|
| 477 |
+
$ua = (string) trim( $properties[1]->attributes()->value );
|
| 478 |
}
|
| 479 |
|
| 480 |
if ( isset ( $properties[2]->attributes()->value ) ) {
|
| 489 |
}
|
| 490 |
|
| 491 |
}
|
| 492 |
+
} else {
|
| 493 |
+
if ( $xml_reader->link['href'] == 'https://www.google.com/analytics/feeds/accounts/default' ) {
|
| 494 |
+
foreach ( $xml_reader->entry AS $entry ) {
|
| 495 |
+
$ns = $entry->getNamespaces( true );
|
| 496 |
+
$properties = $entry->children( $ns['dxp'] )->property;
|
| 497 |
+
|
| 498 |
+
if ( isset ( $properties[3]->attributes()->value ) ) {
|
| 499 |
+
$ua = (string) trim( $properties[3]->attributes()->value );
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
if ( isset ( $properties[2]->attributes()->value ) ) {
|
| 503 |
+
$title = (string) trim( $properties[2]->attributes()->value );
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
if ( ! empty( $ua ) && ! empty( $title ) ) {
|
| 507 |
+
$ga_accounts[] = array(
|
| 508 |
+
'ua' => $ua,
|
| 509 |
+
'title' => $title,
|
| 510 |
+
);
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
}
|
|
|
|
| 516 |
|
| 517 |
+
if ( is_array( $ga_accounts ) ) {
|
| 518 |
+
usort( $ga_accounts, array( $this, 'sort_profiles' ) );
|
| 519 |
+
}
|
| 520 |
|
| 521 |
+
foreach ( $ga_accounts as $key => $ga_account ) {
|
| 522 |
+
$return[] = array(
|
| 523 |
+
'id' => $ga_account['ua'],
|
| 524 |
+
'name' => $ga_account['title'] . ' (' . $ga_account['ua'] . ')',
|
| 525 |
+
);
|
| 526 |
+
}
|
| 527 |
}
|
| 528 |
+
} catch ( Exception $e ) {
|
| 529 |
+
|
| 530 |
}
|
| 531 |
}
|
| 532 |
|
| 551 |
*/
|
| 552 |
private function connect_with_google_analytics() {
|
| 553 |
|
| 554 |
+
$option_name = 'yst_ga_api';
|
| 555 |
|
| 556 |
if ( isset( $_REQUEST['ga_oauth_callback'] ) ) {
|
| 557 |
$o = get_option( $option_name );
|
| 558 |
+
if ( isset( $o['ga_oauth']['oauth_token'] ) && $o['ga_oauth']['oauth_token'] == $_REQUEST['oauth_token'] ) {
|
| 559 |
$gdata = new WP_GData(
|
| 560 |
array(
|
| 561 |
'scope' => 'https://www.google.com/analytics/feeds/',
|
| 562 |
'xoauth_displayname' => 'Google Analytics by Yoast'
|
| 563 |
),
|
| 564 |
+
$o['ga_oauth']['oauth_token'],
|
| 565 |
+
$o['ga_oauth']['oauth_token_secret']
|
| 566 |
);
|
| 567 |
|
| 568 |
+
$o['ga_oauth']['access_token'] = $gdata->get_access_token( $_REQUEST['oauth_verifier'] );
|
| 569 |
+
unset( $o['ga_oauth']['oauth_token'] );
|
| 570 |
+
unset( $o['ga_oauth']['oauth_token_secret'] );
|
| 571 |
+
$o['ga_token'] = $o['ga_oauth']['access_token']['oauth_token'];
|
| 572 |
}
|
| 573 |
|
| 574 |
update_option( $option_name, $o );
|
| 589 |
$request_token = $gdata->get_request_token( $oauth_callback );
|
| 590 |
|
| 591 |
$options = get_option( $option_name );
|
| 592 |
+
|
| 593 |
+
if ( is_array( $options ) ) {
|
| 594 |
+
unset( $options['ga_token'] );
|
| 595 |
+
if ( is_array( $options['ga_oauth'] ) ) {
|
| 596 |
+
unset( $options['ga_oauth']['access_token'] );
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
$options['ga_oauth']['oauth_token'] = $request_token['oauth_token'];
|
| 601 |
+
$options['ga_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
|
| 602 |
update_option( $option_name, $options );
|
| 603 |
|
| 604 |
wp_redirect( $gdata->get_authorize_url( $request_token ) );
|
frontend/class-ga-js.php
CHANGED
|
@@ -51,13 +51,10 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
|
|
| 51 |
$options['allowanchor'] = false;
|
| 52 |
}
|
| 53 |
|
| 54 |
-
$
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
if ( ! empty( $options['manual_ua_code_field'] ) && ! empty( $options['manual_ua_code'] ) ) {
|
| 60 |
-
$ua_code = $options['manual_ua_code_field'];
|
| 61 |
}
|
| 62 |
|
| 63 |
$gaq_push[] = "'_setAccount', '" . $ua_code . "'";
|
| 51 |
$options['allowanchor'] = false;
|
| 52 |
}
|
| 53 |
|
| 54 |
+
global $Yoast_GA_Options;
|
| 55 |
+
$ua_code = $Yoast_GA_Options->get_tracking_code();
|
| 56 |
+
if ( is_null( $ua_code ) ) {
|
| 57 |
+
return;
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
|
| 60 |
$gaq_push[] = "'_setAccount', '" . $ua_code . "'";
|
frontend/class-universal.php
CHANGED
|
@@ -51,14 +51,12 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
|
|
| 51 |
$options['allowanchor'] = false;
|
| 52 |
}
|
| 53 |
|
| 54 |
-
$
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
-
if ( ! empty( $options['manual_ua_code_field'] ) && ! empty( $options['manual_ua_code'] ) ) {
|
| 60 |
-
$ua_code = $options['manual_ua_code_field'];
|
| 61 |
-
}
|
| 62 |
|
| 63 |
// Set tracking code here
|
| 64 |
if ( ! empty( $ua_code ) ) {
|
| 51 |
$options['allowanchor'] = false;
|
| 52 |
}
|
| 53 |
|
| 54 |
+
global $Yoast_GA_Options;
|
| 55 |
+
$ua_code = $Yoast_GA_Options->get_tracking_code();
|
| 56 |
+
if ( is_null( $ua_code ) ) {
|
| 57 |
+
return;
|
| 58 |
}
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
// Set tracking code here
|
| 62 |
if ( ! empty( $ua_code ) ) {
|
includes/class-options.php
CHANGED
|
@@ -56,18 +56,23 @@ if ( ! class_exists( 'Yoast_GA_Options' ) ) {
|
|
| 56 |
if ( ! isset( $this->options['ga_general']['version'] ) && is_null( $this->get_tracking_code() ) ) {
|
| 57 |
$old_options = get_option( 'Yoast_Google_Analytics' );
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
delete_option( 'Yoast_Google_Analytics' );
|
| 73 |
}
|
|
@@ -79,6 +84,12 @@ if ( ! class_exists( 'Yoast_GA_Options' ) ) {
|
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
// Set to the current version now that we've done all needed upgrades
|
| 83 |
$this->options['ga_general']['version'] = GAWP_VERSION;
|
| 84 |
|
| 56 |
if ( ! isset( $this->options['ga_general']['version'] ) && is_null( $this->get_tracking_code() ) ) {
|
| 57 |
$old_options = get_option( 'Yoast_Google_Analytics' );
|
| 58 |
|
| 59 |
+
if ( isset( $old_options ) && is_array( $old_options ) ) {
|
| 60 |
+
if ( isset( $old_options['uastring'] ) && '' !== trim( $old_options['uastring'] ) ) {
|
| 61 |
+
// Save UA as manual UA, instead of saving all the old GA crap
|
| 62 |
+
$this->options['ga_general']['manual_ua_code'] = 1;
|
| 63 |
+
$this->options['ga_general']['manual_ua_code_field'] = $old_options['uastring'];
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// Other settings
|
| 67 |
+
$this->options['ga_general']['allow_anchor'] = $old_options['allowanchor'];
|
| 68 |
+
$this->options['ga_general']['add_allow_linker'] = $old_options['allowlinker'];
|
| 69 |
+
$this->options['ga_general']['anonymous_data'] = $old_options['anonymizeip'];
|
| 70 |
+
$this->options['ga_general']['track_outbound'] = $old_options['trackoutbound'];
|
| 71 |
+
$this->options['ga_general']['track_internal_as_outbound'] = $old_options['internallink'];
|
| 72 |
+
$this->options['ga_general']['track_internal_as_label'] = $old_options['internallinklabel'];
|
| 73 |
+
$this->options['ga_general']['extensions_of_files'] = $old_options['dlextensions'];
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
|
| 77 |
delete_option( 'Yoast_Google_Analytics' );
|
| 78 |
}
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
+
// Check is API option already exists - if not add it
|
| 88 |
+
$yst_ga_api = get_option('yst_ga_api');
|
| 89 |
+
if($yst_ga_api === false) {
|
| 90 |
+
add_option( 'yst_ga_api', array(), '', 'no' );
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
// Set to the current version now that we've done all needed upgrades
|
| 94 |
$this->options['ga_general']['version'] = GAWP_VERSION;
|
| 95 |
|
