Extending the WordPress Plugin


Available Hooks and Filters

Action - wp_logtivity_instance

This action allows you to access the Logtivity_Logger instance just before it is sent to Logtivity. You have access here to modify, remove, add any information to the log as well as stop the log from storing if you so wish.

For example, here we cancel sending to Log to Logtivity if the action contains the text 'Page was Updated'. This might be useful if there were only a handful of logs to you were concerned about and would rather disable the rest.

add_action('wp_logtivity_instance', function($Logtivity_Logger) {

    if (strpos($Logtivity_Logger->action, 'Page was updated') !== false) {
        $Logtivity_Logger->stop();
    }

});

Filter - wp_logtivity_get_user_meta

An alternative approach is using the available filters. This filter passes an array of user meta which can be modified, added to. You must return the array at the end even if it is empty.

add_filter('wp_logtivity_get_user_meta', function($value) {

    return $value;

});

Filter - wp_logtivity_get_meta

This filter similar to the one above, passes an array of meta data being passed to Logtivity. This information can be modified, added to or removed. You must return the array at the end for this to work.

add_filter('wp_logtivity_get_meta', function($value) {

    return $value;

});

Logging Custom Actions

To log Custom Events that aren't covered by this plugin you can call the log method on the Logtivity class at the relevant point in your code and use the API to log your event. You can review the available methods in the Logtivity_Logger class here.

Here is an example usage of the Logtivity_Logger class.

Logtivity::log()
    ->setAction('My Custom Action')
    ->addMeta('Meta Label', $meta)
    ->addMeta('Another Meta label', $someOtherMeta)
    ->addUserMeta('Stripe Customer ID', $stripeCustomerId)
    ->send();