Download the PHP package galatanovidiu/abilities-rest-adapter without Composer
On this page you can find all versions of the php package galatanovidiu/abilities-rest-adapter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download galatanovidiu/abilities-rest-adapter
More information about galatanovidiu/abilities-rest-adapter
Files in galatanovidiu/abilities-rest-adapter
Package abilities-rest-adapter
Short Description Defines Abilities API abilities by reusing existing REST API routes (schema, validation, permission, handler) via rest_do_request().
License MIT
Homepage https://github.com/galatanovidiu/abilities-rest-adapter
Informations about the package abilities-rest-adapter
Abilities REST Adapter
Define a WordPress Abilities API ability by reusing an existing REST API route — its schema, validation, permission check, and handler — instead of re-implementing them. The adapter dispatches the real route via rest_do_request(), so the ability stays behaviorally equivalent to the endpoint.
The signature mirrors core's wp_register_ability( $name, $args ). route, method, label, description, and category are required.
See docs/usage.md for the full guide: the five seams (input_callback / output_callback / input_schema / output_schema / require_permission), collections, the write-safety rule, the permission-error limitation, and the wp ability describe-route command.
- Reuse, don't re-implement. Permission is the route's real check; output is the route's real body. A collection synthesizes
{ items, total, total_pages }from theX-WP-Totalheaders. - Facilitate, don't force. The adapter gives the developer seams instead of baking in opinions:
input_callback( array $params ): array|WP_Error— transform the request before dispatch (set_fields, pincontext, inject fixed params, reshape, or reject).output_callback( $data, array $input, WP_REST_Response $response ): mixed|WP_Error— reshape a successful response (or reject it).input_schema/output_schema— replace the schemas the adapter derives from the route.require_permission( mixed $input ): bool|WP_Error— an opt-in floor checked before the route's own permission; it can only tighten access, never widen it.
- Safety annotations. Every non-readonly operation must declare boolean
destructiveandidempotentvalues undermeta.annotations; invalid or incomplete safety metadata fails registration. Readonly GETs receive the coherent read tuple automatically. - Standalone now, core later. Built as a feature plugin; designed so it can move into core.
- Status: behavioral-equivalence + regression suite green on PHP 7.4–8.5.
Requirements
- WordPress 6.9+ (the Abilities API ships in core 6.9). Faithful permission-error surfacing uses the 7.1
wp_ability_permission_resultfilter. - PHP 7.4+ (matches WordPress core's supported floor). CI tests every major version through PHP 8.5.
The dev environment (.wp-env.json) tracks current WordPress trunk (7.1-alpha) so the 7.1 filter is available.
Installation
As a Composer dependency (plugin developers)
Plugin developers can install the adapter as a Composer dependency and use
wp_register_ability_from_rest_route() from their own plugin. The package is
published on Packagist:
Using Jetpack Autoloader (recommended)
When multiple plugins bundle this adapter, use the Jetpack Autoloader so only the latest shared version loads:
Load it in your main plugin file instead of the standard Composer autoloader:
Using the adapter in your plugin
Check availability and register abilities on wp_abilities_api_init:
See docs/usage.md for the full registration guide.
As a WordPress plugin (recommended for site-wide use)
Install and activate the adapter once; any plugin on the site can call
wp_register_ability_from_rest_route().
Download the latest stable release from the
GitHub Releases page
and install it like any other WordPress plugin. Release ZIPs include the
bundled vendor/ directory.
With WP-CLI
From a git checkout
Development
License
MIT