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

    (@designbymerovingi)

    Hi.

    There is no AJAX call but there are a few functions you can use:

    mycred_add
    You can use this function to add points to a user along with a new entry into your log.

    mycred_get_settings
    This function gives you access to the myCRED_Settings class and gives you further options. For example you can use it to update a users balance without a log entry:

    // Load myCRED
    $mycred = mycred_get_settings();
    
    // Update balance (add 10 points to the given users current balance
    $mycred->update_users_balance( $user_id, 10 );

    Remember that users balances are stored as a user meta and you can always update a users balance by updating this meta.

    By default, myCRED stores each users balance under the mycred_default meta key. So you can always get or update a user balance directly without using any mycred functions.

    Example:

    $user_id = 1;
    
    // Get users balance
    $users_balance = get_user_meta( $user_id, 'mycred_default', true );
    
    // Add 10 points
    $new_balance = $users_balance + 10;
    
    // Save
    update_user_meta( $user_id, 'mycred_default', $new_balance );

    Remember that if you use any myCRED function, make sure you wrap these functions in a function exists check to make sure your site does not crash when you update or disable the myCRED plugin.

    Example:

    if ( function_exists( 'mycred_add' ) ) :
    	mycred_add();
    endif;

    Thread Starter zackskeeter

    (@zackskeeter)

    Thanks a bunch!

    Do you have any ideas on how i could also limit a point being added to once a day?

    So that if a user does a action it will only reward them once for that action within a day

    Thank you for your help!

    Plugin Author myCred

    (@designbymerovingi)

    You would need to use the mycred_add filter which fires before points are awarded and insert a daily counter for each user. You can decline points being given by returning a boolean false in this filter.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use ajax to update user points’ is closed to new replies.