Login Redirect
Less than 1 minute
Definition
class AAM_Framework_Service_LoginRedirect {
public set_redirect(array $redirect) : bool
public get_redirect() : array
public reset() : bool
}
set_redirect
Define how to handle user workflow after successful authentication.
The $redirect argument is an array with set of properties as following:
array (
'type' => string,
'redirect_page_id' => int,
'redirect_page_slug' => string,
'redirect_url' => string,
'callback' => string
)
| Property | Description |
|---|---|
type | Required. Specifies the type of redirect. Accepted types are listed below. |
redirect_page_id | Required if type is "page_redirect". Must reference a valid, existing page ID. |
redirect_page_slug | Required if type is "page_redirect". Must reference a valid, existing page slug. |
redirect_url | Required if type is "url_redirect". Must provide a valid absolute URL (e.g., https://example.com/path) or a relative path (e.g., /path). |
callback | Required if type is "trigger_callback". Must be a valid PHP callback function verified using is_callable. |
The accepted redirect types are:
default: trigger default WordPress core behaviorpage_redirect: redirect to pageurl_redirect: safely redirect to URLtrigger_callback: trigger valid callback function that either handles redirect or returns safe URL for redirect.
The following code redirects users with the Subscriber role to provided URL:
AAM::api()->login_redirect('role:subscriber')->set_redirect([
'type' => 'url_redirect',
'redirect_url' => '/subscribers-home-page'
]);
get_redirect
Get currently defined login redirect for user admin. If no redirect is defined, the method will return an array with type equals default.
AAM::api()->login_redirect('user:admin')->get_redirect();