abilities.php
WordPress Abilities API integration
Registers one read-only ability, jpkcom-harden-trim/get-status: what every
setting of this plugin does on this site and why. The answer comes from
jpkcom_harden_trim_status(), the same function wp harden-trim status
prints, so the two cannot disagree.
Its value is the cases nothing else shows at a glance: a switch that is on and does nothing (kill switch, a core constant that wins, a block theme), a value that does not come from the settings page (plugin constant, filter), and a constant that is ignored because its value is invalid.
The capability is manage_options: the answer describes how the site is
hardened, which is configuration an administrator owns.
The labels, descriptions and messages stay English in every language, as in every JPKCom plugin's abilities: they are read by MCP clients and agents, and their wording is the feature.
Tags
Table of Contents
Constants
- JPKCOM_HARDEN_TRIM_ABILITY_CATEGORY : mixed = 'jpkcom-site'
- Ability category.
- JPKCOM_HARDEN_TRIM_ABILITY_INPUT_KEYS : mixed = array('jpkcom-harden-trim/get-status' => array())
- Top-level input keys per ability.
Functions
- jpkcom_harden_trim_abilities_constant() : bool|null
- JPKCOM_HARDEN_TRIM_ABILITIES as a boolean.
- jpkcom_harden_trim_abilities_enabled() : bool
- Whether the ability should be registered at all.
- jpkcom_harden_trim_ability_capability() : bool
- Whether the current user may run an ability.
- jpkcom_harden_trim_ability_meta() : array<string, mixed>
- The meta array of an ability.
- jpkcom_harden_trim_ability_permission() : bool
- Permission callback of get-status.
- jpkcom_harden_trim_ability_get_status() : array<string, mixed>|WP_Error
- Execute callback of get-status.
- jpkcom_harden_trim_get_ability_definitions() : array<string, array<string, mixed>>
- The registration arguments of every ability.
- jpkcom_harden_trim_register_ability_category() : void
- Register the category, unless another plugin already did.
- jpkcom_harden_trim_register_abilities() : void
- Register the abilities.
Constants
JPKCOM_HARDEN_TRIM_ABILITY_CATEGORY
Ability category.
public
mixed
JPKCOM_HARDEN_TRIM_ABILITY_CATEGORY
= 'jpkcom-site'
Categories are global and registration is FIRST-WINS, so this goes through wp_has_ability_category() rather than assuming.
Tags
JPKCOM_HARDEN_TRIM_ABILITY_INPUT_KEYS
Top-level input keys per ability.
public
mixed
JPKCOM_HARDEN_TRIM_ABILITY_INPUT_KEYS
= array('jpkcom-harden-trim/get-status' => array())
Cross-checked against the registered schema by tests/test-abilities.php.
Tags
Functions
jpkcom_harden_trim_abilities_constant()
JPKCOM_HARDEN_TRIM_ABILITIES as a boolean.
jpkcom_harden_trim_abilities_constant() : bool|null
Tags
Return values
bool|null —Null when undefined or not a boolean value.
jpkcom_harden_trim_abilities_enabled()
Whether the ability should be registered at all.
jpkcom_harden_trim_abilities_enabled() : bool
JPKCOM_HARDEN_TRIM_ABILITIES set to false in wp-config.php suppresses
it. The feature kill switch JPKCOM_HARDEN_TRIM_DISABLE_ALL does not: the
ability is how to see that the kill switch is on.
Tags
Return values
bool —True when registration should proceed.
jpkcom_harden_trim_ability_capability()
Whether the current user may run an ability.
jpkcom_harden_trim_ability_capability(string $ability) : bool
Parameters
- $ability : string
-
Ability name.
Tags
Return values
bool —True when the current user holds the capability.
jpkcom_harden_trim_ability_meta()
The meta array of an ability.
jpkcom_harden_trim_ability_meta(string $ability) : array<string, mixed>
All three annotations explicit: they default to null and the REST run controller derives the HTTP verb from them, so without readonly the run route would be POST-only.
Parameters
- $ability : string
-
Ability name.
Tags
Return values
array<string, mixed> —Meta array.
jpkcom_harden_trim_ability_permission()
Permission callback of get-status.
jpkcom_harden_trim_ability_permission([mixed $input = null ]) : bool
Parameters
- $input : mixed = null
-
Validated input, unused.
Tags
Return values
bool —True when the current user may run the ability.
jpkcom_harden_trim_ability_get_status()
Execute callback of get-status.
jpkcom_harden_trim_ability_get_status([mixed $input = null ]) : array<string, mixed>|WP_Error
A Throwable from reading the settings becomes a WP_Error with status 500 and a message saying that repeating the call will not help.
Parameters
- $input : mixed = null
-
Ability input (an empty object).
Tags
Return values
array<string, mixed>|WP_Error —Status or error.
jpkcom_harden_trim_get_ability_definitions()
The registration arguments of every ability.
jpkcom_harden_trim_get_ability_definitions() : array<string, array<string, mixed>>
Reads no WordPress state and touches no registry, so the tests can assert the shape without a WordPress installation.
Tags
Return values
array<string, array<string, mixed>> —Ability name => registration args.
jpkcom_harden_trim_register_ability_category()
Register the category, unless another plugin already did.
jpkcom_harden_trim_register_ability_category() : void
Tags
jpkcom_harden_trim_register_abilities()
Register the abilities.
jpkcom_harden_trim_register_abilities() : void
wp_register_ability() returns null on every failure path and reports only through _doing_it_wrong(), which is silent in production.