bbp_logged_in_redirect

Redirect a user back to their profile if they are already logged in.

Description

bbp_logged_in_redirect( (string) $url = '' ); 

This should be used before is called in template files where the user should never have access to the contents of that file.

Parameters (1)

0. $url — Optional. (string) => ''
The URL to redirect to

Usage

  1. if ( !function_exists( 'bbp_logged_in_redirect' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // The URL to redirect to 
  5. $url = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_logged_in_redirect($url); 
  9.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_logged_in_redirect( $url = '' ) { 
  2.  
  3. // Bail if user is not logged in 
  4. if ( !is_user_logged_in() ) 
  5. return; 
  6.  
  7. // Setup the profile page to redirect to 
  8. $redirect_to = !empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() ); 
  9.  
  10. // Do a safe redirect and exit 
  11. wp_safe_redirect( $redirect_to ); 
  12. exit;