Giter VIP home page Giter VIP logo

user-action-logging's Introduction

WordPress User Action Logging

Howdy!

This plugin was created to assist with user tracking & activity logging. Currently the plugin tracks user logins & logouts but you can easily incorporate the functionality into your theme by running my custom action to log further activity.

The custom action would need to be run via do_action when your desired activity is triggered. Here is an example below;

// Store user id.
$user_id = get_current_user_id();

// If we have the user id, continue.
if ( ! empty( $user_id ) ) {
  // Get user data with id.
  $user = get_userdata( $user_id );

  // Store a user name.
  $user_name = $user->display_name ? $user->display_name : $user->user_nicename;

  // Log this activity.
  do_action( 'ual_log_action', $user->ID, $user_name . ' logged In', 'logged-in' );
}

The final line - do_action( 'ual_log_action', $user->ID, $user_name . ' logged In', 'logged-in' ); is where the magic happens! It takes 4 parameters; action name (ual_log_action), user ID (int), message (string) and taxonomy slug (string). When this action is used, a post gets created within the Activity CPT and utilises the final parameter to set a taxonomy to that post. This helps with filtering and being able to gain stats. By default, the Activity post that gets created assigns the user ID as the author - again this helps to filter activity by user.

You can paste that do_action line anywhere in your theme (provided the plugin is activated) and the activity will be created.

Once you have a range of activity triggers, you could generate a PDF/CSV which contains all the posts for all users or specific users. If you have any questions or improvements feel free to let me know! :)

user-action-logging's People

Contributors

gemplank avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.