Fetch Supported Widgets
public function onFetchSupportedStatisticsWidgets() : array
Fires while loading the supported widgets to display within the Dashboard and Analytics pages.
Description
This filter can be used to support additional types of widgets without having to edit any core files.
Here you should simply return the list of widgets that can be loaded within the script. Only the base name of the files have to be returned. The base name of the files to load can specify only letters, numbers and underscores.
Return Value
Array. A list holding the name of the external widgets to load.
Example
The example below adds support for all the widgets contained in a specific folder of a third-party plugin. Such as:
/plugins/vikappointments/e4j/widgets/
All the PHP
files contained within the widgets folder of the VikAppointments - E4J plugin will be loaded.
/**
* Trigger filter can be used to register external widgets to
* extend the statistics dashboard without editing any core files.
*
* @return array The array holding the widgets to load.
*/
public function onFetchSupportedStatisticsWidgets()
{
// create base path to "widgets" folder contained within the plugin
$base = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR;
// load all PHP files from "widgets" folder
$files = glob($base . '*.php');
// IMPORTANT: map the widgets to return only the base name
return array_map(function($widget)
{
return preg_replace("/\.php$/i", '', basename($widget));
}, $files);
}
Changelog
Version | Description |
---|---|
1.7 | Introduced. |
Last Update: 2021-10-06 17:19
Helpful?