Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    hmmm…. I think that hooking the user update functions would be the way to do that. BUT i think you’d need a way to validate the email address first before increasing privs. That makes the process more complex. What’s to keep me from changing my email to one of the emails on the list.

    https://codex.wordpress.org/Plugin_API/Action_Reference/profile_update

    This might help.

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Thanks for your replies! All very good points, looks like I might be able to try a unique identifier with that second link, i’ll try tomorrow and let you know how it goes.

    Thread Starter PleasantlyOdd

    (@pleasantlyodd)

    Thank you so much for your help, both of you! I came back to share my solution with the community. What I ended up doing was a combination of both of your inputs.

    ____

    I made it so that when the user updates his last name with the keyword ‘uniquename’, it changes their user permissions. Here’s the code I used, I left it as editor for example reasons:

    <?php
        add_action( 'profile_update', 'my_profile_update', 10, 2 );
    
        function my_profile_update( $user_info ){
          $user_info = get_userdata( $user_info );
          if ( $user_info->last_name === 'uniquename' ){
            $user_info->set_role( 'editor' );
          }
        }
    ?>

    ____

    I’m still very new to PHP hooks/actions though, whats the importance of the 10, 2? would it not work if they were different numbers? from what I understand they’re position values, but what makes the profile update position 10 or why does my function need to be position 2?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Detect e-mail to set user permissions.’ is closed to new replies.