Skip to content

Abilities Explorer: accept input properties that list several types - #1073

Merged
dkotter merged 1 commit into
developfrom
fix/abilities-explorer-union-types
Oct 5, 2026
Merged

dkotter merged 1 commit into
developfrom
fix/abilities-explorer-union-types

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

What?

Stops the Abilities Explorer from crashing when an ability's input property lists several types, such as 'type' => array( 'string', 'object' ).

Why?

JSON Schema allows type to be a list of types, and the Abilities API validates such input. The Explorer runs its own validation first: Ability_Handler::validate_property() passed the list to validate_type(), which takes a string. Under strict_types that throws an uncaught TypeError, so invoking the ability from the Explorer returns a 500 "There has been a critical error on this website." and the ability never runs.

No ability in the plugin declares a list of types yet, but the write abilities in #1025 do: the title, content, and excerpt of core/content-create and core/content-update take a string or an object with a raw key.

How?

validate_property() accepts the value when any listed type matches, and the error message names every listed type, e.g. Field "value" should be of type "string" or "object". A single type behaves as before.

Testing Instructions

  1. Enable the Abilities Explorer experiment.

  2. Register this minimal ability, for example as an mu-plugin:

    <?php
    add_action(
    	'wp_abilities_api_init',
    	static function () {
    		wp_register_ability(
    			'demo/union-type-input',
    			array(
    				'label'               => 'Union type input',
    				'description'         => 'Echoes a value that may be a string or an object.',
    				'category'            => 'site',
    				'input_schema'        => array(
    					'type'       => 'object',
    					'properties' => array(
    						'value' => array( 'type' => array( 'string', 'object' ) ),
    					),
    				),
    				'execute_callback'    => static function ( $input ) {
    					return $input['value'];
    				},
    				'permission_callback' => static function () {
    					return current_user_can( 'manage_options' );
    				},
    			)
    		);
    	}
    );
  3. Go to Tools → Abilities Explorer, click Test on demo/union-type-input, replace the input with {"value":"Hello"}, and click Invoke Ability.

    • On develop, the request to admin-ajax.php fails with a 500 critical error.
    • On this branch, the ability returns "Hello". {"value":{"raw":"Hello"}} works too, and {"value":42} is rejected with Field "value" should be of type "string" or "object".
  4. Run the PHP tests:

    npm run test:php -- --filter Ability_HandlerTest
    

    The new test_validate_input_validates_type_list fails on develop with TypeError: WordPress\AI\Experiments\Abilities_Explorer\Ability_Handler::validate_type(): Argument #2 ($expected_type) must be of type string, array given.

Changelog Entry

Fixed - Abilities Explorer no longer crashes when an ability's input property lists several types.

Open WordPress Playground Preview

JSON Schema allows a property's type to list several types, such as
array( 'string', 'object' ). validate_property() passed that list to
validate_type(), which takes a string, so under strict types invoking
such an ability from the Explorer threw a TypeError and admin-ajax
returned a 500. Accept the value when any listed type matches.
@github-actions

Copy link
Copy Markdown

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.58%. Comparing base (747f943) to head (db5f721).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #1073   +/-   ##
==========================================
  Coverage      81.57%   81.58%           
- Complexity      3077     3079    +2     
==========================================
  Files            129      129           
  Lines          12267    12272    +5     
==========================================
+ Hits           10007    10012    +5     
  Misses          2260     2260           
Flag Coverage Δ
unit 81.58% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo left a comment

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 could reproduce the issue on the develope branch and I can confirm that this fix addresses it.

Image

@gziolo gziolo assigned gziolo and jorgefilipecosta and unassigned gziolo Oct 2, 2026
@jeffpaul jeffpaul added this to the 1.4.0 milestone Oct 4, 2026
@jeffpaul

jeffpaul commented Oct 4, 2026

Copy link
Copy Markdown
Member

@dkotter probably good to pull this into 1.4.0?

@dkotter
dkotter merged commit ac5920c into develop Oct 5, 2026
35 checks passed
@dkotter
dkotter deleted the fix/abilities-explorer-union-types branch October 5, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants