• Resolved jennyong

    (@jennyong)


    Is there any hook for me to use if I want to assign user role when assign badge to user? Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @jennyong ,

    Thanks for contacting us. Hope you are doing well.

    You can use mycred_get_badge function to achieve it.

    Here is the link to the documentation.
    Documentation Link

    You will have to do some custom coding to do it properly.

    Let me know if you have any questions.

    Thanks & Regards,
    WP Experts Support Team.

    Thread Starter jennyong

    (@jennyong)

    Hi this mycred_get_badge does not return badge id. Or which hook that I can use to return badge id? Because I need badge id to assign user role to user. Kindly advise. Thank you

    • This reply was modified 1 year, 5 months ago by jennyong.

    You can get Badge ID’s and user roles using the below code snippet:

    $badges = array(); if (class_exists('myCRED_Badge')){
    $badge_ids = mycred_get_badge_ids();
    
    foreach( $badge_ids as $id ) { $badges[$id] = get_the_title( $id ); }
    
    }
    
    $wp_roles = wp_roles();
    
    $roles = array();
    
    foreach( $wp_roles->roles as $role => $name ) { $roles[$role] = $name['name']; }

    Let me know if you have any further questions.

    Thanks

    Thread Starter jennyong

    (@jennyong)

    Hi,

    can I know what is the field name to store the badge name?

    Thank you

    It is saved in wp_posts table in post_name field

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Assign User Role’ is closed to new replies.