Wordpress/Woocommerce login/sign 向上页需要什么确切的代码
What exact code is needed for Wordpress/Woocommerce login/sign up pages
我正在使用 wordpress 和 woocommerce 创建一个小型电子商务网站,但我并不真正了解 login/signup 用户的能力。我只希望访问该站点的用户能够单击主页上的 link,在那里他们可以注册和登录(可以选择重置密码),在 return 中,这些客户详细信息是保存在用户数据中,以便 wordpress 管理员能够看到。这是什么编码?因为我似乎无法进入很多这些插件。
<?php
global $wpdb, $user_ID;
$firstname='';
$lastname='';
$username='';
$email='';
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
if(sanitize_text_field( $_POST['com_submit']) != ''){
$firstname=sanitize_text_field( $_REQUEST['com_firstname'] );
$lastname=sanitize_text_field( $_REQUEST['com_lastname']);
$username = sanitize_text_field( $_REQUEST['com_username'] );
$email = sanitize_text_field( $_REQUEST['com_email'] );
$password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
$status = wp_create_user($username,$password,$email);
if (is_wp_error($status)) {
$error_msg = __('Username or Email already registered. Please try another one.','twentyten');
}
else{
$user_id=$status;
update_user_meta( $user_id,'first_name', $firstname);
update_user_meta( $user_id,'last_name', $lastname);
//code to auto login start
$alar_enable_auto_login= get_option('alar_enable_auto_login');
if($alar_enable_auto_login==''){
$alar_enable_auto_login= 'true';
}
if($alar_enable_auto_login == 'true'){
if(!is_user_logged_in()){
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($user_id, true, $secure_cookie);
$user_info = get_userdata($user_id);
do_action('wp_login', $user_info->user_login, $user_info);
}
}
//code to auto login end
wp_redirect( get_option('home') );// redirect to home page
exit;
}
}
?>
<div class="alar-registration-form">
<div class="alar-registration-heading">
<?php _e("Registration Form",'');?>
</div>
<?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php } ?>
<form name="form" id="registration" method="post">
<div class="ftxt">
<label><?php _e("First Name :",'');?></label>
<input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $firstname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Last name :",'');?></label>
<input id="com_lastname" name="com_lastname" type="text" class="input" required value=<?php echo $lastname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Username :",'');?></label>
<input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
</div>
<div class="ftxt">
<label><?php _e("E-mail :",'');?> </label>
<input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
</div>
<div class="ftxt">
<label><?php _e("Password :",'');?></label>
<input id="password1" name="com_password" type="password" required class="input" />
</div>
<div class="ftxt">
<label><?php _e("Confirm Password : ",'');?></label>
<input id="password2" name="c_password" type="password" class="input" />
</div>
<div class="fbtn"><input type="submit" name='com_submit' class="button" value="Register"/> </div>
</form>
</div>
<?php
}
//add registration shortcoode
add_shortcode( 'registration-form', 'alar_registration_shortcode' );
// function to login Shortcode
function alar_login_shortcode( $atts ) {
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
global $wpdb;
if(sanitize_text_field( $_GET['login'] ) != ''){
$login_fail_msg=sanitize_text_field( $_GET['login'] );
}
?>
<div class="alar-login-form">
<?php if($login_fail_msg=='failed'){?>
<div class="error" align="center"><?php _e('Username or password is incorrect','');?></div>
<?php }?>
<div class="alar-login-heading">
<?php _e("Login Form",'');?>
</div>
<form method="post" action="<?php echo get_option('home');?>/wp-login.php" id="loginform" name="loginform" >
<div class="ftxt">
<label><?php _e('Login ID :','');?> </label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" required name="log" />
</div>
<div class="ftxt">
<label><?php _e('Password :','');?> </label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" required name="pwd" />
</div>
<div class="fbtn">
<input type="submit" tabindex="100" value="Log In" class="button" id="wp-submit" name="wp-submit" />
<input type="hidden" value="<?php echo get_option('home');?>" name="redirect_to">
</div>
</form>
</div>
just copy and past This code where do you want to add register login form
我正在使用 wordpress 和 woocommerce 创建一个小型电子商务网站,但我并不真正了解 login/signup 用户的能力。我只希望访问该站点的用户能够单击主页上的 link,在那里他们可以注册和登录(可以选择重置密码),在 return 中,这些客户详细信息是保存在用户数据中,以便 wordpress 管理员能够看到。这是什么编码?因为我似乎无法进入很多这些插件。
<?php
global $wpdb, $user_ID;
$firstname='';
$lastname='';
$username='';
$email='';
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
if(sanitize_text_field( $_POST['com_submit']) != ''){
$firstname=sanitize_text_field( $_REQUEST['com_firstname'] );
$lastname=sanitize_text_field( $_REQUEST['com_lastname']);
$username = sanitize_text_field( $_REQUEST['com_username'] );
$email = sanitize_text_field( $_REQUEST['com_email'] );
$password = $wpdb->escape( sanitize_text_field( $_REQUEST['com_password']));
$status = wp_create_user($username,$password,$email);
if (is_wp_error($status)) {
$error_msg = __('Username or Email already registered. Please try another one.','twentyten');
}
else{
$user_id=$status;
update_user_meta( $user_id,'first_name', $firstname);
update_user_meta( $user_id,'last_name', $lastname);
//code to auto login start
$alar_enable_auto_login= get_option('alar_enable_auto_login');
if($alar_enable_auto_login==''){
$alar_enable_auto_login= 'true';
}
if($alar_enable_auto_login == 'true'){
if(!is_user_logged_in()){
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie;
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($user_id, true, $secure_cookie);
$user_info = get_userdata($user_id);
do_action('wp_login', $user_info->user_login, $user_info);
}
}
//code to auto login end
wp_redirect( get_option('home') );// redirect to home page
exit;
}
}
?>
<div class="alar-registration-form">
<div class="alar-registration-heading">
<?php _e("Registration Form",'');?>
</div>
<?php if($error_msg!='') { ?><div class="error"><?php echo $error_msg; ?></div><?php } ?>
<form name="form" id="registration" method="post">
<div class="ftxt">
<label><?php _e("First Name :",'');?></label>
<input id="com_firstname" name="com_firstname" type="text" class="input" required value=<?php echo $firstname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Last name :",'');?></label>
<input id="com_lastname" name="com_lastname" type="text" class="input" required value=<?php echo $lastname; ?> >
</div>
<div class="ftxt">
<label><?php _e("Username :",'');?></label>
<input id="com_username" name="com_username" type="text" class="input" required value=<?php echo $username; ?> >
</div>
<div class="ftxt">
<label><?php _e("E-mail :",'');?> </label>
<input id="com_email" name="com_email" type="email" class="input" required value=<?php echo $email; ?> >
</div>
<div class="ftxt">
<label><?php _e("Password :",'');?></label>
<input id="password1" name="com_password" type="password" required class="input" />
</div>
<div class="ftxt">
<label><?php _e("Confirm Password : ",'');?></label>
<input id="password2" name="c_password" type="password" class="input" />
</div>
<div class="fbtn"><input type="submit" name='com_submit' class="button" value="Register"/> </div>
</form>
</div>
<?php
}
//add registration shortcoode
add_shortcode( 'registration-form', 'alar_registration_shortcode' );
// function to login Shortcode
function alar_login_shortcode( $atts ) {
//if looged in rediret to home page
if ( is_user_logged_in() ) {
wp_redirect( get_option('home') );// redirect to home page
exit;
}
global $wpdb;
if(sanitize_text_field( $_GET['login'] ) != ''){
$login_fail_msg=sanitize_text_field( $_GET['login'] );
}
?>
<div class="alar-login-form">
<?php if($login_fail_msg=='failed'){?>
<div class="error" align="center"><?php _e('Username or password is incorrect','');?></div>
<?php }?>
<div class="alar-login-heading">
<?php _e("Login Form",'');?>
</div>
<form method="post" action="<?php echo get_option('home');?>/wp-login.php" id="loginform" name="loginform" >
<div class="ftxt">
<label><?php _e('Login ID :','');?> </label>
<input type="text" tabindex="10" size="20" value="" class="input" id="user_login" required name="log" />
</div>
<div class="ftxt">
<label><?php _e('Password :','');?> </label>
<input type="password" tabindex="20" size="20" value="" class="input" id="user_pass" required name="pwd" />
</div>
<div class="fbtn">
<input type="submit" tabindex="100" value="Log In" class="button" id="wp-submit" name="wp-submit" />
<input type="hidden" value="<?php echo get_option('home');?>" name="redirect_to">
</div>
</form>
</div>
just copy and past This code where do you want to add register login form