uo_do_logout_redirect
Filters the logout redirect URL, allowing modification before the user is redirected after logging out.
add_filter( 'uo_do_logout_redirect', $callback, 10, 1 );
Description
Filters the redirect URL after a user logs out. Allows developers to customize the logout redirect destination, returning the new URL or `false` to prevent redirection. This filter fires after the logout process but before the actual redirect occurs.
Usage
add_filter( 'uo_do_logout_redirect', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'uo_do_logout_redirect', 'my_custom_logout_redirect', 10, 1 );
/**
* Example function to conditionally disable the default logout redirect.
*
* This filter allows developers to programmatically control whether the
* plugin's default logout redirect functionality is active.
*
* @param bool $default_behavior The default boolean value (usually true).
* @return bool Whether to proceed with the logout redirect.
*/
function my_custom_logout_redirect( $default_behavior ) {
// Example: Disable logout redirect if a specific user role is logged in.
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
// Check if the user has the 'administrator' role.
if ( in_array( 'administrator', $current_user->roles ) ) {
// Don't perform the redirect for administrators.
return false;
}
}
// Otherwise, use the default behavior.
return $default_behavior;
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/login-redirect.php:48
public static function run_frontend_hooks() {
if ( true === self::dependants_exist() ) {
$redirect_priority = 999;
$settings = get_option( 'LoginRedirect', Array() );
if ( ! empty( $settings ) ) {
foreach ( $settings as $setting ) {
if ( 'redirect_priority' === $setting['name'] ) {
$redirect_priority = $setting['value'];
}
}
}
if ( empty( $redirect_priority ) ) {
$redirect_priority = 999;
}
$do_login_redirect = apply_filters( 'uo_do_login_redirect', true );
if( $do_login_redirect ){
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ), $redirect_priority, 3 );
}
$do_logout_redirect = apply_filters( 'uo_do_logout_redirect', true );
if( $do_logout_redirect ){
add_action( 'wp_logout', array( __CLASS__, 'logout_redirect' ), 1, 1 );
}
}
}