piotrpress / wordpress-abilities
This is a lightweight PHP 8+ library for defining and registering custom WordPress Abilities using modern, attribute-based metadata.
Requires
- php: >=8.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-08-31 09:10:13 UTC
README
This is a lightweight PHP 8+ library for defining and registering custom WordPress Abilities using modern, attribute-based metadata.
It helps you keep Ability definitions close to the code that executes them. By combining #[Ability(...)] attribute with AbilityInterface / AbstractAbility, you can describe data in a clear, typed way, then register everything with a single call.
Installation
composer require piotrpress/wordpress-abilities
Example
require_once __DIR__ . '/vendor/autoload.php'; use PiotrPress\WordPress\Ability; use PiotrPress\WordPress\AbilityCategory; use PiotrPress\WordPress\AbstractAbility; #[ Ability( name: 'example/ability', label: 'Example Ability', description: 'Example description', category: new AbilityCategory( slug: 'example-category', label: 'Example Category', description: 'Example description' ), textdomain: 'example', public: true ) ] final class ExampleAbility extends AbstractAbility { public function __invoke( array $input ) : mixed {...} public function input() : array {...} public function output() : array {...} public function permission( array $input ) : bool|\WP_Error {...} } ( new ExampleAbility() )->register();
Category
The category argument in Ability attribute accepts two forms:
AbilityCategoryobject - use this when you want to register a new category. If a category with the same slug already exists, no re-registration is attemptedstring- use this when you want to assign the Ability to an existing category slug.
Development
composer format
NOTE: The format command will format composer.json file, it's required PHP >= 8.2.
composer test
NOTE: The test command will run PHPUnit tests, it's required PHP >= 8.3.
Requirements
- PHP
>= 8.0