Modifying User Points

WordPoints offers a set of functions for modifying the points of a user. Each of them takes the following arguments:

  1. $user_id — The ID of the user whose points to modify.
  2. $points — The number of points to add/subtract/etc. (exactly what the number means depends on the function).
  3. $points_type — The slug of the type of points.
  4. $log_type — A slug for this type of transaction. This controls how the log text is generated, etc.
  5. $log_meta — An optional array of key => value pairs of metadata to save for this transaction.
  6. $log_text — Optional default text for the points log entry for the transaction.

Usually it is not best to modify user points directly using these functions. It is better to use Hooks API instead. However, if a custom event is not useful in your scenario, you can use these functions.

Altering Points #

The wordpoints_points_alter() function will add or subtract points, based on the value of the $points argument. If $points is a positive integer, the points will be added. If it is negative, the points will be subtracted.

This is the function that you will want to use most of the time. The others are just wrappers that you might find useful in some special situations.

Adding Points #

When you only want to add to a users points, you can use the wordpoints_add_points() function.

This function will do nothing of the $points value is negative.

Subtracting Points #

When you only want to subtract from a users points, you can use the wordpoints_subtract_points() function.

This function will do nothing of the $points value is negative.

Setting Points #

When you want to set a users points to a certain value no matter how many points they currently have, use the wordpoints_set_points() function.