Access denied redirect
Overview
Configure the response after AAM denies access in a given site area. Select the subject with AAM::api()->access_denied_redirect($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_AccessDeniedRedirect.
Method reference
| Method | Purpose |
|---|---|
get_redirect($area = null) |
Read the effective redirect. |
set_redirect($area, array $redirect) |
Store a redirect model. |
reset($area = null) |
Remove one rule or all rules for this level. |
is_customized() |
Check for a direct rule or preference. |
Return values vary by method. Rule updates usually return bool; reads can return a value, null, or an array. Errors follow the service’s error_handling setting and may produce WP_Error.
Accepted identifiers
This service has no resource identifier. Pass an area such as 'frontend', 'backend', or 'api' to set_redirect($area, $redirect); the second argument is the redirect model. Omit the area from get_redirect() or reset() to work with the service’s overall configuration.
Example
$redirect = AAM::api()->access_denied_redirect('role:subscriber');
$redirect->set_redirect('frontend', [
'type' => 'url_redirect',
'redirect_url' => '/access-denied/'
]);
This sets the Subscriber role’s fallback for denied frontend requests. AAM redirects to /access-denied/ when that fallback is used; backend and API responses keep their own settings.
Developer notes
- Set the area explicitly, such as
frontend,backend, orapi. - A resource-specific redirect can take precedence over this fallback.
- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
set_redirect($area, $redirect)sets a response model for a site area.get_redirect($area = null)retrieves one area or all configured areas.reset($area = null)removes one override or all overrides.is_customized()reports whether this level has a direct configuration.- Supported areas include
frontend,backend, andapi. The redirect model requirestype; useful types includedefault,custom_message,page_redirect,url_redirect,trigger_callback, andlogin_redirect. - For
custom_message, passmessage; forurl_redirect, passredirect_url; forpage_redirect, passredirect_page_idorredirect_page_slug. API responses only supportdefault,custom_message, andtrigger_callback. A resource-specific redirect may override this fallback.