When we launched the new telligent.com site we started with WordPress. It was an easy way to get a site up and running. While we eventually plan to move to Sitecore, we did want to integrate some community functionality with WordPress right awary. Specifically our trial experience that would allow people to setup trial groups in our community.

Side-note - this also gave us an excuse to work through the APIs on a non-.NET platform and we found a few improvements that we wanted to make along the way for 9.0 too. For example, adding in Ids and ContainerIds into the management panels to ensure developers could quickly find the ids they needed to work with:

WordPress is built with PHP and that meant to interact with the community we would need to write some code [insert knuckle crack]. PHP is powerful in its simplicity, but I have to admit it felt like stepping back to my ASP days when compared to working with ASP.NET.

You can find the functions library I wrote for calling into the Telligent REST API from WordPress in our GitHub repository:

WordPress / PHP function library


Using the function library is pretty simple:

1. API Key

First you'll need to get an API key for the user who will be calling into the community. There is plenty of documentation covering that. Enter the API key and username of the user to make API calls through in the telligent_functions.php file:

The following variable must be set for the library to communicate
with Telligent.
define("REST_PATH",     "https://community.telligent.com/api.ashx/v2/");
define("API_KEY",	"");
define("API_USER",	"");

2. API path

You will also need to define the path to your API in your community. Typically this will be:

[URL to your community]/api.ashx/v2/

3. Include telligent_functions.php in the appropriate PHP file:

include_once (get_template_directory()."/telligent_functions.php");

Once you've done this you can call into the various functions within the library. All of the functions rely on a method CallRestApi(). This API is reponsible for writing the appropriate REST headers as well as making the right HTTP POST or GET call to the server.

Let's look at one of the functions to look up a user by username:

* GetUserIdByName (GET)
* https://community.telligent.com/developers/w/developer85/46983.show-user-rest-endpoint
* Returns the ID of the newly created group
* username	Name of the user to lookup
function GetUserIdByName ($username) {
  $username = filter_var($username, FILTER_SANITIZE_STRING);
  $path = REST_PATH . 'users/' . $username . '.xml';

  // Call Rest API
  $result = CallRestApi($path);
  // Read the returned XML
  $xml = simplexml_load_string($result) or die("Error: Cannot create object");
  return $xml->User->Id;

This function accepts a single parameter, the username of a user and returns the numeric identifier. For example, 'rhoward' - my username - returns the numeric value for my account. In this case 1 -- privilidges of being the very first community member I guess :)

Next, the function builds the URL to make the HTTP Get request. In this case a $path is constructed:


Next we use the CallRestApi() method to execute the request path and return the populated xml. We walk the XML elements for the ID value and return that from the function.

You can browse through the rest of the functions in there and see how they use the REST API to call into the platform to perform various actions. If you have improvements or recommendations, we would love to see this PHP library expanded. Or better yet, we can implment a full SDK similar to our .NET SDK.