Filters

slimstat_reports_info

WP Slimstat allows you to customize the reports available in the plugin. You can add, remove, or edit reports using a simple API. This document explains how to use this feature.

Overview

WP Slimstat stores report information in an array called self::$reports_info. You can modify this array using the slimstat_reports_info filter.

self::$reports_info = apply_filters( ‘slimstat_reports_info’, self::$reports_info );

Report Structure

Each report is defined as an array with specific keys:

  • title: The title of the report (string).

  • callback: The function to render the report (string or array).

  • callback_args: Arguments for the callback function (array).

  • raw: Function to retrieve data from the database.

  • classes: CSS classes for layout (array of strings).

Options: ‘normal’, ‘wide’, ‘full-width’, ‘tall’.

  • screens: Where the report appears (array of strings).

Options: ‘wp-slim-view-1’ to ‘wp-slim-view-6’, ‘dashboard’.

  • **tooltip **(optional): Tooltip text for the report (string).

Example: Adding a Custom Report

Use the slimstat_reports_info filter to add your custom report:

add_filter(‘slimstat_reports_info’, ‘add_custom_report’);

function add_custom_report($reports_info) { $reports_info[‘slim_custom_report’] = array( ‘title’ => ‘My Custom Report’, ‘callback’ => ‘raw_results_to_html’, ‘callback_args’ => array( ‘raw’ => ‘get_custom_data’ ), ‘classes’ => array(‘full-width’), ‘screens’ => array(‘wp-slim-view-3’) );

return $reports_info;

}

In this example

  • slim_custom_report is the unique ID for your report.

  • raw_results_to_html is a WP Slimstat function that renders data.

  • get_custom_data is your custom function to fetch data.

Important Notes

  • Use unique IDs for your custom reports to avoid conflicts with built-in reports.

  • The raw function in callback_args is used for Excel exports and email functionality.

  • You can mix and match classes (e.g., array(‘normal’, ‘tall’)).

  • Place your report in appropriate screens based on its content.

By following these guidelines, you can easily add, customize, or remove reports in WP Slimstat to suit your needs