Create a gist now

Instantly share code, notes, and snippets.

This is an example of how to add widgets to the UCM dashboard
<?php
// upload this file to includes/plugin_custom_dashboard_widgets/custom_dashboard_widgets.php
class module_custom_dashboard_widgets extends module_base{
public static function can_i($actions,$name=false,$category=false,$module=false){
if(!$module)$module=__CLASS__;
return parent::can_i($actions,$name,$category,$module);
}
public static function get_class() {
return __CLASS__;
}
public function init(){
$this->links = array();
$this->module_name = "custom_dashboard_widgets";
$this->module_position = 1;
$this->version = 1;
hook_add( 'dashboard_widgets', 'module_custom_dashboard_widgets::my_widgets' );
}
public static function my_widgets() {
$widgets = array();
// start first widget:
ob_start();
?>
<div>
Put your Widget HTML Code Here
</div>
<?php
$widgets[] = array(
'title' => "My Widget Title",
'columns' => 2, // this can be 1, 2, 3 or 4
'content' => ob_get_clean(),
);
// end first widget.
// start second widget:
ob_start();
?>
<div>
Put your Widget HTML Code Here
</div>
<?php
$widgets[] = array(
'title' => "My Widget Title",
'columns' => 2, // this can be 1, 2, 3 or 4
'content' => ob_get_clean(),
);
// end second widget.
return $widgets;
} // end hook function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment