A wrapper function for add_user_meta, it assures that point related data is saved under the correct meta key structure.

Available since version 1.5


(int | bool) Primary key id for success. FALSE for failure.


Param Type Required Description
function mycred_add_user_meta(
$user_id int Yes

The users numeric ID.

$meta_key string Yes

The meta key id.

$end string No

Optional ending to append to the meta key id. In certain situation on Multisites, the meta key gets the blogs ID appended. The value of $end is then appended after the blog ID, whilst the value of $meta_key is before the blog id. On regular WordPress installations $end is appended onto $meta_key.

$value string Yes

The meta value.

$unique bool No

TRUE if the meta data is unique or FALSE if not. Defaults to TRUE.

) { ... }


Example 1: Save the total number of times a user has gained points for approved comments.

$user_id       = get_current_user_id();
$comment_count = mycred_count_ref_instances( 'approved_comment', $user_id );

mycred_add_user_meta( $user_id, 'comment_point_count', '', $comment_count );