Difference between revisions of "Creating a Widget"
(Created page with 'Creating a widget is very easy to do. They can be defined as part of any hook file - be it part of a provisioning/server module, registrar module or addon module. Or even just …') |
(No difference)
|
Revision as of 16:34, 22 February 2012
Creating a widget is very easy to do. They can be defined as part of any hook file - be it part of a provisioning/server module, registrar module or addon module. Or even just a standalone hook file for a standalone widget on it's own.
All the widgets included in WHMCS by default are open source, and so are the ideal way to get started by following one of them as an example. You can find the default widgets in the /modules/widgets/ folder.
The basic idea is that you need to create a function, which returns an array with 2 parts - a title, and the content. The title is the name displayed for the widget, and the content is the output within the widget block. And then using the same methodology as with hooks, you define the custom function to WHMCS using a Hook call of "AdminHomeWidgets". So here's a very basic Hello World example:
<?php
function widget_hello_world($vars) {
$content = '<p><strong>Hello World</strong> Sample Widget Content</p>';
return array( 'title' => 'Hello World', 'content' => $content );
}
add_hook("AdminHomeWidgets",1,"widget_hello_world");
?>
An additional variable return that is supported from the widget functions is "jquerycode" and using that, it is possible to define jQuery scripting that is then placed in the <head> section of the page, and this can be used for having ajax based loading of content within the widget. Please refer to the whmcs_news.php widget within the /modules/widgets/ folder for a good example of this functionality.
Right now the AdminHomeWidgets is the only available hook point, but in due course we plan to add support for other pages where widgets will be able to be utilised.