Not found redirect
Overview
Configure the workflow for a WordPress 404 response. Select the subject with AAM::api()->not_found_redirect($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_NotFoundRedirect.
Method reference
| Method | Purpose |
|---|---|
get_redirect() |
Read the effective redirect. |
set_redirect(array $redirect) |
Store a redirect model. |
reset() |
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. set_redirect() takes a redirect model array for the selected access level; get_redirect() and reset() take no target. See the example below for the model shape.
Example
$redirect = AAM::api()->not_found_redirect('role:subscriber');
$redirect->set_redirect([
'type' => 'url_redirect',
'redirect_url' => '/help/'
]);
When a Subscriber reaches a WordPress 404 page, AAM uses /help/ as the redirect destination.
Developer notes
- Use this preference for 404 handling; access denied uses its own service.
- Test the result through a real request because WordPress controls when a request becomes a 404.
- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
set_redirect($redirect)stores a redirect model;get_redirect()resolves the effective model;reset()removes the selected level’s override.- The model needs a
type:defaultuses WordPress behavior,url_redirectusesredirect_url,page_redirectuses a page identifier, andtrigger_callbackuses a callable callback. This service also acceptslogin_redirect. - Use a relative path for an on-site destination. Test the actual WordPress event because the PHP framework stores the preference while the plugin handles the redirect during a request.