Points

Estimated reading: 5 minutes 5807 views

Point Balances

Each user on your website has their own balance. This balance is stored as a custom user meta, just like any other user detail in WordPress. This also means that if you backup your wp_usermeta table in your database, you are also backing up your user’s balances.

myCred manipulates these user meta via a set of functions to provide support for some of its core features. Depending on your setup, and what myCred features you require, you can use either functions myCred provides or functions WordPress provides.

Point Type Identification

Since version 1.4, myCred has built-in support for managing multiple point types. This means that a user will potentially have multiple balances, one for each point type they are not excluded from. To keep track of this, myCred stores balances under their “point type key” which is used as the meta_key.

Current vs. Total Balance

Each user has two balances for each point type a website uses. This is to accommodate certain myCred features, for example, the Ranks add-on.

A user’s current balance is the amount of points that the user has right now. Their total balance is the total number of points a user has gained based on their history. In most cases, the two balances will be the same with the exception of manual adjustments of a user’s balance by an administrator.

This is used by the Ranks add-on to allow a user to keep their rank even if they spend their points causing their current balance to diminish (e.g. spend points in your store). In this example, if ranks are based on a user’s current balance, then they would be demoted when using their points.

The Default Point Type

myCred will store the default point type on a website under the meta_key mycred_default. As of version 1.7, you can change this using the MYCRED_DEFAULT_KEY constant.

Custom Point Types

When you create a new point type, you are required to set a unique point type key. This key is then used to identify balances for this point type. This of course also means that if a third-party system also stores points as a custom user meta, you could manage that point type in myCred by creating a new point type using the same key as the third-party system.

Exclude Users

myCred allows you to exclude users and/or administrators from having a balance. Being excluded also means that you can not use any myCred feature since you lack a balance. You can exclude users in three ways:

myCRED Core Settings for your point type.

Excluded users do not have a balance.

Exclude Specific Users

You can exclude certain users by adding them to the exclusion list.

Exclude Admins

To exclude admins from the point type, you need to enable their checkboxes in the setting. This will prevent admins from earning or losing points.

Exclude by User Role

You can exclude certain user roles by adding them to the exclusion list.

Alternatively, you can also use the mycred_exclude_user filter and adjust the users you want to be excluded from a particular point type via script.

Multisites

On multisite installations, a user’s metadata is stored in one table which means if a user needs to have a unique balance on each site, we can not use the point type key setup. This would mean a user would have the same balance on all sites (if they are member of more than one).

To get around this, myCred appends the site’s Blog ID to the meta key. This way a user can have a unique balance on each site. You can disable this using the “Central Logging” feature in myCred. When central logging is enabled, a user will have the same balance and history on all sites.

Figure 1. Point type key comparisons based on WordPress usage.

Regular WordPress WordPress Multisites
Point Type Balance / Total With Central Logging Without Central Logging
Default Point Type
Current Balance
mycred_default mycred_default mycred_default_{blog_id}
Default Point Type
Total Balance
mycred_default_total mycred_default_total mycred_default_{blog_id}_total
Custom Point Type
Current Balance
mypointtype mypointtype mypointtype_{blog_id}
Custom Point Type
Total Balance
mypointtype_total mypointtype_total mypointtype_{blog_id}_total