Wordpress integration with the DreamFactory REST API platform for user management
by Terence Bennett
• July 6, 2018
Noggle CEO Lars von Thienen has been indulging in a little island hopping lately. There aren’t many palm trees on these islands, but getting between them is a lot faster and safer now.
The new Noggle service allows controlled and privileged access across a broad information archipelago. It’s a peer-to-peer document network that’s fully indexed and searchable from a single, unified access point.
It’s a clever solution to distributed content that allows users to maintain their own islands of content, without having to store them in shared repositories. They simply tell Noggle where the docs are on their computer and they are exposed to their peer network; fully indexed, searchable, and sharable.
DreamFactory also served as a perfect bolt-on service to their existing Wordpress/Woocommerce portal. Von Thienen crafted a series of functions for integrating DreamFactory into Wordpress and has generously shared them with us.
This code assumes the existence of an existing DreamFactory instance along with a valid user with sufficient priveleges to access the user/system API.
General usage
Get a valid token with GetDreamfactoryToken()
Prepare the POST/GET body with parameters
Call CallDFAPI() with parameters
Define the correct Wordpress hooks and execution points
Get a valid Dreamfactory token
Here is a low level PHP function to get a current token for user management, via a Dreamfactory instance at YOURHOST. It returns a valid token for further processing or error.
function GetDreamfactoryToken()
{
$method = 'POST';
$url = 'https://[YOURHOST.COM]/api/v2/user/session';
This function is a general helper to call Dreamfactory REST APIs. It returns a decoded JSON string or error code and needs a valid session token and DreamFactory API key.
if ($response!=‘error')
{
// process response Array
$regemail= $response["resource"][0]["email"];
if ($regemail == $usertocheck)
{
//Yes, user is already in dreamfactory host, now do something…
}
}
Register/Invite a new user via Dreamfactory
//Get a session token to perform database actions for users
$token= GetDreamfactoryToken();
if ($response!='error')
{
// Success, user has been invited via DF host
//do something…
}
With these tools in place, von Thienen now has an effective solution for user management. But, the integration lets Wordpress and Woocommerce handle the front-end presentation layer and transaction.
Terence Bennett, CEO of DreamFactory, has a wealth of experience in government IT systems and Google Cloud. His impressive background includes being a former U.S. Navy Intelligence Officer and a former member of Google's Red Team. Prior to becoming CEO, he served as COO at DreamFactory Software.