Support » Plugin: WP Approve User » Exclude userrole

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Konstantin Obenland

    (@obenland)

    The easiest way would probably be to hook into 'user_register' on a later priority and update the meta value based on the users’ role.

    Alternatively, if you’re the one adding these users, make sure you do it with a user that has the create_users capability.

    Thank you. Would be nice to see this as a feature on a settings page 🙂

    Plugin Author Konstantin Obenland

    (@obenland)

    How are these users added on your installation? Which role do they have assigned?

    @obeland Our clients users are created upon registration the same goes for Admins, and we want to exclude admins.

    Can you please provide a snippet for this or include this as a feature to be able to exclude user roles ?

    Thanks for your help !

    • This reply was modified 6 months, 1 week ago by JungleWP.
    Plugin Author Konstantin Obenland

    (@obenland)

    Can you please provide a snippet

    I’m not sure if I should be amused or offended. I am sure however, my answer earlier will get you 90% of the way there.

    @obenland 😉 your answer is 100% on point! I apologize if my comment made you feel confused. But we genuinely believe that adding this feature will greatly help many non technical users who seek a simple solution in your Plugin.

    Please find below the solution we have been able to provide to our client based on your answer and your Github repository.

    We have used a custom function and the meta wp-approve-user instead that hooks into wp_head

    /**We want to avoid Exploiting the WordPress default user registration form, instead we approve only admin users we create trough a specific form.**/
    
    add_action( 'wp_head', 'myform_create_new_admin_approved');
    
    function myform_create_new_admin_approved() {
    require( 'wp-includes/registration.php' );
    
         if (  isset( $_POST['username_name'] ) &&  isset( $_POST[$user_pwd'] ) && 
         !username_exists($_POST['username_name'])) {
                $user_id = wp_create_user( $_POST['first_name'], $_POST[$user_pwd']);
                $user = new WP_User( $user_id );
    	    $user->set_role( 'administrator' ); 
    	    update_user_meta( $user_id, 'wp-approve-user', true );
                }
         }
    

    Best regard,
    Alfonso

    • This reply was modified 6 months, 1 week ago by JungleWP.
    • This reply was modified 6 months, 1 week ago by JungleWP.
    • This reply was modified 6 months, 1 week ago by JungleWP.
    • This reply was modified 6 months, 1 week ago by JungleWP.
    • This reply was modified 6 months, 1 week ago by JungleWP.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclude userrole’ is closed to new replies.