mycred_add

Codex / mycred/balance / Functions / mycred_add

Navigation:

  1. Description
  2. Usage
  3. Parameters
  4. Example
  5. Return

Description

Adds a given amount of points to a specific user. Once the user’s balance has been updated, a new log entry is made under the given reference.

Note! This function will not check if the given user id should be excluded! This must be done before calling this function!

 

Usage

<?php mycred_add( $ref, $user_id, $amount, $entry, $ref_id, $data, $type ); ?>

 

Parameters

  • ref (string) required
    Required reference id for this update. This reference must be explanatory as myCRED will replace underscores with whitespaces and capitalize each word when viewing the log and this reference is what will be presented when filtering by reference. Example: reference = points_for_action becomes = Points For Action.
  • user_id (int) required
    Required user id.
  • amount (int|float) required
    Amount (positive or negative).
  • entry (string)
    Log entry template.
  • ref_id (int|string|array)
    Optional reference id.
  • data (int|string|array|object)
    Optional data to save with this log entry. Note that arrays are serialized!
  • type (string)
    Optional point type.

 

Example

Example 1: Add 10 points to a user.

<?php
$user_id = 12;
if ( !mycred_exclude_user( $user_id ) ) {
	// Add points and save the current year as ref_id
	mycred_add( 'birthday_present', $user_id, 10, 'Birthday %plural%!', date( 'y' ) );
}
?>

 

Return

Returns true on success else fail.

Last edited March 5, 2016