The gform_user_registration_login_redirect_url filter allows you to modify the redirect URL after a user logs in using the User Registration add-on login widget.
Usage
add_filter('gform_user_registration_login_redirect_url', 'your_function_name', 10, 2);
Parameters
- $login_redirect (string) – The URL to which the user will be redirected after a successful login.
- $sign_on (object) – The user object if the login is successful, otherwise an error.
More information
See Gravity Forms Docs: gform_user_registration_login_redirect_url
This filter was introduced in the User Registration version 3.2.
Source code location: GF_User_Registration::handle_login_submission() in gravityformsuserregistration/class-gf-user-registration.php
.
Examples
Redirect all users to a custom URL
add_filter('gform_user_registration_login_redirect_url', 'redirect_to_custom_url', 10, 2); function redirect_to_custom_url($login_redirect, $sign_on) { // Redirect all users to the "My Account" page return 'https://localhost/wp.dev/my-account/'; }
Redirect users based on their role
add_filter('gform_user_registration_login_redirect_url', 'redirect_based_on_role', 10, 2); function redirect_based_on_role($login_redirect, $sign_on) { if (in_array('administrator', $sign_on->roles)) { // Redirect administrators to the admin dashboard $login_redirect = 'https://example.com/wp-admin/'; } else { // Redirect all other users to the "My Account" page $login_redirect = 'https://example.com/my-account/'; } return $login_redirect; }
Redirect users to their profile page
add_filter('gform_user_registration_login_redirect_url', 'redirect_to_profile_page', 10, 2); function redirect_to_profile_page($login_redirect, $sign_on) { // Redirect users to their profile page return home_url('/profile/' . $sign_on->user_login); }
Redirect users based on a custom user meta
add_filter('gform_user_registration_login_redirect_url', 'redirect_based_on_custom_meta', 10, 2); function redirect_based_on_custom_meta($login_redirect, $sign_on) { $user_id = $sign_on->ID; $user_custom_meta = get_user_meta($user_id, 'custom_meta_key', true); if ('value1' === $user_custom_meta) { $login_redirect = 'https://example.com/page1/'; } elseif ('value2' === $user_custom_meta) { $login_redirect = 'https://example.com/page2/'; } return $login_redirect; }
Redirect users to a custom URL with a query string
add_filter('gform_user_registration_login_redirect_url', 'redirect_with_query_string', 10, 2); function redirect_with_query_string($login_redirect, $sign_on) { // Redirect users to a custom URL with their username as a query string return home_url('/welcome/?username=' . urlencode($sign_on->user_login)); }