AAM::api()

AAM::api() returns the framework gateway. It resolves an access level, creates the requested service, and caches the service instance for that access level and settings.

$service = AAM::api()->posts('role:editor', [
    'error_handling' => 'wp_error'
]);

Arguments

Argument Meaning
$access_level Optional subject. Omit it for the current user or visitor. Pass an access-level object or a supported string.
$settings Optional service settings. error_handling controls how the framework reports failures.

Supported strings are user:<ID|login|email>, role:<slug>, visitor (also guest or anonymous), and default (also all, anyone, or everyone). The access-level object can come from AAM::api()->user(), role(), visitor(), or default(). See Ways to select a level for examples, aliases, and the difference between a service subject and a resource identifier.

Services

The gateway exposes every service in the service index. For example, posts(), urls(), api_routes(), capabilities() (alias caps()), policies(), settings(), abilities(), and the four mcp_*() services. Each takes the same two gateway arguments. You can also call a service from an access-level object:

$role = AAM::api()->role('editor');
$role->posts()->deny(34, 'read');

The service returned by $role->posts() is already bound to the Editor role, so the rule applies to that role.

A service failure can return WP_Error when configured that way. Check is_wp_error($result) before treating a result as a successful access decision. See each service page for its method arguments and return behavior.