• Resolved aehernandez

    (@aehernandez)


    Hi!

    I’m using your plugin to create a user via Zapier. I’m currently trying to update a user’s meta with a custom action that I’ve set up, but it’s not updating the custom meta.

    This is the code:

    function custom_role_meta_fn($user_id) {
        $user_meta= get_userdata($user_id); 
        $user_roles=$user_meta->roles; 
        if (in_array('subscriber_custom', $user_roles)){
           update_user_meta( $user_id, 'simple-restrict-slug', 'yes');
        }
    } add_action('custom_role_meta', 'custom_role_meta_fn');

    Could you help me with this issue?
    Thank you in advance!

Viewing 1 replies (of 1 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hey @aehernandez – I think there might be an issue with how you currently setup your custom action.
    How do you call the action? Do you set up the “do_action” argument and add as a value “custom_role_meta”?

    If so, then you need to change the “$user_id” variable to “$user” since we parse the user object. We also parse the user id additionally with it as a second parameter.
    Simply change your code to the following and set up the do_action argument within Zapier.

     function custom_role_meta_fn($user, $user_id) {
        $user_meta= get_userdata($user_id); 
        $user_roles=$user_meta->roles; 
        if (in_array('subscriber_custom', $user_roles)){
           update_user_meta( $user_id, 'simple-restrict-slug', 'yes');
        }
    } add_action('custom_role_meta', 'custom_role_meta_fn', 10, 2);

    Feel free to reach out in case you have further questions. ??

    • This reply was modified 5 years, 5 months ago by Ironikus.
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Action’ is closed to new replies.