Functions and API

Adding Custom Reports to WP Slimstat

Applies to SlimStat 6.0.0 and SlimStat Pro 3.0.0 · checked

Register a custom report with slimstat_reports_info. Give it a unique ID, a rendering callback and a real screen ID such as slimview3 (Audience). Place the code in your own WordPress plugin, not inside SlimStat.

A small administrator-only report

add_filter( 'slimstat_reports_info', function ( $reports ) {
    $reports['my_slimstat_count'] = array(
        'title' => 'Recorded pageviews',
        'callback' => 'my_slimstat_render_count',
        'callback_args' => array(),
        'classes' => array( 'normal' ),
        'locations' => array( 'slimview3' ),
    );
    return $reports;
} );

function my_slimstat_render_count( $args = array() ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    $count = wp_slimstat_db::count_records( 'id' );
    echo '<p>' . esc_html( number_format_i18n( (int) $count ) ) . '</p>';
}

This uses the active report filters and the plugin database API. It does not introduce a custom SQL query, expose visitor data or bypass report permissions. The callback deliberately restricts this example to administrators.

Test each output you support

Check your report in the Audience screen with different date ranges and an empty result. Pro email and export integrations need an appropriate raw-data callback in callback_args['raw']; the minimal rendering example above does not provide one.

For custom queries, use SlimStat’s configured database and prepared values, respect site/network scope, bound result sizes and escape output. See the report registry filter and database API methods.