For the complete documentation index, see llms.txt. This page is also available as Markdown.

Extending

Filters for overriding capabilities, adding or removing providers, and building your own abilities on ACPT's infrastructure

Two WordPress filters let you customize the Abilities API integration from your own plugin or theme's functions.php, without touching ACPT's code.

Overriding the required capability

By default, every content-model ability requires manage_options and every content-data (field value) ability requires edit_posts — see How it works → Permissions. Override this per ability, per user, or based on the input being sent with the acpt/abilities-api/capability filter:

/**
 * @param string $capability   The default capability for this ability.
 * @param string $abilityName  The full ability name, e.g. "acpt/save-post-type".
 * @param mixed  $input        The input passed to the ability (or null).
 */
add_filter('acpt/abilities-api/capability', function ($capability, $abilityName, $input) {
    // Let editors manage forms, but keep everything else at manage_options.
    if (strpos($abilityName, 'acpt/') === 0 && strpos($abilityName, '-form') !== false) {
        return 'edit_others_posts';
    }

    return $capability;
}, 10, 3);

The returned value is passed straight to current_user_can(), so it can be any valid WordPress capability string.

Adding or removing providers

Every ability is registered by a small "provider" class (CustomPostTypeAbilities, TaxonomyAbilities, …), one per content domain. The full list ACPT registers by default is filterable with acpt/abilities-api/providers:

Or add your own provider to register additional, site-specific abilities alongside ACPT's:

Any class that isn't a subclass of AbstractAbilityProvider is silently skipped, so a bad value here can't fatal the site.

Building your own ability provider

You don't have to reinvent wp_register_ability() boilerplate — ACPT's own AbilityRegistrar and AbilityOutputSchema classes are safe to reuse from your own provider:

Then register it with the acpt/abilities-api/providers filter shown above. AbilityRegistrar takes care of building the execute_callback/permission_callback wrappers, the {success, message, data} response envelope, and the readonly/destructive/idempotent metadata the same way it does for every built-in ACPT ability — see How it works for exactly what that means.

Last updated