1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Auto register wordpress after submit signup form?

Discussion in 'Content Management' started by Kinda Intellectual, Jun 24, 2013.

  1. #1
    I have a signup form for my free hosting site, how can I get the information from that form to auto create a user on wordpress?
     
    Kinda Intellectual, Jun 24, 2013 IP
  2. homer7

    homer7 Well-Known Member

    Messages:
    268
    Likes Received:
    25
    Best Answers:
    4
    Trophy Points:
    125
    #2
    search if there are already plugins doing that task
    pretty sure there are some.
     
    homer7, Jun 29, 2013 IP
  3. vikaskumarbhardwaj

    vikaskumarbhardwaj Banned

    Messages:
    83
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    98
    Digital Goods:
    1
    #3
    You must have some knowledge about php and html form to do this extensive functionality.
    As this is a advance level work so i am not going to explain every steps for simple html form.

    But before starting make sure you have working html form on your remote server, decide how you want to handle
    errors- via ajax or page redirect and make some security modifications for CSF scripts. You must check that post is coming from your server only. Now submit your from on your site with $_GET['register_from_remote'] value on your server. And paste these codes in functions.php and handle your error or success message as you wish.
    add_action('init','register_from_remote');
    function register_from_remote(){
        if ($_GET['register_from_remote']/*or your specific post validateor*/) {
            if($_POST['user_name'] && $_POST['email_address']){
                $user_login = sanitize_user( str_replace(" ","",$_POST['user_name']) );
                $user_email = trim($_POST['email_address']);
                  require_once( ABSPATH . WPINC . '/registration-functions.php');
        
                $errors = register_user($user_login, $user_email);
                if(!is_wp_error($errors)){
                    echo 'User have been added';
                }else {
                    ?>
                    <div class="error flash">
            <ul>
            <?php
            foreach($errors as $error) {
              if(count($error) > 0) {foreach($error as $e) echo "<li>".$e[0]."</li>";}
            }
          ?>
          </ul>
        </div>
                <?php }
            }else{
                echo 'Sorry either you have not entered user name or email address ';
             
            }
        }
    }
     
    function register_user($user_login,$user_email,$other_info=array()){
          $errors = new WP_Error();
          $sanitized_user_login = sanitize_user( $user_login );
          $user_email = apply_filters( 'user_registration_email', $user_email );
     
    // Check the username
          if ($sanitized_user_login =='') {
          $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.', 'themeshive' ) );
        } elseif (!validate_username($user_login)) {
          $errors->add('invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses                   illegal characters. Please enter a valid username.', 'themeshive' ) );
          $sanitized_user_login = '';
          } elseif ( username_exists( $sanitized_user_login ) ) {
            $errors->add('username_exists', __( '<strong>ERROR</strong>: This username is already registered, please                 choose another one.', 'themeshive' )  );
     
            }
     
          // Check the e-mail address
            if ( $user_email == '' ) {
                  $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.', '                            themeshive' ) );
           } elseif ( ! is_email( $user_email ) ) {
                $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.', '                     themeshive' )  );
            $user_email = '';
          } elseif ( email_exists( $user_email ) ) {
              $errors->add(  'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please                       choose another one.', 'themeshive' )   );
            }
            
          do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
          $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
          
          if ($errors->get_error_code()){
              //do_dump($errors);
              return $errors;
          }
          $user_pass = wp_generate_password( 12, false);
          $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
          if (! $user_id) {
              $errors->add(  'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you...                        please contact the <a href="mailto:%s">webmaster</a> !', 'themeshive' ), get_option( '                        admin_email' ) ) 
                      );
            return $errors;
          }
     
          update_user_meta( $user_id, 'credits','0' ); 
     
          update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
          wp_new_user_notification( $user_id, $user_pass );
          do_action('themeshive_user_registered', $user_id);
          return $user_id;
      }
     
    
    PHP:
     
    Last edited: Jun 29, 2013
    vikaskumarbhardwaj, Jun 29, 2013 IP