Posts
Overview
Manage access and presentation rules for individual WordPress posts. Select the subject with AAM::api()->posts($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Posts.
Method reference
| Method | Purpose |
|---|---|
is_hidden_on($post_identifier, $website_area) |
Check whether listing is hidden in an area. |
is_hidden($post_identifier) |
Check whether listing is hidden. |
is_password_protected($post_identifier) |
Check for a password rule. |
is_restricted($post_identifier) |
Check whether direct reading is restricted. |
is_redirected($post_identifier) |
Check for a redirect rule. |
is_teaser_message_set($post_identifier) |
Check for a teaser rule. |
is_denied_to($post_identifier, $permission) |
Check whether an action is denied. |
is_allowed_to($post_identifier, $permission) |
Check whether an action is allowed. |
is_access_expired($post_identifier) |
Check whether a timed rule has expired. |
set_password($post_identifier, $password, $exclude_authors = false) |
Set a password rule. |
set_teaser_message($post_identifier, $message, $exclude_authors = false) |
Set a teaser message. |
set_redirect($post_identifier, $redirect, $exclude_authors = false) |
Store a redirect model. |
set_expiration($post_identifier, $timestamp, $exclude_authors = false) |
Set an expiration timestamp. |
deny($post_identifier, $permission, $exclude_authors = false) |
Store a deny rule. |
allow($post_identifier, $permission) |
Store an allow rule. |
hide($post_identifier, $website_area = null, $exclude_authors = false) |
Deny listing. |
show($post_identifier, $website_area = null) |
Allow listing. |
get_password($post_identifier) |
Read the password rule. |
get_teaser_message($post_identifier) |
Read the teaser message. |
get_redirect($post_identifier) |
Read the effective redirect. |
get_expiration($post_identifier) |
Read the expiration timestamp. |
aggregate() |
Get effective permissions for this resource type. |
reset($post_identifier = null) |
Remove one rule or all rules for this level. |
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 post target to a rule or decision method in any of these forms:
$post = 34; // Numeric post ID
$post = '34'; // Numeric ID string
$post = get_post(34); // WP_Post object
$post = ['id' => 34]; // ID array
$post = ['id' => 34, 'post_type' => 'page']; // ID with a type check
$post = ['slug' => 'annual-report', 'post_type' => 'page']; // Slug and required type
$post = ['post_name' => 'annual-report', 'post_type' => 'page'];
AAM::api()->posts('role:editor')->deny($post, 'read');
Each assignment shows an alternative way to set $post; the final call uses the last form. A slug needs post_type so AAM can find the right post. When an array contains id, AAM uses that ID and checks post_type if provided. A missing post or mismatched type produces an error under the service’s error_handling setting. These forms identify the target post; the argument to posts() identifies the access level.
Example
$posts = AAM::api()->posts('role:subscriber');
$posts->deny(34, ['list', 'read']);
if ($posts->is_restricted(34)) {
// Render a response for a custom request.
}
This saves both a listing and direct-read denial for post 34 at the Subscriber role level. is_restricted() checks the direct-read decision; your custom flow must act on that result.
Developer notes
- A slug array must include
post_type; use an ID array when you also want to check the post type. listhides a post from listings;readrestricts direct access.hide()handles thelistrule.- The
$exclude_authorsparameter on supported setters anddeny()requires the premium add-on. - The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($post, $permission)accepts a permission string or array. Common permissions arelistandread;allow()reverses a stored denial.reset($post = null)removes one post’s rules or all post rules for this level.set_password(),set_teaser_message(),set_redirect(), andset_expiration()configure ways to restrict reading. Useget_*()andis_*()methods to inspect the effective rule. Expiration is a Unix timestamp.hide($post, $website_area = null)targets listing. The optional area can be a string or array; omit it for all areas.