Skip to main content

Logout Redirect

Vasyl MartyniukLess 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
)
PropertyDescription
typeRequired. Specifies the type of redirect. Accepted types are listed below.
redirect_page_idRequired if type is "page_redirect". Must reference a valid, existing page ID.
redirect_page_slugRequired if type is "page_redirect". Must reference a valid, existing page slug.
redirect_urlRequired if type is "url_redirect". Must provide a valid absolute URL (e.g., https://example.com/path) or a relative path (e.g., /path).
callbackRequired if type is "trigger_callback". Must be a valid PHP callback function verified using is_callableopen in new window.

The accepted redirect types are:

  • default: trigger default WordPress core behavior
  • page_redirect: redirect to page
  • url_redirect: safely redirect to URL
  • trigger_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();
Virtual Assistant