Skip to content

Conversation

@gziolo
Copy link
Member

@gziolo gziolo commented Sep 26, 2025

This PR introduces a new invoke_callback helper method in the WP_Ability class to standardize callback invocation logic. The method handles whether to pass input parameters based on the presence of an input schema, replacing duplicated logic in the permission and execution callback methods. Additional test coverage was added to ensure that functionality continues to work the same way.

You can run tests locally with:

npm run test:php

@gziolo gziolo self-assigned this Sep 26, 2025
@gziolo gziolo added [Type] Bug Something isn't working [Status] In Progress Assigned work scheduled labels Sep 26, 2025
@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.26%. Comparing base (56616ba) to head (bb6aaf0).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk      #88      +/-   ##
============================================
+ Coverage     86.24%   86.26%   +0.01%     
  Complexity      110      110              
============================================
  Files            16       16              
  Lines           807      808       +1     
  Branches         86       86              
============================================
+ Hits            696      697       +1     
  Misses          111      111              
Flag Coverage Δ
javascript 92.62% <ø> (ø)
unit 83.92% <100.00%> (+0.02%) ⬆️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gziolo gziolo force-pushed the update/invoke-callback-refactor branch from e0d09cb to 53233b4 Compare October 10, 2025 09:06
@gziolo gziolo requested a review from Copilot October 10, 2025 09:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new invoke_callback helper method in the WP_Ability class to standardize callback invocation logic. The method handles whether to pass input parameters based on the presence of an input schema, replacing duplicated logic in the permission and execution callback methods.

  • Adds a new protected invoke_callback helper method to centralize callback invocation logic
  • Refactors check_permissions and do_execute methods to use the new helper
  • Adds comprehensive test coverage for different callback types (functions, closures, static methods, instance methods)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/abilities-api/class-wp-ability.php Introduces invoke_callback helper method and refactors existing methods to use it
tests/unit/abilities-api/wpAbility.php Adds test methods and data provider to verify callback handling with different callable types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gziolo gziolo marked this pull request as ready for review October 10, 2025 09:54
@github-actions
Copy link

github-actions bot commented Oct 10, 2025

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: gziolo <[email protected]>
Co-authored-by: JasonTheAdams <[email protected]>
Co-authored-by: felixarntz <[email protected]>

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

@gziolo gziolo added [Type] Enhancement New feature or request and removed [Status] In Progress Assigned work scheduled [Type] Bug Something isn't working labels Oct 10, 2025
Copy link
Member

@JasonTheAdams JasonTheAdams left a comment

Choose a reason for hiding this comment

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

Nice little refactor! I made a minor suggestion, but it's small enough where I'll approve regardless of your decision.

*/
protected function invoke_callback( callable $callback, $input = null ) {
$args = array();
if ( ! empty( $this->get_input_schema() ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

While we're cleaning things up, what do you think about adding a $this->has_input_schema() method to make this sort of check more declarative?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like a good idea 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I will play with this, and the other method idea #104 (comment) in a follow-up PR 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it make sense to have a similar method for the output schema? Given all the other tasks necessary for WP 6.9, this one is nice to have we can introduce later.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@gziolo Good idea, LGTM!

@gziolo gziolo merged commit 4dc57b3 into trunk Oct 10, 2025
23 checks passed
@gziolo gziolo deleted the update/invoke-callback-refactor branch October 10, 2025 19:00
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.

3 participants