Metaboxes
Overview
Manage visibility of WordPress editor metaboxes by ID and screen. Select the subject with AAM::api()->metaboxes($access_level, $settings). Omit $access_level to use the current user or visitor.
PHP class: AAM_Framework_Service_Metaboxes.
Method reference
| Method | Purpose |
|---|---|
get_items($screen_id = null) |
List discovered items. |
items($screen_id = null) |
Alias of get_items(). |
get_item($slug, $screen_id = null) |
Get one discovered item. |
item($slug, $screen_id = null) |
Alias of get_item(). |
deny($metabox, $screen_id = null) |
Store a deny rule. |
allow($metabox, $screen_id = null) |
Store an allow rule. |
reset($metabox = null, $screen_id = null) |
Remove one rule or all rules for this level. |
is_denied($metabox, $screen_id = null) |
Check the effective deny decision. |
is_allowed($metabox, $screen_id = null) |
Check the effective allow decision. |
is_customized($metabox = null, $screen_id = null) |
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
Pass a metabox slug string and, when needed, a screen ID such as 'post' or 'page': deny('my-box', 'post'). Rule methods also accept a registered metabox descriptor with a callback and id; AAM derives its stored slug from that descriptor. For example:
$metabox = ['id' => 'my-box', 'callback' => 'my_plugin_render_box'];
AAM::api()->metaboxes('role:editor')->deny($metabox, 'post');
The array needs a callback; an array containing only id is not a valid identifier. get_items('post') helps discover the stored slugs for that screen.
Example
$boxes = AAM::api()->metaboxes('role:author');
$boxes->deny('postcustom', 'post');
$hidden = $boxes->is_denied('postcustom', 'post');
This hides the postcustom metabox on the post editor screen for Authors. $hidden checks the rule with the same screen ID.
Developer notes
- Pass a screen ID when the same metabox ID is used on multiple screens.
get_items()returns discovered metaboxes for a screen; discovery depends on the WordPress admin context.- The selected access level determines whose rules are stored or evaluated. See Access levels.
Behavior and parameters
deny($metabox, $screen_id = null)andallow()accept a metabox identifier, optionally scoped to a screen.reset()removes the matching rule or all rules.get_items($screen_id = null)discovers registered boxes;get_item($slug, $screen_id = null)finds one.is_customized()detects a direct rule.