<?php
/* Template Name: Register Template */
if(is_user_logged_in()) { $user_id = get_current_user_id();$current_user = wp_get_current_user();$profile_url = get_author_posts_url($user_id);$edit_profile_url = get_edit_profile_url($user_id); ?>
<div class="regted">
You're login with nickname <a href="<?php echo $profile_url ?>"><?php echo $current_user->display_name; ?></a> Are you want to <a href="<?php echo esc_url(wp_logout_url($current_url)); ?>">Exit</a> ?
</div>
<?php } else { ?>
<div class="register">
<?php $err = ''; $success = ''; global $wpdb, $PasswordHash, $current_user, $user_ID; if(isset($_POST['task']) && $_POST['task'] == 'register' ) { $pwd1 = $wpdb->escape(trim($_POST['pwd1']));
$pwd2 = $wpdb->escape(trim($_POST['pwd2']));
$email = $wpdb->escape(trim($_POST['email']));
$username = $wpdb->escape(trim($_POST['username']));
if( $email == "" || $pwd1 == "" || $pwd2 == "" || $username == "") {
$err = 'Please enter password in this field';
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err = 'Email is invalid';
} else if(email_exists($email) ) {
$err = 'Email is existed';
} else if($pwd1 <> $pwd2 ){
$err = 'Password does not match the confirm password';
} else {
$user_id = wp_insert_user( array ('user_pass' => apply_filters('pre_user_user_pass', $pwd1), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'subscriber' ) );
if( is_wp_error($user_id) ) {
$err = 'Error on user creation.';
} else {
do_action('user_register', $user_id);
$success = 'Registered Successfully';
}
}
}
?>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!--display error/success message-->
<div id="message">
<?php
if(! empty($err) ) :
echo ''.$err.'';
endif;
?>
<?php
if(! empty($success) ) :
$login_page = home_url( '/login' );
echo ''.$success. '<a href='.$login_page.'> Login</a>'.'';
endif;
?>
</div>
<div class="container">
<div id="loginbox" style="margin-top:100px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div style="padding-bottom: 50px;" class="col-md-6 col-md-offset-4 col-sm-8 col-sm-offset-2"/><img src="#url.logo"></div>
<form class="form-horizontal" method="post" role="form">
<div class="form-group">
<label class="control-label col-sm-3" for="username">Username:</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="username" id="username" placeholder="Username">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-9">
<input type="email" class="form-control" name="email" id="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd1">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="pwd1" id="pwd1" placeholder="Enter your password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd2">Retype password:</label>
<div class="col-sm-9">
<input type="password" class="form-control" name="pwd2" id="pwd2" placeholder="Retype password">
</div>
</div>
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9" style="text-align:center;">
<button type="submit" class="btn btn-primary">Register</button>
<input type="hidden" name="task" value="register" /><br/>
</div>
</div>
</form>
</div>
</div>
</div>
<?php
get_footer();
?>
<div class="message">
<?php
$login = (isset($_GET['login']) ) ? $_GET['login'] : 0;
if ( $login === "failed" ) {
echo '<strong>Error</strong> Wrong username or password!';
} elseif ( $login === "empty" ) {
echo '<strong>Error:</strong>Username or password is blank field.';
} elseif ( $login === "false" ) {
echo '<strong>ERROR:</strong> Exit';
}
?>
</div>
<?php } ?>
Пример моей пользовательской страницы входа. Сохранение login.php и внесение кода
add_action('init','wpse_login');
function wpse_login(){
global $pagenow;
if( 'wp-login.php' == $pagenow && !is_user_logged_in()) {
wp_redirect('http://yoursite.com/login.php');
exit();
}
}
в functions.php