Skip to content

Instantly share code, notes, and snippets.

@michaloo
Last active September 18, 2017 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaloo/c349b41ab7a37997a66d327f72124522 to your computer and use it in GitHub Desktop.
Save michaloo/c349b41ab7a37997a66d327f72124522 to your computer and use it in GitHub Desktop.
Hull Client + Wordpress
<?php
// this is main theme functions.php file
// first require Hull_Client files,
// if you are using Composer following line enable autoload:
require "vendor/autoload.php";
function hull_init_client() {
$current_user = wp_get_current_user();
if ($current_user->ID) {
$hull = new Hull_Client(array(
'hull' => array(
'host' => 'org-url',
'appId' => 'platform-id',
'appSecret' => 'platform-secret'
)
));
$userData = array(
'email' => $current_user->user_email,
'external_id' => $current_user->ID
);
?>
<script id="hull-js-sdk"
access-token="<?php echo $hull->userToken($userData) ?>"
org-url="<?php echo $hull->host ?>"
platform-id="<?php echo $hull->appId ?>"
src="https://js.hull.io/0.10.0/hull.js.gz" async></script>
<?php
}
}
add_action( 'wp_enqueue_scripts', 'hull_init_client' );
@lkraav
Copy link

lkraav commented Sep 16, 2017

Hmmm. Does this cause every logged in pageview to generate a remote token API request? This does not sound sensible. Can the access token be cached?

@unity
Copy link

unity commented Sep 18, 2017

Hey @lkraav - The Hull client doesn't generate a remote token api request - It generates a JWT, signed with the appSecret. No remote calls there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment