Advertisement
wardhanarizaldi

WP custom login functions

Jan 26th, 2020
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. /* Main redirection of the default login page */
  2. function redirect_login_page() {
  3.     $login_page  = home_url('/login/');
  4.     $page_viewed = basename($_SERVER['REQUEST_URI']);
  5.  
  6.     if($page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
  7.         wp_redirect($login_page);
  8.         exit;
  9.     }
  10. }
  11. add_action('init','redirect_login_page');
  12.  
  13. /* Where to go if a login failed */
  14. function custom_login_failed() {
  15.     $login_page  = home_url('/login/');
  16.     wp_redirect($login_page . '?login=failed');
  17.     exit;
  18. }
  19. add_action('wp_login_failed', 'custom_login_failed');
  20.  
  21. /* Where to go if any of the fields were empty */
  22. function verify_user_pass($user, $username, $password) {
  23.     $login_page  = home_url('/login/');
  24.     if($username == "" || $password == "") {
  25.         wp_redirect($login_page . "?login=empty");
  26.         exit;
  27.     }
  28. }
  29. add_filter('authenticate', 'verify_user_pass', 1, 3);
  30.  
  31. /* What to do on logout */
  32. function logout_redirect() {
  33.     $login_page  = home_url('/login/');
  34.     wp_redirect($login_page . "?login=false");
  35.     exit;
  36. }
  37. add_action('wp_logout','logout_redirect');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement