diff --git a/README.txt b/README.txt
index daa2b1e..00c5762 100644
--- a/README.txt
+++ b/README.txt
@@ -7,7 +7,7 @@ License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html
Requires at least: 5.2.0
Tested up to: 5.8
-Stable tag: 2.0.8
+Stable tag: 2.0.9
The official plugin for integrating Open Web Analytics with WordPress based web sites and applications.
diff --git a/composer.json b/composer.json
index bd2043f..c6a0ea7 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
"sort-packages": true
},
"require": {
- "open-web-analytics/owa-php-sdk": "^1.0.3"
+ "open-web-analytics/owa-php-sdk": "^1.0.6"
},
"autoload": {
"psr-4": {
diff --git a/composer.lock b/composer.lock
index 9211c8f..feb15c6 100644
--- a/composer.lock
+++ b/composer.lock
@@ -75,16 +75,16 @@
},
{
"name": "guzzlehttp/promises",
- "version": "1.4.1",
+ "version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
- "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d"
+ "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d",
- "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
+ "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
"shasum": ""
},
"require": {
@@ -96,7 +96,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.4-dev"
+ "dev-master": "1.5-dev"
}
},
"autoload": {
@@ -112,30 +112,59 @@
"MIT"
],
"authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ },
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Tobias Nyholm",
+ "email": "tobias.nyholm@gmail.com",
+ "homepage": "https://github.com/Nyholm"
+ },
+ {
+ "name": "Tobias Schultze",
+ "email": "webmaster@tubo-world.de",
+ "homepage": "https://github.com/Tobion"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
- "time": "2021-03-07T09:25:29+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/GrahamCampbell",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/Nyholm",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-10-22T20:56:57+00:00"
},
{
"name": "guzzlehttp/psr7",
- "version": "1.8.2",
+ "version": "1.8.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
- "reference": "dc960a912984efb74d0a90222870c72c87f10c91"
+ "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/psr7/zipball/dc960a912984efb74d0a90222870c72c87f10c91",
- "reference": "dc960a912984efb74d0a90222870c72c87f10c91",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85",
+ "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85",
"shasum": ""
},
"require": {
@@ -172,13 +201,34 @@
"MIT"
],
"authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ },
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
+ {
+ "name": "George Mponos",
+ "email": "gmponos@gmail.com",
+ "homepage": "https://github.com/gmponos"
+ },
+ {
+ "name": "Tobias Nyholm",
+ "email": "tobias.nyholm@gmail.com",
+ "homepage": "https://github.com/Nyholm"
+ },
+ {
+ "name": "Márk Sági-Kazár",
+ "email": "mark.sagikazar@gmail.com",
+ "homepage": "https://github.com/sagikazarmark"
+ },
{
"name": "Tobias Schultze",
+ "email": "webmaster@tubo-world.de",
"homepage": "https://github.com/Tobion"
}
],
@@ -193,20 +243,34 @@
"uri",
"url"
],
- "time": "2021-04-26T09:17:50+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/GrahamCampbell",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/Nyholm",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-10-05T13:56:00+00:00"
},
{
"name": "open-web-analytics/owa-php-sdk",
- "version": "1.0.3",
+ "version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/Open-Web-Analytics/owa-php-sdk.git",
- "reference": "1005882724755f1dbf80d0da1f70c5b787a056f1"
+ "reference": "b4d7f0fb376c4e792eef160ecbd25cad035200e6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/Open-Web-Analytics/owa-php-sdk/zipball/1005882724755f1dbf80d0da1f70c5b787a056f1",
- "reference": "1005882724755f1dbf80d0da1f70c5b787a056f1",
+ "url": "https://api.github.com/repos/Open-Web-Analytics/owa-php-sdk/zipball/b4d7f0fb376c4e792eef160ecbd25cad035200e6",
+ "reference": "b4d7f0fb376c4e792eef160ecbd25cad035200e6",
"shasum": ""
},
"require": {
@@ -248,7 +312,7 @@
"type": "github"
}
],
- "time": "2021-09-18T03:55:30+00:00"
+ "time": "2021-11-09T00:56:02+00:00"
},
{
"name": "psr/http-message",
diff --git a/owa-plugin.php b/owa-plugin.php
index 2c24d76..7d1be9a 100644
--- a/owa-plugin.php
+++ b/owa-plugin.php
@@ -5,7 +5,7 @@
Plugin URI: http://www.openwebanalytics.com
Description: This plugin enables Wordpress blog owners to use the Open Web Analytics Framework.
Author: Peter Adams
-Version: 2.0.8
+Version: 2.0.9
Author URI: http://www.openwebanalytics.com
*/
@@ -179,7 +179,7 @@ function _init() {
// remove this if uneeded
if ( ! $this->isOwaReadyToTrack() ) {
- $this->adminMsgs[] = ['message' => 'Open Web Analytics requires a valid API Key, Endpoint, and Site ID before tracking can begin.', 'class' => 'notice-warning'];
+ $this->adminMsgs[] = ['message' => 'Open Web Analytics requires that you select a Site ID before tracking can begin.', 'class' => 'notice-warning'];
}
@@ -457,6 +457,15 @@ function isOwaReadyToTrack() {
}
+ function isOwaSdkReady() {
+
+ if ( $this->getOption( 'owaEndpoint' ) && $this->getOption( 'apiKey' ) && $this->getOption('authKey') ) {
+
+ return true;
+ }
+
+ }
+
function makeOwaInstanceValidationHash() {
@@ -467,18 +476,25 @@ function initOwaSdk() {
if( empty( $this->owaSdk ) ) {
- if ( $this->getOption( 'owaEndpoint' ) && $this->getOption( 'apiKey' ) ) {
+ if ( $this->getOption( 'owaEndpoint' ) && $this->getOption( 'apiKey' ) && $this->getOption( 'authKey' ) ) {
$config = [
//'cookie_domain' => 'your.domain.com',
- 'api_key' => $this->getOption('apiKey'),
+ 'credentials' => [
+ 'api_key' => $this->getOption('apiKey'),
+ 'auth_key' => $this->getOption('authKey')
+ ],
'instance_url' => $this->getOption('owaEndpoint')
];
$sdk = new OwaSdk\sdk( $config );
$this->owaSdk = $sdk;
+
+ } else {
+
+ $this->addNag('You must enter your OWA API key, Secret Auth key, and Endpoint settings.', 'notice-warning');
}
}
}
@@ -663,7 +679,11 @@ function createTrackedSiteForNewBlog($blog_id, $user_id, $domain, $path, $site_i
function trackNewBlogAction( $blog_id, $user_id, $domain, $path, $site_id ) {
$owa = $this->getOwaTrackerInstance();
- $owa->trackAction('Blog Created', 'WordPress', $domain);
+
+ if ( $owa ) {
+
+ $owa->trackAction('Blog Created', 'WordPress', $domain);
+ }
}
/**
@@ -678,8 +698,12 @@ function trackedPostEditAction( $post_id, $post ) {
}
$owa = $this->getOwaTrackerInstance();
- $label = $post->post_title;
- $owa->trackAction($post->post_type.' edited', 'WordPress', $label );
+
+ if ( $owa ) {
+
+ $label = $post->post_title;
+ $owa->trackAction($post->post_type.' edited', 'WordPress', $label );
+ }
}
/**
@@ -717,12 +741,15 @@ function trackPostAction( $new_status, $old_status, $post ) {
// track action
if ( $action_name ) {
-
$owa = $this->getOwaTrackerInstance();
- self::debug(sprintf("new: %s, old: %s, post: %s", $new_status, $old_status, print_r($post, true)));
- $label = $post->post_title;
- $owa->trackAction($action_name, 'WordPress', $label);
+ if ( $owa ) {
+
+ self::debug(sprintf("new: %s, old: %s, post: %s", $new_status, $old_status, print_r($post, true)));
+ $label = $post->post_title;
+
+ $owa->trackAction($action_name, 'WordPress', $label);
+ }
}
}
@@ -732,9 +759,13 @@ function trackPostAction( $new_status, $old_status, $post ) {
function trackAttachmentEditAction( $post_id ) {
$owa = $this->getOwaTrackerInstance();
- $post = get_post( $post_id );
- $label = $post->post_title;
- $owa->trackAction('Attachment Edit', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $post = get_post( $post_id );
+ $label = $post->post_title;
+ $owa->trackAction('Attachment Edit', 'WordPress', $label);
+ }
}
/**
@@ -743,9 +774,13 @@ function trackAttachmentEditAction( $post_id ) {
function trackAttachmentCreatedAction( $post_id ) {
$owa = $this->getOwaTrackerInstance();
- $post = get_post($post_id);
- $label = $post->post_title;
- $owa->trackAction('Attachment Created', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $post = get_post($post_id);
+ $label = $post->post_title;
+ $owa->trackAction('Attachment Created', 'WordPress', $label);
+ }
}
/**
@@ -754,14 +789,19 @@ function trackAttachmentCreatedAction( $post_id ) {
function trackUserRegistrationAction( $user_id ) {
$owa = $this->getOwaTrackerInstance();
- $user = get_userdata($user_id);
- if (!empty($user->first_name) && !empty($user->last_name)) {
- $label = $user->first_name.' '.$user->last_name;
- } else {
- $label = $user->display_name;
- }
- $owa->trackAction('User Registration', 'WordPress', $label);
+ if ( $owa ) {
+
+ $user = get_userdata($user_id);
+
+ if (!empty($user->first_name) && !empty($user->last_name)) {
+ $label = $user->first_name.' '.$user->last_name;
+ } else {
+ $label = $user->display_name;
+ }
+
+ $owa->trackAction('User Registration', 'WordPress', $label);
+ }
}
/**
@@ -770,8 +810,12 @@ function trackUserRegistrationAction( $user_id ) {
function trackUserLoginAction( $user_id ) {
$owa = $this->getOwaTrackerInstance();
- $label = $user_id;
- $owa->trackAction('User Login', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $label = $user_id;
+ $owa->trackAction('User Login', 'WordPress', $label);
+ }
}
/**
@@ -780,14 +824,18 @@ function trackUserLoginAction( $user_id ) {
function trackUserProfileUpdateAction( $user_id, $old_user_data = '' ) {
$owa = $this->getOwaTrackerInstance();
- $user = get_userdata($user_id);
- if (!empty($user->first_name) && !empty($user->last_name)) {
- $label = $user->first_name.' '.$user->last_name;
- } else {
- $label = $user->display_name;
- }
- $owa->trackAction('User Profile Update', 'WordPress', $label);
+ if ( $owa ) {
+
+ $user = get_userdata($user_id);
+ if (!empty($user->first_name) && !empty($user->last_name)) {
+ $label = $user->first_name.' '.$user->last_name;
+ } else {
+ $label = $user->display_name;
+ }
+
+ $owa->trackAction('User Profile Update', 'WordPress', $label);
+ }
}
/**
@@ -796,8 +844,12 @@ function trackUserProfileUpdateAction( $user_id, $old_user_data = '' ) {
function trackPasswordResetAction( $user ) {
$owa = $this->getOwaTrackerInstance();
- $label = $user->display_name;
- $owa->trackAction('User Password Reset', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $label = $user->display_name;
+ $owa->trackAction('User Password Reset', 'WordPress', $label);
+ }
}
/**
@@ -806,8 +858,12 @@ function trackPasswordResetAction( $user ) {
function trackTrackbackAction( $comment_id ) {
$owa = $this->getOwaTrackerInstance();
- $label = $comment_id;
- $owa->trackAction('Trackback', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $label = $comment_id;
+ $owa->trackAction('Trackback', 'WordPress', $label);
+ }
}
function trackCommentAction( $id, $comment_data = '' ) {
@@ -815,8 +871,12 @@ function trackCommentAction( $id, $comment_data = '' ) {
if ( $comment_data === 'approved' || $comment_data === 1 ) {
$owa = $this->getOwaTrackerInstance();
- $label = '';
- $owa->trackAction('Comment', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $label = '';
+ $owa->trackAction('Comment', 'WordPress', $label);
+ }
}
}
@@ -834,7 +894,11 @@ function trackCommentEditAction( $new_status, $old_status, $comment ) {
}
$owa = $this->getOwaTrackerInstance();
- $owa->trackAction('Comment Edit', 'WordPress', $label);
+
+ if ( $owa ) {
+
+ $owa->trackAction('Comment Edit', 'WordPress', $label);
+ }
}
}
@@ -847,16 +911,19 @@ function trackFeedRequest() {
self::debug('Tracking WordPress feed request');
$owa = $this->getOwaTrackerInstance();
+
+ if ( $owa ) {
- $event = $owa->makeEvent();
- // set event type
- $event->setEventType( 'base.feed_request' );
- // determine and set the type of feed
- $event->set( 'feed_format', esc_attr( get_query_var( 'feed' ) ) );
- $event->set( 'feed_subscription_id', esc_attr( get_query_var( $this->getOption( 'feed_subscription_param' ) ) ) );
- //$event->set( 'feed_subscription_id', $_GET['owa_sid'] );
- // track
- $owa->trackEvent( $event );
+ $event = $owa->makeEvent();
+ // set event type
+ $event->setEventType( 'base.feed_request' );
+ // determine and set the type of feed
+ $event->set( 'feed_format', esc_attr( get_query_var( 'feed' ) ) );
+ $event->set( 'feed_subscription_id', esc_attr( get_query_var( $this->getOption( 'feed_subscription_param' ) ) ) );
+ //$event->set( 'feed_subscription_id', $_GET['owa_sid'] );
+ // track
+ $owa->trackEvent( $event );
+ }
}
}
@@ -893,6 +960,22 @@ public function registerOptions() {
)
),
+ 'authKey' => array(
+
+ 'default_value' => '',
+ 'field' => array(
+ 'type' => 'text',
+ 'title' => 'Secret Auth Key',
+ 'page_name' => 'owa-wordpress',
+ 'section' => 'general',
+ 'description' => 'The secret OWA_AUTH_KEY found the owa-config.php file of your OWA Server instance.',
+ 'label_for' => 'OWA Auth Key',
+ 'length' => 70,
+ 'error_message' => ''
+ )
+ ),
+
+
'owaEndpoint' => array(
'default_value' => '',
@@ -1096,41 +1179,27 @@ public static function debug( $msg, $exit = false ) {
}
}
}
-
- function owaRemoteGet( $params ) {
-
- if ( $this->getOption('apiKey') && $this->getOption('owaEndpoint') ) {
- $params['owa_apiKey'] = $this->getOption('apiKey');
- $ret = wp_remote_get( $this->getOption('owaEndpoint').'api/?' . build_query( $params ) );
- self::debug('Got response from OWA endpoint' );
- if ( ! is_wp_error( $ret ) ) {
-
- $body = wp_remote_retrieve_body( $ret );
- $body = json_decode($body);
- return $body;
-
- } else {
-
- self::debug('REST call from WordPress Failed with params: '. print_r($params, true) );
- }
- }
- }
-
// @todo renovate this to use an SDK method
function getSitesFromOwa( $sites ) {
- $params = ['owa_module' => 'base', 'owa_version' => 'v1', 'owa_do' => 'sites' ];
- $sites = $this->owaRemoteGet( $params );
+ if ( $this->isOwaSdkready() ) {
+ $sites_client = $this->owaSdk->createSites();
+ $sites = $sites_client->listSites();
+ }
+
$list = [];
- foreach ( $sites->data as $site) {
+ if ( $sites ) {
- $list[ $site->properties->site_id->value ] = ['label' => sprintf('%s (%s)', $site->properties->site_id->value, $site->properties->domain->value), 'siteId' => $site->properties->site_id->value ];
- }
-
+ foreach ( $sites as $site) {
+
+ $list[ $site['properties']['site_id']['value'] ] = ['label' => sprintf('%s (%s)', $site['properties']['site_id']['value'], $site['properties']['domain']['value']), 'siteId' => $site['properties']['site_id']['value'] ];
+ }
+ }
+
return $list;
}
@@ -1138,11 +1207,14 @@ function getSitesFromOwa( $sites ) {
// get instance of OWA's tracker
public function getOwaTrackerInstance() {
- $tracker = $this->owaSdk->createTracker();
+ if ( $this->isOwaReadyToTrack() && ! empty( $this->owaSdk ) ) {
+
+ $tracker = $this->owaSdk->createTracker();
- $tracker->setSiteId( self::generateSiteId() );
+ $tracker->setSiteId( self::generateSiteId() );
- return $tracker;
+ return $tracker;
+ }
}
/**
diff --git a/src/settings/fields/select.php b/src/settings/fields/select.php
index d1565b5..d31842d 100644
--- a/src/settings/fields/select.php
+++ b/src/settings/fields/select.php
@@ -23,16 +23,26 @@ public function render( $attrs ) {
foreach ($options as $option) {
+ $v = '';
+
+ if (is_array( $option ) ) {
+
+ $v = $option[ $attrs['id'] ];
+ } else {
+
+ $v = $option;
+ }
+
$selected_attr = '';
- if ($option['siteId'] === $selected) {
+ if ($v === $selected) {
$selected_attr = 'selected';
}
$opts .= sprintf(
' \n',
- esc_attr( $option['siteId'] ),
+ esc_attr( $v ),
esc_html( $selected_attr ),
esc_html( $option['label'] )
);