• Resolved hftobeason

    (@hftobeason)


    When a new user is added to my WordPress site running UM, a bunch of usermeta rows are created for that new user, including a row for meta_key “wp_capabilities”, which contains the user role. Another row is also created, meta_key “description”, which is always blank. This is a screenshot of the database:

    mySQL Database

    What I’m trying to do is add some code that will automatically populate the meta_key “description” row with a meta_value corresponding to the user’s role – initially “registered”, but updating if the role gets updated in UM.

    Any help most appreciated. I’m not a coding expert, but I can usually follow along…

    Thanks.

    • This topic was modified 4 years, 3 months ago by hftobeason.
    • This topic was modified 4 years, 3 months ago by hftobeason.
    • This topic was modified 4 years, 3 months ago by hftobeason.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @hftobeason

    Do you want to change the user’s description based on the user role of the user on registration?

    You can try this code snippet:

    add_action( 'um_registration_complete', 'um_122220_change_registration_role' ,1 );
    function um_122220_change_registration_role( $user_id ){
       
        um_fetch_user( $user_id );
        $role = um_user("role");
    
        update_user_meta( $user_id, "description", "Testers test" );
    
    }

    Regards,

    Thread Starter hftobeason

    (@hftobeason)

    @champsupertramp, thank you for your reply.

    Where do I add that code? functions.php of my child theme?

    Does that code run when the user role is changed? For example from “registered” to “short_term”?

    And is the “Testers test” correct? Or should it be $role?

    Thank you again for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Automatically populate/update “description” meta_key field’ is closed to new replies.