Fetch Supported Widgets
public function onFetchSupportedStatisticsWidgets() : array
Fires while loading the supported widgets to display within the dashboard and statistics 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.
Note: at the first execution of the hook the $widgets
argument isn't an array
.
Return Value
Array. The array 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/vikrestaurants/e4j/widgets/
All the PHP
files contained within the widgets folder of the VikRestaurants - 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
$files = array_map(function($widget) {
return basename($widget);
}, $files);
return $files;
}
Changelog
Version | Description |
---|---|
1.8 | Introduced. |