Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cfff125
Add initial core abilities for WordPress 6.9
Jameswlepage Oct 10, 2025
1957efb
Fix linting issues and update hook naming
Jameswlepage Oct 10, 2025
299ecc9
Remove core/find-abilities ability
Jameswlepage Oct 15, 2025
7f928ef
Refactor core abilities: namespace, categories, and expanded environm…
Jameswlepage Oct 15, 2025
19f665a
Fix wp/get-current-user-info output schema required fields
Jameswlepage Oct 15, 2025
033f653
Remove unused input parameter from wp/get-site-info permission callback
Jameswlepage Oct 15, 2025
dbf97f7
Refine core abilities with constants and improved descriptions
Jameswlepage Oct 16, 2025
28b6040
Update includes/abilities/class-wp-core-abilities.php
Jameswlepage Oct 16, 2025
93e85df
Fix code style and add environment examples in WP_Core_Abilities
Jameswlepage Oct 16, 2025
53d37fb
Merge branch 'trunk' into feature/initial-core-abilities
Jameswlepage Oct 16, 2025
6dced81
Merge branch 'trunk' into feature/initial-core-abilities
Jameswlepage Oct 19, 2025
4dce755
Apply suggestions from code review
Jameswlepage Oct 19, 2025
00fa5c1
Changed namespace back to core/ and not wp/ to align w/ GB
Jameswlepage Oct 19, 2025
afd83c9
Renaming Get Current User info to Get User Info to allow for flexibil…
Jameswlepage Oct 19, 2025
766490b
Update function name for user info too
Jameswlepage Oct 19, 2025
8f09665
Rewrite Site Info ability to return all fields by default w/ self doc…
Jameswlepage Oct 19, 2025
b7b69a1
Normalize ability inputs with schema defaults for empty REST calls
Jameswlepage Oct 20, 2025
73a2092
drop input var on site permission callback
Jameswlepage Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions includes/abilities-api/class-wp-ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,27 @@ public function get_input_schema(): array {
return $this->input_schema;
}

/**
* Applies the defined input default when no input is provided.
*
* @since 0.4.0
*
* @param mixed $input Optional. The raw input provided for the ability. Default `null`.
* @return mixed The input with the schema default applied when available.
*/
public function normalize_input( $input = null ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran out of time to include that in the patch against WordPress trunk. Is there anyone willing to handle the bug fix PR in core just for this change? 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WordPress/wordpress-develop#10395 - started working on the patch. Unit tests are still missing at the time of writing.

if ( null !== $input ) {
return $input;
}

$input_schema = $this->get_input_schema();
if ( ! empty( $input_schema ) && array_key_exists( 'default', $input_schema ) ) {
return $input_schema['default'];
}

return null;
}

/**
* Retrieves the output schema for the ability.
*
Expand Down Expand Up @@ -436,6 +457,7 @@ protected function invoke_callback( callable $callback, $input = null ) {
* @return bool|\WP_Error Whether the ability has the necessary permission.
*/
public function check_permissions( $input = null ) {
$input = $this->normalize_input( $input );
$is_valid = $this->validate_input( $input );
if ( is_wp_error( $is_valid ) ) {
return $is_valid;
Expand Down Expand Up @@ -522,6 +544,7 @@ protected function validate_output( $output ) {
* @return mixed|\WP_Error The result of the ability execution, or WP_Error on failure.
*/
public function execute( $input = null ) {
$input = $this->normalize_input( $input );
$has_permissions = $this->check_permissions( $input );
if ( true !== $has_permissions ) {
if ( is_wp_error( $has_permissions ) ) {
Expand Down
5 changes: 4 additions & 1 deletion includes/abilities/class-wp-core-abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected static function register_get_site_info(): void {
),
),
'additionalProperties' => false,
'default' => array(),
),
'output_schema' => array(
'type' => 'object',
Expand Down Expand Up @@ -141,6 +142,7 @@ protected static function register_get_site_info(): void {
'additionalProperties' => false,
),
'execute_callback' => static function ( $input = array() ): array {
$input = is_array( $input ) ? $input : array();
$all_fields = array( 'name', 'description', 'url', 'wpurl', 'admin_email', 'charset', 'language', 'version' );
$requested_fields = ! empty( $input['fields'] ) ? $input['fields'] : $all_fields;

Expand All @@ -151,7 +153,8 @@ protected static function register_get_site_info(): void {

return $result;
},
'permission_callback' => static function (): bool {
'permission_callback' => static function ( $input = null ): bool {
unset( $input );
Comment thread
Jameswlepage marked this conversation as resolved.
Outdated
return current_user_can( 'manage_options' );
},
'meta' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function run_ability( $request ) {
);
}

$input = $this->get_input_from_request( $request );
$input = $ability->normalize_input( $this->get_input_from_request( $request ) );
$result = $ability->execute( $input );
if ( is_wp_error( $result ) ) {
if ( 'ability_invalid_input' === $result->get_error_code() ) {
Expand Down Expand Up @@ -162,7 +162,7 @@ public function run_ability_permissions_check( $request ) {
);
}

$input = $this->get_input_from_request( $request );
$input = $ability->normalize_input( $this->get_input_from_request( $request ) );
if ( ! $ability->check_permissions( $input ) ) {
return new \WP_Error(
'rest_ability_cannot_execute',
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/abilities-api/wpCoreAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function test_core_get_bloginfo_ability_is_registered(): void {
$input_schema = $ability->get_input_schema();
$output_schema = $ability->get_output_schema();

$this->assertSame( 'object', $input_schema['type'] );
$this->assertArrayHasKey( 'default', $input_schema );
$this->assertSame( array(), $input_schema['default'] );

// Input schema should have optional fields array.
$this->assertArrayHasKey( 'fields', $input_schema['properties'] );
$this->assertSame( 'array', $input_schema['properties']['fields']['type'] );
Expand All @@ -85,7 +89,7 @@ public function test_core_get_bloginfo_executes(): void {
$ability = wp_get_ability( 'core/get-site-info' );

// Test without fields parameter - should return all fields.
$result = $ability->execute( array() );
$result = $ability->execute();

$this->assertIsArray( $result );
$this->assertArrayHasKey( 'name', $result );
Expand Down
Loading