Snippet allowing you to replace the url after logging in to FluentCommunity.
/**
* Robust redirect after login for FluentCommunity/FluentAuth/WordPress.
* Tries multiple hooks + supports AJAX JSON responses. Adds debug logs to debug.log.
*/
// configure your target URL here:
$fc_target_after_login_url = 'https://google.com';
// --- helper debug logger (do debug.log) ---
if (!function_exists('fc_debug_log')) {
function fc_debug_log($msg) {
if (defined('WP_DEBUG') && WP_DEBUG) {
if (is_array($msg) || is_object($msg)) {
error_log('[FC-REDIRECT] ' . print_r($msg, true));
} else {
error_log('[FC-REDIRECT] ' . $msg);
}
}
}
}
// 1) Classic WP login_redirect filter (wysoki priorytet)
add_filter('login_redirect', function($redirect_to, $request, $user) use ($fc_target_after_login_url) {
fc_debug_log("login_redirect called; user: " . (is_object($user) ? $user->user_login : 'no-user'));
if (is_a($user, 'WP_User')) {
return $fc_target_after_login_url;
}
return $redirect_to;
}, 99999, 3);
// 2) wp_login action — zapis meta (fallback dla AJAX)
add_action('wp_login', function($user_login, $user) use ($fc_target_after_login_url) {
fc_debug_log("wp_login fired for user: {$user_login}");
if ($user instanceof WP_User) {
update_user_meta($user->ID, '_fc_after_login_redirect', $fc_target_after_login_url);
}
}, 10, 2);
// 3) fluent_community_after_login — jeśli ten hook istnieje w Twojej instalacji (non-AJAX)
add_action('fluent_community_after_login', function ($user_id) use ($fc_target_after_login_url) {
fc_debug_log("fluent_community_after_login fired for user_id: {$user_id}");
if (!$user_id) return;
// jeśli to nie AJAX — zrób redirect
if (! (defined('DOING_AJAX') && DOING_AJAX) ) {
wp_safe_redirect($fc_target_after_login_url);
exit;
}
// jeśli AJAX — spróbujemy nadpisać JSON response (patrz filter poniżej)
}, 10, 1);
// 4) fluent_community_login_response — modyfikuj JSON response (jeśli FluentCommunity używa tego filtra)
add_filter('fluent_community_login_response', function($response) use ($fc_target_after_login_url) {
fc_debug_log("fluent_community_login_response filter called; original response: " . json_encode($response));
if (is_array($response)) {
$response['redirect_to'] = $fc_target_after_login_url;
}
return $response;
});
// 5) Init-based redirect if user meta was set (fallback przy pierwszym pełnym żądaniu)
add_action('init', function() {
if (!is_user_logged_in()) return;
$user_id = get_current_user_id();
$redirect_url = get_user_meta($user_id, '_fc_after_login_redirect', true);
if ($redirect_url) {
// usuń meta zanim przekierujesz, żeby nie zapętlić
delete_user_meta($user_id, '_fc_after_login_redirect');
// unikaj przekierowania w WP adminie lub w AJAX
if (!is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
fc_debug_log("init redirecting user {$user_id} to {$redirect_url}");
wp_safe_redirect($redirect_url);
exit;
}
}
});\
What function does it apply to?
Giovanni Augusto It allows you to replace the link to the page you'll be redirected to when you log in using the fluentcommunity login page. I use this along with a snippet that allows you to use shortcodes to display and block content on a specially prepared "My Account" page.
And you really are an adventurer)