Hooks

Hooks allow users to extend the functional extent of WordPress plugins. The following hooks are deposited in Statify and can be addressed or controlled via code:

statify__skip_tracking

Type: Filter (Boolean)
Implementation: Statify 1.2.6

Customized control of page counting, e.g. for page type, user rights, browser type. In this way, all or certain blog pages can be excluded from counting.

The hook takes one (optional) parameter containing the result of previous filters (if any). The first custom filter always receives null.

There are three possible return values:

  • true – Statify does not consider the currently called blog page
  • false – Statify does consider the current request without evaluating any built-in filters
  • null – can be interpreted as “no decision”Statify will continue evaluating the built-in filter chain

Code example:

add_filter(
    'statify__skip_tracking',
    function( $previous_result ) {
        if ( 1 === 1 ) {
            return true;
        }
	
        return false;
    }
);Code language: PHP (php)

statify__user_can_see_stats

Type: Filter (Boolean)
Implementation: Statify 1.3.1

Display control of the Dashboard statistics for non-administrators. The access to the Dashboard-Widget with WordPress statistics can be granted per user or user group.

The return value true allows access to the statistics. The editing of the plugin settings in the widget remains exclusively reserved for users with the user role edit_dashboard.

Code example:

add_filter( 'statify__user_can_see_stats', '__return_true' );Code language: PHP (php)

Specific for Editors:

add_filter(
    'statify__user_can_see_stats',
    function( $previous ) {
        return $previous || current_user_can( 'edit_others_pages' );
    }
);Code language: PHP (php)

More about Roles and there Capabilities can be found in the Codex.


statify__visit_saved

Type: Action
Implementation: Statify 1.6.0

This action hook is fired after Statify stored a visit in the database. It is designed for further processing or extension of the result.

The hook takes up to two parameters:

  • array $data – associative array with the three fields that have been inserted into the database:
    • created – string containing the visit date in YYYY-MM-DD format
    • referrer – the referrer URL
    • target – the target page (relative URL)
  • int $id – ID of the entry in the wp_statify table

Code example:

add_action(
    'statify__visit_saved',
    function( $data, $id ) {
        /*
         * Do custom stuff...
         *
         * $data = array(
         *   'created'  => '2020-05-20',
         *   'referrer' => 'https://pluginkollektiv.org/',
         *   'target`   => '/'
         * )
         *
         * $id = 42
         */
    },
    10,
    2
);Code language: PHP (php)