Title: Code to Add/Subtract points
Last modified: August 21, 2016

---

# Code to Add/Subtract points

 *  Resolved [iamonlythird](https://wordpress.org/support/users/iamonlythird/)
 * (@iamonlythird)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/)
 * Hi,
 * I am planning to migrate from CubePoints so I will need to write a few custom
   modules for this prior making the move, all of which are quite simple.
 * My question is, what is the code that we can use to Add and Subtract points from
   a user? And what is the code to log it for the user?
 * Some good information about this would be very helpful.
 * Thank you!
 * [http://wordpress.org/plugins/mycred/](http://wordpress.org/plugins/mycred/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [myCred](https://wordpress.org/support/users/designbymerovingi/)
 * (@designbymerovingi)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/#post-4154404)
 * Hey.
 * To add points you can use the [mycred_add](http://mycred.me/functions/mycred_add/)
   function and to deduct you can use [mycred_subtract](http://mycred.me/functions/mycred_subtract/)
   function.
 * Both functions will add to your log when used unless they are executed by an 
   administrator in which case log entries are optional.
 *  Thread Starter [iamonlythird](https://wordpress.org/support/users/iamonlythird/)
 * (@iamonlythird)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/#post-4154471)
 * Excellent, thank you for the reply. I have a remaining question. I need to use
   a custom log entry, is that possible? For example, it should log “You edited 
   a post.”
 *  Plugin Author [myCred](https://wordpress.org/support/users/designbymerovingi/)
 * (@designbymerovingi)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/#post-4154482)
 * Without knowing what you are trying to accomplish, the easiest way to add something
   to your log is to use the mycred_get_settings function.
 * Example:
 *     ```
       // Init myCRED
       $mycred = mycred_get_settings();
   
       // Add a custom log entry
       $mycred->add_to_log(
       	'my_custom_reference', // reference ID. Should be explanatory (required)
       	1, // user id (required)
       	10, // points amount (required)
       	'My log entry text', // log entry (optional)
       	1, // reference id. Only integers are allowed, used to store user / post / comment ids
       	'optional extra', // optional extra data space
       	'mycred_default' // points type, will default to this
       );
       ```
   
 * A few notes:
 * reference = this should be something unique that explains what you did, you can
   then search for log entries according to these reference.
 * log entry = if you are using template tags, make sure you do not parse them before
   saving into the database. they are parsed first when they are retrieved from 
   the database.
 * ref id = this is used to store reference ids for example the ID of the post you
   purchased or the user ID to whom you transferred points to. It can not be anything
   but integers!
 * data = you can use this column to anything you want, any extra info you might
   want to save. Remember that if you use template tags in your log entry this should
   contain an array with the ref_type key to indicate to myCRED what the ref id 
   is referring to (i.e. user / post / comment).
 * Finally, if you decide to use the mycred_get_settings function, you also gain
   access to the same functions the add and subtract functions use!
 * Example: Add points using mycred_get_settings():
 *     ```
       // init myCRED
       $mycred = mycred_get_settings();
   
       // Add points
       $mycred->add_points( 'manual', 1, 10, 'My custom log entry' );
       ```
   
 * You deduct points by passing on a negative value for the amount of points. So
   awarding -10 points will deduct 10 points from the user.
 * It uses the same arguments as the add_to_log method.
    Fore more info check out
   the [mycred_get_settings](http://mycred.me/functions/mycred_get_settings/) doc
   or the doc for the [myCRED_Settings](http://mycred.me/classes/mycred_settings/)
   class.
 *  Thread Starter [iamonlythird](https://wordpress.org/support/users/iamonlythird/)
 * (@iamonlythird)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/#post-4154564)
 * This is what I would call helpful. Thank you. Marking this as resolved. I will
   report back if I experience any problems.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Code to Add/Subtract points’ is closed to new replies.

 * ![](https://ps.w.org/mycred/assets/icon-128x128.gif?rev=3512531)
 * [Points Management System For Gamification, Ranks, Badges, and Loyalty Rewards Program - myCred](https://wordpress.org/plugins/mycred/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mycred/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mycred/)
 * [Active Topics](https://wordpress.org/support/plugin/mycred/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mycred/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mycred/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [iamonlythird](https://wordpress.org/support/users/iamonlythird/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/code-to-addsubtract-points/#post-4154564)
 * Status: resolved