Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. $args = array(
  2. 'echo' => true,
  3. 'redirect' => site_url( $_SERVER['REQUEST_URI'] ),
  4. 'form_id' => 'loginform',
  5. 'label_username' => __( 'Username' ),
  6. 'label_password' => __( 'Password' ),
  7. 'label_remember' => __( 'Remember Me' ),
  8. 'label_log_in' => __( 'Log In' ),
  9. 'id_username' => 'user_login',
  10. 'id_password' => 'user_pass',
  11. 'id_remember' => 'rememberme',
  12. 'id_submit' => 'wp-submit',
  13. 'remember' => true,
  14. 'value_username' => NULL,
  15. 'value_remember' => false );
  16.  
  17. wp_login_form( $args );
  18.  
  19. /**
  20. * Function Name: front_end_login_fail.
  21. * Description: This redirects the failed login to the custom login page instead of default login page with a modified url
  22. **/
  23. add_action( 'wp_login_failed', 'front_end_login_fail' );
  24. function front_end_login_fail( $username ) {
  25.  
  26. // Getting URL of the login page
  27. $referrer = $_SERVER['HTTP_REFERER'];
  28. // if there's a valid referrer, and it's not the default log-in screen
  29. if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) {
  30. wp_redirect( get_permalink( LOGIN_PAGE_ID ) . "?login=failed" );
  31. exit;
  32. }
  33.  
  34. }
  35.  
  36. /**
  37. * Function Name: check_username_password.
  38. * Description: This redirects to the custom login page if user name or password is empty with a modified url
  39. **/
  40. add_action( 'authenticate', 'check_username_password', 1, 3);
  41. function check_username_password( $login, $username, $password ) {
  42.  
  43. // Getting URL of the login page
  44. $referrer = $_SERVER['HTTP_REFERER'];
  45.  
  46. // if there's a valid referrer, and it's not the default log-in screen
  47. if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) {
  48. if( $username == "" || $password == "" ){
  49. wp_redirect( get_permalink( LOGIN_PAGE_ID ) . "?login=empty" );
  50. exit;
  51. }
  52. }
  53.  
  54. }
  55. // Replace my constant 'LOGIN_PAGE_ID' with your custom login page id.
  56.  
  57. <div class="wp_login_error">
  58. <?php if( isset( $_GET['login'] ) && $_GET['login'] == 'failed' ) { ?>
  59. <p>The password you entered is incorrect, Please try again.</p>
  60. <?php }
  61. else if( isset( $_GET['login'] ) && $_GET['login'] == 'empty' ) { ?>
  62. <p>Please enter both username and password.</p>
  63. <?php } ?>
  64. </div>
  65.  
  66. site_url($_SERVER['REQUEST_URI'] );
  67.  
  68. 'redirect' => get_permalink()
  69.  
  70. add_action('wp_login_failed', '_login_failed_redirect');
  71.  
  72. function _login_failed_redirect( $username ){
  73.  
  74. //get your page by slug and then its permalink
  75. $post = get_page_by_path('slug');
  76.  
  77. //Or you can get your page ID, if you are assigning a custom template to a page.
  78. $redirect_page = !empty ( $post ) ? get_permalink ( $post->ID ) : site_url();
  79.  
  80. $user = get_user_by('login', $username );
  81.  
  82. if(!$user){
  83. //Username incorrect
  84. wp_redirect($redirect_page .'?login_error=1');
  85.  
  86. }else{
  87. //Username Password combination incoorect
  88. wp_redirect($redirect_page .'?login_error=2');
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement