Title: Exclude userrole
Last modified: July 17, 2019

---

# Exclude userrole

 *  Resolved [CommerceBird](https://wordpress.org/support/users/fawadinho/)
 * (@fawadinho)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/)
 * Hello,
 * How can I exclude a particular userrole from approval? Is there a hook I can 
   use?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Konstantin Obenland](https://wordpress.org/support/users/obenland/)
 * (@obenland)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11741913)
 * 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.
 *  Thread Starter [CommerceBird](https://wordpress.org/support/users/fawadinho/)
 * (@fawadinho)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11743193)
 * Thank you. Would be nice to see this as a feature on a settings page 🙂
 *  Plugin Author [Konstantin Obenland](https://wordpress.org/support/users/obenland/)
 * (@obenland)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11744979)
 * How are these users added on your installation? Which role do they have assigned?
 *  Anonymous User
 * (@anonymized-15307071)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11748819)
 * @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 years, 10 months ago by Anonymous User.
 *  Plugin Author [Konstantin Obenland](https://wordpress.org/support/users/obenland/)
 * (@obenland)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11749067)
 * > Can you please provide a snippet
 * I’m not sure if I should be amused or offended. I am sure however, [my answer earlier](https://wordpress.org/support/topic/exclude-userrole/#post-11741913)
   will get you 90% of the way there.
 *  Anonymous User
 * (@anonymized-15307071)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11749658)
 * [@obenland](https://wordpress.org/support/users/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 years, 10 months ago by Anonymous User.
    -  This reply was modified 6 years, 10 months ago by Anonymous User.
    -  This reply was modified 6 years, 10 months ago by Anonymous User.
    -  This reply was modified 6 years, 10 months ago by Anonymous User.
    -  This reply was modified 6 years, 10 months ago by Anonymous User.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Exclude userrole’ is closed to new replies.

 * ![](https://ps.w.org/wp-approve-user/assets/icon-256x256.png?rev=3013178)
 * [WP Approve User](https://wordpress.org/plugins/wp-approve-user/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-approve-user/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-approve-user/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-approve-user/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-approve-user/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-approve-user/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: Anonymous User
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/exclude-userrole/#post-11749658)
 * Status: resolved