-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d02ac0
commit 1f8ab35
Showing
2 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Logger Class. | ||
* | ||
* @package Codeinwp/HyveLite | ||
*/ | ||
|
||
namespace ThemeIsle\HyveLite; | ||
|
||
/** | ||
* Class Logger | ||
*/ | ||
class Logger { | ||
|
||
/** | ||
* Tracking URL. | ||
* | ||
* @var string | ||
*/ | ||
const TRACK_URL = 'https://api.themeisle.com/track/'; | ||
|
||
/** | ||
* Send data to the server if the user has opted in. | ||
* | ||
* @param array $events Data to track. | ||
* @return void | ||
*/ | ||
public static function track( $events ) { | ||
if ( ! self::has_consent() ) { | ||
return; | ||
} | ||
|
||
try { | ||
$payload = []; | ||
|
||
$license = apply_filters( 'product_hyve_license_key', 'free' ); | ||
|
||
if ( 'free' !== $license ) { | ||
$license = wp_hash( $license ); | ||
} | ||
|
||
foreach ( $events as $event ) { | ||
$payload[] = [ | ||
'slug' => 'hyve', | ||
'site' => get_site_url(), | ||
'license' => $license, | ||
'data' => $event, | ||
]; | ||
} | ||
|
||
$args = [ | ||
'headers' => [ | ||
'Content-Type' => 'application/json', | ||
], | ||
'body' => wp_json_encode( $payload ), | ||
]; | ||
|
||
wp_remote_post( self::TRACK_URL, $args ); | ||
} finally { | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* Check if the user has consented to tracking. | ||
* | ||
* @return bool | ||
*/ | ||
public static function has_consent() { | ||
return 'yes' === get_option( 'hyve_lite_logger_flag', false ) || defined( 'HYVE_BASEFILE' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters