Policies

Overview

Create, attach, inspect, and detach JSON access policies. Select the subject with AAM::api()->policies($access_level, $settings). Omit $access_level to use the current user or visitor.

PHP class: AAM_Framework_Service_Policies.

Method reference

Method Purpose
get_policies($args = []) List attached policies.
policies($args = []) Alias of get_policies().
get_policy($policy_id) Get an attached policy.
policy($policy_id) Alias of get_policy().
attach($policy_id) Attach a policy by ID.
detach($policy_id) Detach a policy by ID.
create($policy, $status = 'publish', $apply = true) Create a policy.
get_statements($resource_pattern = null, $args = []) Get effective policy statements.
get_params($key_pattern = null, $args = []) Get effective policy parameters.
get_param($key, $args = []) Get one effective parameter.
statements($resource_pattern = null, $args = []) Alias of get_statements().
params($key_pattern = null, $args = []) Alias of get_params().
param($key, $args = []) Alias of get_param().
reset() Remove one rule or all rules for this level.
is_customized() Check for a direct rule or preference.
is_attached($policy_id) Check whether a policy is attached.
is_detached($policy_id) Check whether a policy is detached.

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

Pass the numeric ID of an existing aam_policy post to attach(), detach(), get_policy(), or the attachment checks. create() instead accepts a policy JSON string or an array containing json and optional post fields such as title; its input defines a new policy rather than identifying an existing one.

Example

$policies = AAM::api()->policies('role:subscriber');
$policies->attach(123);
$attached = $policies->is_attached(123);

The policy with ID 123 must already exist. attach() assigns it to the Subscriber role, and $attached checks that assignment.

Developer notes

Behavior and parameters