Repository navigation
Abilities Explorer: accept input properties that list several types - #1073
Conversation
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.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@dkotter probably good to pull this into 1.4.0? |

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
typeto 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 tovalidate_type(), which takes a string. Understrict_typesthat throws an uncaughtTypeError, 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-createandcore/content-updatetake a string or an object with arawkey.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
Enable the Abilities Explorer experiment.
Register this minimal ability, for example as an mu-plugin:
Go to Tools → Abilities Explorer, click Test on
demo/union-type-input, replace the input with{"value":"Hello"}, and click Invoke Ability.develop, the request toadmin-ajax.phpfails with a 500 critical error."Hello".{"value":{"raw":"Hello"}}works too, and{"value":42}is rejected withField "value" should be of type "string" or "object".Run the PHP tests:
The new
test_validate_input_validates_type_listfails ondevelopwithTypeError: WordPress\AI\Experiments\Abilities_Explorer\Ability_Handler::validate_type(): Argument #2 ($expected_type) must be of type string, array given.Changelog Entry