Log API

The myCRED Log is one of the most important part of myCRED. In this log, you have a complete historic overview of how points have been awarded or deducted from your users. The only thing that is not logged is if you as an administrator edits a users point balance without a log entry.

Besides giving you a complete overview, the log is also used by myCRED to calculate totals and limits that you might be enforcing on your website.

Make sure you include the myCRED Log table in your database backup! Backing up your log is always important!

Add Log Entry

All log entries are handled by the add_to_log() function in the myCRED_Settings class.

In order for a new entry to be saved the following conditions must be met:

  • A reference must be set.
  • A user ID must be provided.
  • Creds can not be zero.

Furthermore if ctype is not set, the function will default to mycred_default (the id of the default point type in myCRED).

Example using the API to add a new log entry.

Query Log Entries

myCRED uses the myCRED_Query_Log class to query and to render log entries. If you have used the WP_Query class you will find a lot of similarities when it comes to querying entries.

Example: Get the last 10 entries for user with the ID 1.

Example: Get all log entries for approved comments from today.

Display Log Table

Rendering log tables using the myCRED_Query_Log is not mandatory, if you prefer, you can construct your own table.

Example: Show log entries for user with the ID 1. Show 10 entries per page.

Table Column Headers

You can customize which table column headers to show when rendering the log table. You can use this to remove columns you do not want to show or add your own custom columns.

The table columns are controlled by the headers variable of the myCRED_Query_Log class and it is an associative array of column ids with their associated labels.

The default columns that myCRED provides:

Column ID Description
cb Checkbox column for bulk actions. Used in the admin area.
username User column. Shows the username the log entry belongs to.
ref Reference column. Shows the reference associated with the log entry.
time Date column. Show the date of the log entry.
creds Points column. Shows the formatted point amount.
entry Entry column. Shows the log entry.

Example: Customize what column headers to show in the table.

Add Custom Table Columns

You can add your own table columns, both on the front and in the admin area. This can come in handy if you are not interested in building your own table in the front end. To add a custom column, you need to do two things:

  1. First, you will need to add your custom table column to the list. To do this, we need to use the mycred_log_column_headers filter. You can also use this filter to remove columns you do not want to use.
  2. Once we added the column, we will need to render it’s content or the column will be shown but be empty. To do this, we need to use the  mycred_log_{column} filter.

Example: Add a custom table column in the admin area that shows each log entries unique ID.

Last edited June 24, 2016