Create a bbBolt Client

There are two components to the bbBolt Client – the bbBolt Client Class and the bbBolt Client UI class. The first of these creates an object for storing the settings specific to your Support System, such as the server’s URL. The second is a singleton class which is used to setup a single bbBolt interface for all bbBolt Clients active on a website.

To provide a bbBolt Client with your plugin, you must do two things:

  1. Include the bbBolt library in your plugin’s folder
  2. Call the register_bbbolt_client() function.

Including the bbBolt Library in your Plugin

For best results, copy the entire bbbolt directory into your plugins folder. This will ensure you have the require images and class files for running a bbBolt Client with your plugin and will also make it easier to upgrade to future versions.

Once copied, remove the example-client.php and example-server.php files as these act only as a guide to developers for how to create a client and server.

Now the files are in your plugin’s directory, you must include them:

require_once( 'bbbolt-client.class.php' );

The Register bbBolt Client Function

The bbBolt Client class file includes a helper function for registering a new client.

register_bbbolt_client( $name, $args );

To create your bbBolt client, you must call this function and pass it two parameters: $name & $args.

Parameters

  • $name (string)(required) – the name of your plugin or the name of the
  • $args (array) – an array of named arguments including:
    • ‘site_url’ (string)(required) – the URL which includesthe URL of your plugin’s website.
    • ‘labels’ (array)(optional) – associative array of labels for the client, currently only supports ‘name’ & ‘singular_name’ labels

You can call this function from any file in your plugin, but it must be called from within the WordPress init hook.

For example:

function eg_register_bbbolt_client(){
    $plugin_name = “My Plugin’s Name”;
    $args = array( 'site_url' => 'http://demo.bbbolt.org/' );
    register_bbbolt_client( $plugin_name, $args );
}
add_action( 'init', 'eg_register_yet_another_client' );

This code is similar to that in the example-clients.php file.

Once you have called this function, your client is setup and ready for interaction with your bbBolt Server.

HINT

To see a bbBolt Client in action without having to create your own client, install bbBolt directory in your /wp-content/plugins/ folder and activate the bbBolt Example Clients plugin from the WordPress Plugins administration page.