Skip to content

Conversation

@huzaifaalmesbah
Copy link
Member

@huzaifaalmesbah huzaifaalmesbah commented Nov 7, 2025

Description

This PR fixes critical documentation errors that would cause developers to write incorrect code when implementing the Abilities API.

Changes Made

1. ✅ Fixed Invalid Function Reference

File: docs/rest-api.md (line 14)

Before:

The ability remains available for internal PHP usage via `wp_execute_ability()`.

After:

The ability remains available for internal PHP usage via `wp_get_ability()` and `$ability->execute()`.

Reason: The function wp_execute_ability() does not exist in the codebase. Verified by searching all files in includes/ directory. The correct pattern is documented in includes/abilities-api/class-wp-ability.php at line 595.


2. ✅ Fixed Incorrect Parameter Placement

Files:

  • docs/getting-started.md (lines 110-127)
  • docs/hooks.md (lines 72-91)

Before:

wp_register_ability( 'my-plugin/ability', array(
    'label'               => __( 'Title', 'my-plugin' ),
    'description'         => __( 'Description.', 'my-plugin' ),
    'execute_callback'    => 'callback',
    'permission_callback' => '__return_true',
    'meta'                => array(
        'category'    => 'site-info',  // ❌ Wrong location
        'show_in_rest' => true,
    ),
) );

After:

wp_register_ability( 'my-plugin/ability', array(
    'label'               => __( 'Title', 'my-plugin' ),
    'description'         => __( 'Description.', 'my-plugin' ),
    'category'            => 'site-info',  // ✅ Correct location
    'execute_callback'    => 'callback',
    'permission_callback' => '__return_true',
    'meta'                => array(
        'show_in_rest' => true,
    ),
) );

Reason: According to the function signature in includes/abilities-api.php (line 237), category is a required top-level parameter, not part of the meta array. This is confirmed by the core implementation in includes/abilities/wp-core-abilities.php (line 89).


3. ✅ Fixed Incorrect Class Name

File: docs/hooks.md (line 26)

Before:

@param \WP_Abilities_Category_Registry $registry

After:

@param \WP_Ability_Categories_Registry $registry

Reason: The actual class name is WP_Ability_Categories_Registry as defined in includes/abilities-api/class-wp-ability-categories-registry.php (line 18).


Verification

Function Existence Check

All available global functions in includes/abilities-api.php:

  • wp_register_ability() - line 278
  • wp_unregister_ability() - line 324
  • wp_has_ability() - line 357
  • wp_get_ability() - line 389
  • wp_get_abilities() - line 419
  • wp_register_ability_category() - line 467
  • wp_unregister_ability_category() - line 512
  • wp_has_ability_category() - line 544
  • wp_get_ability_category() - line 576
  • wp_get_ability_categories() - line 607
  • wp_execute_ability() - DOES NOT EXIST

Parameter Structure Check

Verified against:

  • Function signature: includes/abilities-api.php (lines 232-277)
  • Core implementation: includes/abilities/wp-core-abilities.php (lines 87-143)
  • Class definition: includes/abilities-api/class-wp-ability.php (lines 213-260)

Impact

Before This PR ❌

Developers following the documentation would:

  1. Get fatal errors calling non-existent wp_execute_ability()
  2. Experience ability registration failures with category in wrong location
  3. Have incorrect class name references in their code

After This PR ✅

Developers can:

  1. Correctly execute abilities using wp_get_ability() and $ability->execute()
  2. Successfully register abilities with proper parameter structure
  3. Reference the correct class names in their implementations

Testing

  • Verified all function names exist in codebase
  • Checked actual implementation matches documented structure
  • Cross-referenced with core ability examples
  • Confirmed class names in actual class files

Checklist

  • Documentation changes are accurate to codebase
  • All code examples are tested against actual implementation
  • Function references verified to exist
  • Parameter structures match function signatures
  • Class names verified in actual class files

Fixes: #139

- Replace non-existent wp_execute_ability() with correct wp_get_ability() and ->execute() pattern
- Move 'category' parameter from meta array to top-level args array in examples
- Fix class name from WP_Abilities_Category_Registry to WP_Ability_Categories_Registry

The documentation incorrectly referenced wp_execute_ability() which does not exist in the codebase (verified in includes/abilities-api.php lines 278-607). The correct approach is to use wp_get_ability() to retrieve the ability object, then call its execute() method (defined in includes/abilities-api/class-wp-ability.php line 595).

Additionally, code examples showed 'category' inside the meta array, but per the function signature (includes/abilities-api.php line 237) and core implementation (includes/abilities/wp-core-abilities.php line 89), category must be a top-level parameter.

Fixes documentation accuracy to match actual codebase implementation.
@github-actions
Copy link

github-actions bot commented Nov 7, 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: huzaifaalmesbah <[email protected]>
Co-authored-by: gziolo <[email protected]>
Co-authored-by: mindctrl <[email protected]>

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

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.46%. Comparing base (0a1cda6) to head (754783c).
⚠️ Report is 1 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #140   +/-   ##
=========================================
  Coverage     80.46%   80.46%           
  Complexity      178      178           
=========================================
  Files            20       20           
  Lines          1474     1474           
  Branches        119      120    +1     
=========================================
  Hits           1186     1186           
  Misses          288      288           
Flag Coverage Δ
javascript 94.61% <ø> (ø)
unit 76.31% <ø> (ø)

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 added the [Type] Developer Documentation Improvements or additions to documentation label Nov 7, 2025
@gziolo gziolo added this to the WP 6.9 milestone Nov 7, 2025
@gziolo gziolo enabled auto-merge (squash) November 14, 2025 11:42
@gziolo gziolo merged commit cc03046 into WordPress:trunk Nov 14, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Developer Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation contains invalid function name and incorrect parameter placement

3 participants