How to add the foreground registration function for WordPress

Source: Internet
Author: User

1. Add a registry ticket
1. First create a php file under the Directory of the current topic, name it reg-page.php, and then copy all the code in page. php to the reg-page.php;

2. Delete all comments starting with the reg-page.php, I .e./* and */, and all contents between them;

3. Search: the_content. Similar code can be found. <? Php the_content ();?>, Replace it with code 1 (note that it is saved using UTF-8 encoding)

If you cannot find the_content in the reg-page.php, you can find: get_template_part, you can find similar code: <? Php get_template_part ('content', 'page');?>, Replace all the code in the content-page.php with this code. Replace it with the following code <? Php the_content ();?>

Html

The code is as follows: Copy code

<? Php the_content ();?>
<? Php if (! Empty ($ error )){
Echo '<p class = "ludou-error">'. $ error. '</p> ';
}
If (! Is_user_logged_in () {?>
<Form name = "registerform" method = "post" action = "<? Php echo $ _ SERVER ["REQUEST_URI"];?> "Class =" ludou-reg ">
<P>
<Label for = "user_login"> user name <br/>
<Input type = "text" name = "user_login" id = "user_login" class = "input" value = "<? Php if (! Empty ($ sanitized_user_login) echo $ sanitized_user_login;?> "Size =" 20 "/>
</Label>
</P>

<P>
<Label for = "user_email"> email <br/>
<Input type = "text" name = "user_email" id = "user_email" class = "input" value = "<? Php if (! Empty ($ user_email) echo $ user_email;?> "Size =" 25 "/>
</Label>
</P>
   
<P>
<Label for = "user_pwd1"> password (at least 6 digits) <br/>
<Input id = "user_pwd1" class = "input" type = "password" tabindex = "21" size = "25" value = "" name = "user_pass"/>
</Label>
</P>
   
<P>
<Label for = "user_pwd2"> duplicate password <br/>
<Input id = "user_pwd2" class = "input" type = "password" tabindex = "21" size = "25" value = "" name = "user_pass2"/>
</Label>
</P>
   
<P class = "submit">
<Input type = "hidden" name = "ludou_reg" value = "OK"/>
<Input type = "submit" name = "wp-submit" id = "wp-submit" class = "button-primary button-large" value = "register"/>
</P>
</Form>
<? Php} else {
Echo '<p class = "ludou-error"> You have registered and logged on! </P> ';
}?>

Add Form processing code
At the beginning of the reg-page.php, place the first <? Php changed to code 2 (note the use of UTF-8 encoding to save ):


Php code

The code is as follows: Copy code

<? Php
 
If (! Empty ($ _ POST ['ludou _ reg ']) {
$ Error = '';
$ Sanitized_user_login = sanitize_user ($ _ POST ['User _ login']);
$ User_email = apply_filters ('User _ registration_email ', $ _ POST ['User _ email']);

// Check the username
If ($ sanitized_user_login = ''){
$ Error. = '<strong> error </strong>: enter the user name. <Br/> ';
} Elseif (! Validate_username ($ user_login )){
$ Error. = '<strong> error </strong>: The user name contains invalid characters. Enter a valid user name <br/>. ';
$ Sanitized_user_login = '';
} Elseif (username_exists ($ sanitized_user_login )){
$ Error. = '<strong> error </strong>: The user name has been registered. Please select another one. <Br/> ';
  }

// Check the e-mail address
If ($ user_email = ''){
$ Error. = '<strong> error </strong>: Enter the email address. <Br/> ';
} Elseif (! Is_email ($ user_email )){
$ Error. = '<strong> error </strong>: The email address is incorrect .! <Br/> ';
$ User_email = '';
} Elseif (email_exists ($ user_email )){
$ Error. = '<strong> error </strong>: The email address has been registered. Change it. <Br/> ';
  }
   
// Check the password
If (strlen ($ _ POST ['User _ pass']) <6)
$ Error. = '<strong> error </strong>: The password must contain at least six characters! <Br/> ';
Elseif ($ _ POST ['User _ pass']! = $ _ POST ['User _ pass2 '])
$ Error. = '<strong> error </strong>: The two passwords must be consistent! <Br/> ';
     
If ($ error = ''){
$ User_id = wp_create_user ($ sanitized_user_login, $ _ POST ['User _ pass'], $ user_email );
   
If (! $ User_id ){
$ Error. = sprintf ('<strong> error </strong>: your registration request cannot be completed... contact <a href = "mailto: % s"> administrator </a>! <Br/> ', get_option ('admin _ email '));
    }
Else if (! Is_user_logged_in ()){
$ User = get_userdatabylogin ($ sanitized_user_login );
$ User_id = $ user-> ID;
 
// Automatic logon
Wp_set_current_user ($ user_id, $ user_login );
Wp_set_auth_cookie ($ user_id );
Do_action ('WP _ login', $ user_login );
    }
  }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.