Skip to content

Conversation

justlevine
Copy link
Contributor

What

This PR adds array shapes for the $properties array used by

  • wp_register_ability()
  • WP_Abilities_Registry::register()
  • WP_Ability::__construct()

Why

To ensure both we and consumers are using the correct array shapes.

Additional Notes

  • Generics are not used e.g. to hint the schema/meta shapes. Until core supports generics, that extra level of DX would fall to a 3rd party library like php-stubs/wordpress-stubs.
  • As a result of the array shapes we could in theory make the param less verbose, but human contribs might not be familiar with the syntax, so I left it out.

@justlevine
Copy link
Contributor Author

I don't have perms to rerun the failing CI, but since it's for WP6.7 which we're removing in #18 🤷

@gziolo gziolo added the [Type] Enhancement New feature or request label Aug 18, 2025
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (trunk@a749d71). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             trunk      #20   +/-   ##
========================================
  Coverage         ?   90.66%           
  Complexity       ?       99           
========================================
  Files            ?        7           
  Lines            ?      557           
  Branches         ?        0           
========================================
  Hits             ?      505           
  Misses           ?       52           
  Partials         ?        0           
Flag Coverage Δ
unit 90.66% <ø> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

That's very useful addition 👍🏻

* execute_callback?: callable( array<string,mixed> $input): (mixed|\WP_Error),
* permission_callback?: callable( ?array<string,mixed> $input ): bool,
* meta?: array<string,mixed>,
* ...<string, mixed>
Copy link
Member

Choose a reason for hiding this comment

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

Everything else gets ignored, do we need to list it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exaclty why it's here - this is the long-overdue syntax for partially sealed arrays.

Otherwise if users don't clean up their arrays (or more "justifiable" real world scenario: if extensions hook in their own custom args) they'll get errors about unsupported array values, when it doesn't matter because we only keep the ones we need.

Copy link
Member

@gziolo gziolo Aug 19, 2025

Choose a reason for hiding this comment

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

I don’t think it adds any value at the moment because it’s impossible to successfully pass more settings. It’ll rather change in the future when we add WP hooks.

@gziolo gziolo merged commit 507e9ec into WordPress:trunk Aug 19, 2025
17 checks passed
@justlevine justlevine deleted the dev/properties-array-shap branch August 20, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants