• Resolved iamonlythird

    (@iamonlythird)


    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!

    https://www.ads-software.com/plugins/mycred/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hey.

    To add points you can use the mycred_add function and to deduct you can use 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

    (@iamonlythird)

    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

    (@designbymerovingi)

    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 doc or the doc for the myCRED_Settings class.

    Thread Starter iamonlythird

    (@iamonlythird)

    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.