bbp_logout_url( string $url = '', string $redirect_to = '' )
Return a clean and reliable logout URL
Description Description
This function is used to filter logout_url
. If no $redirect_to value is passed, it will default to the request uri, then the forum root.
See: wp_logout_url()
Parameters Parameters
- $url
-
(Optional) URL used to log out
Default value: ''
- $redirect_to
-
(Optional) Where to redirect to?
Default value: ''
Return Return
(string) The url
Source Source
File: includes/common/functions.php
function bbp_logout_url( $url = '', $redirect_to = '' ) { // If there is no redirect in the URL, let's add one... if ( ! strstr( $url, 'redirect_to' ) ) { // Get the forum root, to maybe use as a default $forum_root = bbp_get_root_url(); // No redirect passed, so check referer and fallback to request uri if ( empty( $redirect_to ) ) { // Check for a valid referer $redirect_to = wp_get_referer(); // Fallback to request uri if invalid referer if ( false === $redirect_to ) { $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } } // Filter the $redirect_to destination $filtered = apply_filters( 'bbp_logout_url_redirect_to', $redirect_to ); // Validate $redirect_to, default to root $validated = wp_validate_redirect( $filtered, $forum_root ); // Assemble $redirect_to and add it (encoded) to full $url $appended = add_query_arg( array( 'loggedout' => 'true' ), $validated ); $encoded = urlencode( $appended ); $url = add_query_arg( array( 'redirect_to' => $encoded ), $url ); } // Filter & return return apply_filters( 'bbp_logout_url', $url, $redirect_to ); }
Changelog Changelog
Version | Description |
---|---|
2.1.0 | Introduced. |