Terms
Overview
Manage access to individual taxonomy terms, with premium term restrictions. Select the subject with AAM::api()->terms($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Terms.
The methods below require the premium add-on.
Method reference
| Method | Purpose |
|---|---|
is_hidden_on($term_identifier, $website_area) |
Check whether listing is hidden in an area. |
is_hidden($term_identifier) |
Check whether listing is hidden. |
is_password_protected($term_identifier) |
Check for a password rule. |
is_restricted($term_identifier) |
Check whether direct reading is restricted. |
is_redirected($term_identifier) |
Check for a redirect rule. |
is_teaser_message_set($term_identifier) |
Check for a teaser rule. |
is_denied_to($term_identifier, $permission) |
Check whether an action is denied. |
is_allowed_to($term_identifier, $permission) |
Check whether an action is allowed. |
is_access_expired($term_identifier) |
Check whether a timed rule has expired. |
set_password($term_identifier, $password, $exclude_authors = false) |
Set a password rule. |
set_teaser_message($term_identifier, $message, $exclude_authors = false) |
Set a teaser message. |
set_redirect($term_identifier, $redirect, $exclude_authors = false) |
Store a redirect model. |
set_expiration($term_identifier, $timestamp, $exclude_authors = false) |
Set an expiration timestamp. |
deny($term_identifier, $permission, $exclude_authors = null) |
Store a deny rule. |
allow($term_identifier, $permission) |
Store an allow rule. |
hide($term_identifier, $website_area = null, $exclude_authors = false) |
Deny listing. |
show($term_identifier, $website_area = null) |
Allow listing. |
get_password($term_identifier) |
Read the password rule. |
get_teaser_message($term_identifier) |
Read the teaser message. |
get_redirect($term_identifier) |
Read the effective redirect. |
get_expiration($term_identifier) |
Read the expiration timestamp. |
aggregate() |
Get effective permissions for this resource type. |
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 term target in one of these forms:
$term = 17; // Numeric term ID
$term = get_term(17, 'category'); // WP_Term object
$term = ['id' => 17, 'taxonomy' => 'category']; // ID with taxonomy
$term = ['slug' => 'news', 'taxonomy' => 'category']; // Slug with required taxonomy
$term = ['id' => 17, 'taxonomy' => 'category', 'post_type' => 'post'];
AAM::api()->terms('role:editor')->deny($term, 'read');
Each assignment shows an alternative way to set $term; the final call uses the last form. A slug needs taxonomy. The optional post_type scopes a term rule to associated content; you can also pass ['scope' => 'post'] as the second argument to terms(). A term ID or object identifies the term without a slug lookup.
Example
$terms = AAM::api()->terms('role:subscriber');
$terms->deny(['slug' => 'internal', 'taxonomy' => 'category'], 'list');
$hidden = $terms->is_hidden(['slug' => 'internal', 'taxonomy' => 'category']);
These premium calls hide the internal category term from Subscriber listings. The array identifies the term by slug and taxonomy; $hidden reads the resulting rule.
Developer notes
- Identify a term by ID,
WP_Term, or an array withslugandtaxonomy(oridandtaxonomy). - For term rules scoped to a post type, pass
post_typein the identifier array orscopein service settings. - The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny()andallow()accept a permission string or array.hide()andshow()target thelistpermission, optionally limited to a website area.set_password(),set_teaser_message(),set_redirect(), andset_expiration()affect posts associated with a term. The optionalexclude_authorsflag changes how authors are treated.aggregate()returns the term permission map for the selected access level. There is no publicreset()method on this service.