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

`$user_id`

— The ID of the user whose points to modify.`$points`

— The number of points to add/subtract/etc. (exactly what the number means depends on the function).`$points_type`

— The slug of the type of points.`$log_type`

— A slug for this type of transaction. This controls how the log text is generated, etc.`$log_meta`

— An optional array of key => value pairs of metadata to save for this transaction.`$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.

1 2 3 4 5 | // Adding 10 points. wordpoints_alter_points( $user_id, 10, 'points', 'my_log_type' ); // Subtract 5 points. wordpoints_alter_points( $user_id, -5, 'points', 'my_log_type' ); |

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.

1 | wordpoints_add_points( $user_id, 10, 'points', 'my_log_type' ); |

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.

1 2 | // Subtract 10 points. wordpoints_subtract_points( $user_id, 10, 'points', 'my_log_type' ); |

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.

1 2 | // After this the user will have exactly 10 points. wordpoints_set_points( $user_id, 10, 'points', 'my_log_type' ); |