0

I have a custom form so the user can register at my site.

He can register as a subscriber or as a shop.

I need to 'block' all registrations for shop, so the user register as a shop, receives an email telling him that the registration is on hold, the admin receives an email telling him a new shop registered, and the admin approves the registration in the admin panel.

Any ideas on how to do that? I've searched for a plugin, but some of them forced me to use their own registration forms and others prevented any role from registering.

What I have so far is a regular registration form that I created. One for the shops and one for the subscribers. It works perfectly.

1 Answer 1

1

Ok, I found a way to do it. It's not a perfect solution but will allow me to continue the project.

I just created another role called 'shop_pending'.

When the user registers as a shop, he won't get the role 'shop', instead he will get the role' shop_pending'.

After all the process is done, the admin can go to the users page, edit the specific user, and change it's role.

Here is part of the code I'm using:

// Check args and replace if necessary
if (!is_array($fields_shop))     $fields_shop = array();
if (!is_wp_error($errors_shop))  $errors_shop = new WP_Error;
if (isset($_POST['submit_shop'])) {
    // Get fields from submitted form
    $fields_shop = ds_get_fields_shop();  
    // Validate fields and produce errors
    if (ds_validate_shop($fields_shop, $errors_shop)) {      
    // If successful, register user
      $fields_shop['role'] = 'shop_pending';
      $shop_id = wp_insert_user($fields_shop);
      update_user_meta( $shop_id, 'user_avatar', $fields_shop['user_avatar'] );
      update_user_meta( $shop_id, 'nome_shop', $fields_shop['nome_shop'] );
      update_user_meta( $shop_id, 'cont_shop', $fields_shop['cont_shop'] );
      update_user_meta( $shop_id, 'telefone_shop', $fields_shop['telefone_shop'] );
      update_user_meta( $shop_id, 'zip', $fields_shop['zip'] );
      update_user_meta( $shop_id, 'conselho2', $fields_shop['conselho2'] );

      // Clear field data
      $fields_shop = array(); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.