Home » Thiết kế web
1 | <script type="text/javascript"> |
1 | <script type="text/javascript"> |
![]() |
| Color Code HTML |
1 2 3 4 | <?php/* Template Name: Login Page */ |
1 | wp_login_form(); |
1 2 3 4 5 6 7 8 | $args = array('redirect' => site_url( $_SERVER['REQUEST_URI'] ),'form_id' => 'dangnhap', //Để dành viết CSS'label_username' => __( 'Tên tài khoản' ),'label_password' => __( 'Mật khẩu' ),'label_remember' => __( 'Ghi nhớ' ),'label_log_in' => __( 'Đăng nhập' ),); |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php/* Template Name: Login Page */?><div class="login-area"> <div class="note"> <h3>Đăng nhập</h3> <p>Hãy sử dụng tài khoản của bạn để đăng nhập vào website. Nếu chưa có tài khoản, <a href="<?php bloginfo('url'); ?>/wp-login.php?action=register">đăng ký tại đây</a>.</p> </div> <div class="form"> <?php $args = array( 'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 'form_id' => 'dangnhap', //Để dành viết CSS 'label_username' => __( 'Tên tài khoản' ), 'label_password' => __( 'Mật khẩu' ), 'label_remember' => __( 'Ghi nhớ' ), 'label_log_in' => __( 'Đăng nhập' ), ); wp_login_form($args); ?> </div></div> |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <style> body { background: #2E8D41; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.5em; } .login-area { background: #FFF; margin: 100px auto; width: 960px; padding: 1em; overflow: hidden; } .note { float: left; margin-right: 20px; } .form { float: right; width: 250px; text-align: center; } label { display: block; } input, input, input, input, input, input, input, select, textarea { border: 1px solid #DDD; -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07); background-color: #FFF; color: #333; -webkit-transition: .05s border-color ease-in-out; transition: .05s border-color ease-in-out; padding: 5px 10px; } input { background: #51a818; background-image: -webkit-linear-gradient(top, #51a818, #3d8010); background-image: -moz-linear-gradient(top, #51a818, #3d8010); background-image: -ms-linear-gradient(top, #51a818, #3d8010); background-image: -o-linear-gradient(top, #51a818, #3d8010); background-image: linear-gradient(to bottom, #51a818, #3d8010); -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; font-family: Arial; color: #ffffff; padding: 10px 20px 10px 20px; border: solid #32a840 2px; text-decoration: none; }</style> |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 | /* Tự động chuyển đến một trang khác sau khi login */function my_login_redirect( $redirect_to, $request, $user ) { //is there a user to check? global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { //check for admins if ( in_array( 'administrator', $user->roles ) ) { // redirect them to the default place return admin_url(); } else { return home_url(); } } else { return $redirect_to; }}add_filter( 'login_redirect', 'my_login_redirect', 10, 3 ); |
admin_url()), còn thành viên bình thường nó sẽ trỏ tới trang chủ (home_url()).01 02 03 04 05 06 07 08 09 10 | function redirect_login_page() { $login_page = home_url( '/dang-nhap/' ); $page_viewed = basename($_SERVER['REQUEST_URI']); if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') { wp_redirect($login_page); exit; }}add_action('init','redirect_login_page'); |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 | /* Kiểm tra lỗi đăng nhập */function login_failed() { $login_page = home_url( '/dang-nhap/' ); wp_redirect( $login_page . '?login=failed' ); exit;}add_action( 'wp_login_failed', 'login_failed' ); function verify_username_password( $user, $username, $password ) { $login_page = home_url( '/dang-nhap/' ); if( $username == "" || $password == "" ) { wp_redirect( $login_page . "?login=empty" ); exit; }}add_filter( 'authenticate', 'verify_username_password', 1, 3); |
01 02 03 04 05 06 07 08 09 10 | <?php $login = (isset($_GET['login']) ) ? $_GET['login'] : 0; if ( $login === "failed" ) { echo '<p><strong>ERROR:</strong> Sai username hoặc mật khẩu.</p>'; } elseif ( $login === "empty" ) { echo '<p><strong>ERROR:</strong> Username và mật khẩu không thể bỏ trống.</p>'; } elseif ( $login === "false" ) { echo '<p><strong>ERROR:</strong> Bạn đã thoát ra.</p>'; }?> |
