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

Behavior and parameters