Change Role based on Balance

Home / Code Snippets / Change Role based on Balance

Change a users WordPress role based on their point balance.

The above code goes into your theme's function.php file.

  1. This is very great code. But is it compatible with 1.6.2? When a subscriber got more than 100 points it’s role becomes administrator eveytime. Can you check it please? And is it also functioning reverse – lower role when user lost points?

  2. I have implemented this code and it is working when the user moves up a level but not when the user needs to go back down a level. Is there a way that this can happen?
    Thanks

  3. Great, I am trying to send email notification to users once upon their role was changed, and I try to add email notification code in theme option:

    function user_role_update( $user_id, $new_role ) {
            $site_url = get_bloginfo('wpurl');
            $user_info = get_userdata( $user_id );
            $to = $user_info->user_email;
            $subject = "Role changed: ".$site_url."";
            $message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
            wp_mail($to, $subject, $message);
    }
    add_action( 'set_user_role', 'user_role_update', 10, 2);
    

    and the email will send only when user role is changed by admin at backend, would you please let us how to hook mycred email notification add-on? any sample code would be great appreciated, have a nice day.

    Alex

    1. The email notice add-on was built to send email when a user gains or loses points. If you want to tie in your script to send an email notice, you need to give your users points.

  4. Hello,

    I can make it to work with wordpress Default roles like ‘contributor’, ‘author’, ‘editor’, ‘administrator, and I use the plugin of “Capability Manager Enhanced” to create a new role named “Mycredlevelroleone” in our Multisites, and set ‘Mycredlevelroleone’ => 100000, and it does not work.

    How to make it support the custom roles please?

    Thanks.

    Alex

Leave a Reply

Spin to win points 💰
Kindly get back to your previous orientation view... your wheel is rolling there...

Do you really like this awesome addon and wanna use on your site? click here to get it now 👍
myCRED Fortune Wheel special offer unlocked!
You have a chance to win free tokens. Are you feeling lucky? Give it a spin.
* You can spin the wheel only once in a month.
* You can spin again any time by paying 500 points
* Once you pay for spin you are not able to refund it.
You must login to play mycred fortune wheel
11
Happy HolidaysGET DISCOUNT