Hook: dashboard_statistics
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: dashboard_statistics

The dashboard_statistics hook allows developers to add custom statistics to the dashboard. Plugins can contribute their own metrics, which will be merged into the global statistics array.

Usage


$pluginStats = DynamicHooks::executeHook('dashboard_statistics');

// Merge plugin statistics into the counts
if (!empty($pluginStats) && is_array($pluginStats)) {
    foreach ($pluginStats as $namespace => $stats) {
        if (is_array($stats)) {
            foreach ($stats as $statKey => $stat) {
                if (isset($stat['label']) && isset($stat['value'])) {
                    $JSCMS_COUNTS[$statKey] = $stat;
                }
            }
        }
    }
}
    

This hook provides a mechanism to dynamically extend dashboard statistics with plugin-defined metrics.

Example Implementation


DynamicHooks::addHook('dashboard_statistics', function () {
    return [
        'custom_stat' => [
            'label' => 'Custom Metric',
            'value' => 12345,
            'icon' => 'fas fa-chart-line', // Optional
        ]
    ];
}, 'custom_plugin_namespace');
    

Best Practices

  • Ensure custom statistics have meaningful labels and accurate values.
  • Use unique keys for statistics to avoid conflicts with other plugins.
  • Provide optional icons for enhanced visual representation.

Troubleshooting

  • Verify the hook is correctly registered under the intended namespace.
  • Check for missing or invalid properties in the statistics array (e.g., label or value).
  • Inspect the merged global statistics array ($JSCMS_COUNTS) for conflicts or missing data.
Was this article helpful?
0 out of 0 found this helpful