bbp_logout_url

Return a clean and reliable logout URL.

Description

(string) bbp_logout_url( (string) $url = '', (string) $redirect_to = '' ); 

Returns (string)

The url

Parameters (2)

0. $url — Optional. (string) => ''
The url.
1. $redirect_to — Optional. (string) => ''
Where to redirect to?

Usage

  1. if ( !function_exists( 'bbp_logout_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // The url. 
  5. $url = ''; 
  6.  
  7. // Where to redirect to? 
  8. $redirect_to = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_logout_url($url, $redirect_to); 
  12.  

Defined (1)

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

/includes/common/functions.php  
  1. function bbp_logout_url( $url = '', $redirect_to = '' ) { 
  2.  
  3. // Make sure we are directing somewhere 
  4. if ( empty( $redirect_to ) && !strstr( $url, 'redirect_to' ) ) { 
  5.  
  6. // Rejig the $redirect_to 
  7. if ( !isset( $_SERVER['REDIRECT_URL'] ) || ( $redirect_to !== home_url( $_SERVER['REDIRECT_URL'] ) ) ) { 
  8. $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ''; 
  9.  
  10. $redirect_to = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  11.  
  12. // Sanitize $redirect_to and add it to full $url 
  13. $redirect_to = add_query_arg( array( 'loggedout' => 'true' ), esc_url( $redirect_to ) ); 
  14. $url = add_query_arg( array( 'redirect_to' => urlencode( $redirect_to ) ), $url ); 
  15.  
  16. // Filter and return 
  17. return apply_filters( 'bbp_logout_url', $url, $redirect_to );