Logout Redirect
Less than 1 minute
Definition
class AAM_Framework_Service_LogoutRedirect {
public set_redirect(array $redirect) : bool
public get_redirect() : array
public reset() : bool
}
set_redirect
Define how to handle user workflow after successful logout.
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 Administrator role to page with slug home:
AAM::api()->logout_redirect('role:administrator')->set_redirect([
'type' => 'page_redirect',
'redirect_page_slug' => 'home'
]);
get_redirect
Get currently defined logout redirect for users with the Administrator role. If no redirect is defined, the method will return an array with type equals default.
AAM::api()->logout_redirect('role:administrator')->get_redirect();