Skip to content

Commit ba95508

Browse files
committed
Tests/Feature #64990: Add unit tests for wp_get_abilities() filtering and rename private helper to _wp_get_abilities_match_meta
- Rename wp_get_abilities_match_meta() to _wp_get_abilities_match_meta() per WordPress private function naming convention - Add tests/phpunit/tests/abilities-api/wpGetAbilities.php covering: - category filter (single string, array OR logic, non-existent) - namespace filter (prefix match, trailing-slash normalisation, non-existent) - meta filter (single key, AND logic across keys, nested arrays, missing key) - match_callback per-item inclusion/exclusion and argument passing - wp_get_abilities_match filter hook exclusion and argument passing - result_callback result reshaping and argument passing - wp_get_abilities_result filter hook reshaping and argument passing - Combined category + meta and namespace + match_callback filters
1 parent 0350d8e commit ba95508

2 files changed

Lines changed: 688 additions & 3 deletions

File tree

src/wp-includes/abilities-api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ function wp_get_abilities( array $args = array() ): array {
513513
}
514514

515515
// Step 1c: Filter by meta key/value pairs (AND logic, supports nested arrays).
516-
if ( ! empty( $meta ) && ! wp_get_abilities_match_meta( $ability->get_meta(), $meta ) ) {
516+
if ( ! empty( $meta ) && ! _wp_get_abilities_match_meta( $ability->get_meta(), $meta ) ) {
517517
continue;
518518
}
519519

@@ -575,14 +575,14 @@ function wp_get_abilities( array $args = array() ): array {
575575
* @param array $conditions The required key/value conditions to match against.
576576
* @return bool True if all conditions match, false otherwise.
577577
*/
578-
function wp_get_abilities_match_meta( array $meta, array $conditions ): bool {
578+
function _wp_get_abilities_match_meta( array $meta, array $conditions ): bool {
579579
foreach ( $conditions as $key => $value ) {
580580
if ( ! array_key_exists( $key, $meta ) ) {
581581
return false;
582582
}
583583

584584
if ( is_array( $value ) ) {
585-
if ( ! is_array( $meta[ $key ] ) || ! wp_get_abilities_match_meta( $meta[ $key ], $value ) ) {
585+
if ( ! is_array( $meta[ $key ] ) || ! _wp_get_abilities_match_meta( $meta[ $key ], $value ) ) {
586586
return false;
587587
}
588588
} elseif ( $meta[ $key ] !== $value ) {

0 commit comments

Comments
 (0)