phpface

WP filter login and logout URLs

Dec 21st, 2021 (edited)
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. /**
  2.  * Filter login url
  3.  */
  4. function streamtube_child_filter_login_url( $login_url, $redirect, $force_reauth  ){
  5.  
  6.     // Define your custom login url here
  7.     $new_login_url = 'your custom login url';
  8.  
  9.     if ( ! empty( $redirect ) ) {
  10.         $custom_login_page_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $new_login_url );
  11.     }
  12.  
  13.     if ( $force_reauth ) {
  14.         $new_login_url = add_query_arg( 'reauth', '1', $login_url );
  15.     }  
  16.  
  17.     return $new_login_url;
  18.  
  19. }
  20. add_filter( 'login_url', 'streamtube_child_filter_login_url', 100, 3 );
  21.  
  22. /**
  23.  *
  24.  * Filter logout url
  25.  *
  26.  */
  27. function streamtube_child_filter_logout_url( $logout_url, $redirect ){
  28.  
  29.     // Define your custom logout url here
  30.     $new_logout_url = 'your custom logout url';
  31.  
  32.     $args = array();
  33.  
  34.     if ( ! empty( $redirect ) ) {
  35.         $args['redirect_to'] = urlencode( $redirect );
  36.     }
  37.  
  38.     $new_logout_url = add_query_arg( $args, $new_logout_url );
  39.     $new_logout_url = wp_nonce_url( $new_logout_url, 'log-out' );
  40.  
  41.     return $new_logout_url;
  42. }
  43. add_filter( 'logout_url', 'streamtube_child_filter_logout_url', 100, 2 );
Add Comment
Please, Sign In to add comment