bp_core_login_redirect

When a user logs in, redirect him in a logical way.

Description

(string) bp_core_login_redirect( (string) $redirect_to, (string) $redirect_to_raw, (WP_User) $user ); 

Returns (string)

The redirect URL.

Parameters (3)

0. $redirect_to (string)
The URL to be redirected to, sanitized in wp-login.php.
1. $redirect_to_raw (string)
The unsanitized redirect_to URL ($_REQUEST['redirect_to']).
2. $user (WP_User)
The WP_User object corresponding to a successfully logged-in user. Otherwise a WP_Error object.

Usage

  1. if ( !function_exists( 'bp_core_login_redirect' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // The URL to be redirected to, sanitized in wp-login.php. 
  5. $redirect_to = ''; 
  6.  
  7. // The unsanitized redirect_to URL ($_REQUEST['redirect_to']). 
  8. $redirect_to_raw = ''; 
  9.  
  10. // The WP_User object corresponding to a successfully 
  11. // logged-in user. Otherwise a WP_Error object. 
  12. $user = null; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = bp_core_login_redirect($redirect_to, $redirect_to_raw, $user); 
  16.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-filters.php  
  1. function bp_core_login_redirect( $redirect_to, $redirect_to_raw, $user ) { 
  2.  
  3. // Only modify the redirect if we're on the main BP blog. 
  4. if ( !bp_is_root_blog() ) { 
  5. return $redirect_to; 
  6.  
  7. // Only modify the redirect once the user is logged in. 
  8. if ( !is_a( $user, 'WP_User' ) ) { 
  9. return $redirect_to; 
  10.  
  11. /** 
  12. * Filters whether or not to redirect. 
  13. * Allows plugins to have finer grained control of redirect upon login. 
  14. * @since 1.6.0 
  15. * @param bool $value Whether or not to redirect. 
  16. * @param string $redirect_to Sanitized URL to be redirected to. 
  17. * @param string $redirect_to_raw Unsanitized URL to be redirected to. 
  18. * @param WP_User $user The WP_User object corresponding to a 
  19. * successfully logged in user. 
  20. */ 
  21. $maybe_redirect = apply_filters( 'bp_core_login_redirect', false, $redirect_to, $redirect_to_raw, $user ); 
  22. if ( false !== $maybe_redirect ) { 
  23. return $maybe_redirect; 
  24.  
  25. // If a 'redirect_to' parameter has been passed that contains 'wp-admin', verify that the 
  26. // logged-in user has any business to conduct in the Dashboard before allowing the 
  27. // redirect to go through. 
  28. if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) { 
  29. return $redirect_to; 
  30.  
  31. if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) ) { 
  32. return wp_get_referer(); 
  33.  
  34. /** 
  35. * Filters the URL to redirect users to upon successful login. 
  36. * @since 1.9.0 
  37. * @param string $value URL to redirect to. 
  38. */