1

I have a registration form which will filled by users and according to that form i have only First name, Last name, Middle name, Email address as important and so many other minor things.

After registration the admin will create username and password for that person which will go through mail to that person. After that he can able to login.

Can anyone give me a hint how can i proceed.

  • 1
    I don´t understand your question. If you have the email address of the user, you can create a user with that information, and send the password to the person. Please clarify your problem. – flomei Mar 7 '17 at 10:38
0

Very simple idea. Follow the steps:

Step 1)

1) Create a post type registration.add the necessary field like first name, last name, email etc which are associated in your form.

2) Custom registration from values saves into registration post types. So now your form submitted values are in your hand.

3) Save first name and last name in the title field.

4) check email field in users table in wp, exists or not. If exists post will not create and show notification already exists or reset whatever you want to show.

Step 2)
1) in registration post type list add a link add to user besides edit, preview etc link or create a column User Creat where add is the link for creating the user.

2) when click add in your backend code work to create the user. All value you got from the post.

3) When created the new user set a role.

3) Now you can delete registration post for that user which is currently created.

I am giving you code label hints. This is for an idea. It will not work if you directly copy and paste.So take an idea to see the code.

From Registration form to custom post type data save

$post = array( 
            'post_title'=>$_POST['firstname'] . $_POST['lastname'], 
            'post_type'=>'registration', 
            'post_content'=>'',
            'post_status'   => 'publish',
            );
$registration_id = wp_insert_post($post);
update_post_meta($registration_id, 'email', $_POST['email']);
//wp_publish_post($registration_id);

added to extra field in user table

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>

  <h3>Extra profile information</h3>

  <table class="form-table">

    <tr>
      <th><label for="abn">ABN</label></th>

      <td>
        <input type="text" name="abn" id="abn" value="<?php echo esc_attr( get_the_author_meta( 'abn', $user->ID ) ); ?>" class="regular-text" /><br />
        <span class="description">Please enter your abn num.</span>
      </td>
    </tr>
    <tr>
      <th><label for="abn">Business Name</label></th>

      <td>
        <input type="text" name="BusinessName" id="BusinessName" value="<?php echo esc_attr( get_the_author_meta( 'BusinessName', $user->ID ) ); ?>" class="regular-text" /><br />
        <span class="description">Please enter your Business Name.</span>
      </td>
    </tr>
    <tr>
      <th><label for="abn">Business type</label></th>

      <td>
        <input type="text" name="Businesstype" id="Businesstype" value="<?php echo esc_attr( get_the_author_meta( 'Businesstype', $user->ID ) ); ?>" class="regular-text" /><br />
        <span class="description">Please enter your Business type.</span>
      </td>
    </tr>
  </table>
<?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

  if ( !current_user_can( 'edit_user', $user_id ) )
    return false;

  /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  update_usermeta( $user_id, 'abn', $_POST['abn'] );
  update_usermeta( $user_id, 'BusinessName', $_POST['BusinessName'] );
  update_usermeta( $user_id, 'Businesstype', $_POST['Businesstype'] );
}

Post types add column

//add bulk action in registration post types
add_filter('manage_edit-product_columns', 'my_extra_cake_columns');
function my_extra_cake_columns($columns) {
    $columns['slices'] =__('Create User');
    return $columns;
}


    add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
    add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );

    function my_save_extra_profile_fields( $user_id ) {

      if ( !current_user_can( 'edit_user', $user_id ) )
        return false;

      /* Copy and paste this line for additional fields. */
      update_usermeta( $user_id, 'abn', $_POST['abn'] );
      update_usermeta( $user_id, 'BusinessName', $_POST['BusinessName'] );
      update_usermeta( $user_id, 'Businesstype', $_POST['Businesstype'] );
    }

add_action( 'manage_product_posts_custom_column', 'my_cake_column_content', 10, 2 );
function my_cake_column_content( $column_name, $post_id ) {
    if ( 'slices' != $column_name )
        return;
    echo '<a href="#">Add as user</a>';
}

add_filter( 'manage_edit-product_sortable_columns', 'my_sortable_cake_column' );
function my_sortable_cake_column( $columns ) {
    $columns['slices'] = 'slice';
    return $columns;
}

create User and send mail

//How to Create User
$fname = get_post_meta($post_id,'firstname',true);
$lname = get_post_meta($post_id,'lastname',true);
$email_address = get_post_meta($post_id,'email',true);
$password = rand(); //create random password 
$user_id = wp_create_user( $email_address, $password, $email_address );
          // Set the nickname
          wp_update_user(
            array(
              'ID'          =>    $user_id,
              'nickname'    =>    $email_address,
              'first_name'  =>    $fname,
              'last_name'   =>    $lname
            )
          );

          // Set the role
          $user = new WP_User( $user_id );

//delete that post
wp_delete_post( $post_id ); 
// Email the user
wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );

Another Thing you can also use gravityforms.It has also functionality to create the user after registration. Its a paid plugins.

Hope the idea will work for you. Please let me know if you have any other query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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