Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[{*.txt,wp-config-sample.php}]
end_of_line = crlf
20 changes: 20 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.2/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
87 changes: 87 additions & 0 deletions src/abilities-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php declare( strict_types = 1 );

/**
* Abilities API
*
* Defines functions for managing abilities in WordPress.
*
* @package WordPress
* @subpackage Abilities API
* @since 0.1.0
*/

/**
* Registers a new ability using Abilities API.
*
* Note: Do not use before the {@see 'abilities_api_init'} hook.
*
* @see WP_Abilities_Registry::register()
*
* @since 0.1.0
*
* @param string|WP_Ability $name The name of the ability, or WP_Ability instance. The name must be a string
* containing a namespace prefix, i.e. `my-plugin/my-ability`. It can only
* contain lowercase alphanumeric characters, dashes and the forward slash.
* @param array $properties Optional. An associative array of properties for the ability. This should
* include `label`, `description`, `input_schema`, `output_schema`,
* `execute_callback`, `permission_callback`, and `meta`.
* @return ?WP_Ability An instance of registered ability on success, null on failure.
*/
function wp_register_ability( $name, array $properties = array() ): ?WP_Ability {
if ( ! did_action( 'abilities_api_init' ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: abilities_api_init, 2: string value of the ability name. */
esc_html__( 'Abilities must be registered on the %1$s action. The ability %2$s was not registered.' ),
'<code>abilities_api_init</code>',
'<code>' . esc_attr( $name ) . '</code>'
),
'0.1.0'
);
return null;
}

return WP_Abilities_Registry::get_instance()->register( $name, $properties );
}

/**
* Unregisters an ability using Abilities API.
*
* @see WP_Abilities_Registry::unregister()
*
* @since 0.1.0
*
* @param string $name The name of the registered ability, with its namespace.
* @return ?WP_Ability The unregistered ability instance on success, null on failure.
*/
function wp_unregister_ability( string $name ): ?WP_Ability {
return WP_Abilities_Registry::get_instance()->unregister( $name );
}

/**
* Retrieves a registered ability using Abilities API.
*
* @see WP_Abilities_Registry::get_registered()
*
* @since 0.1.0
*
* @param string $name The name of the registered ability, with its namespace.
* @return ?WP_Ability The registered ability instance, or null if it is not registered.
*/
function wp_get_ability( string $name ): ?WP_Ability {
return WP_Abilities_Registry::get_instance()->get_registered( $name );
}

/**
* Retrieves all registered abilities using Abilities API.
*
* @see WP_Abilities_Registry::get_all_registered()
*
* @since 0.1.0
*
* @return WP_Ability[] The array of registered abilities.
*/
function wp_get_abilities(): array {
return WP_Abilities_Registry::get_instance()->get_all_registered();
}
Loading