wp-includes/abilities-api.php:498Retrieves registered abilities, optionally filtered by the given arguments.
$argsarrayoptionalarray()$categorystring
$namespacestring
$metaarray
$item_include_callbackcallable
$result_callbackcallable
WP_Ability[]2 hooks fire while wp_get_abilities() runs, in this order:
Filters whether an individual ability should be included in the result set.
Filters the full list of matched abilities after all per-item filtering is complete.
function wp_get_abilities( array $args = array() ): array { $registry = WP_Abilities_Registry::get_instance(); if ( null === $registry ) { return array(); } $abilities = $registry->get_all_registered(); $category = isset( $args['category'] ) && is_string( $args['category'] ) ? $args['category'] : ''; $namespace = isset( $args['namespace'] ) && is_string( $args['namespace'] ) ? rtrim( $args['namespace'], '/' ) . '/' : ''; $meta = isset( $args['meta'] ) && is_array( $args['meta'] ) ? $args['meta'] : array(); $item_include_callback = isset( $args['item_include_callback'] ) && is_callable( $args['item_include_callback'] ) ? $args['item_include_callback'] : null; $result_callback = isset( $args['result_callback'] ) && is_callable( $args['result_callback'] ) ? $args['result_callback'] : null; $matched = array(); foreach ( $abilities as $name => $ability ) { // Step 1a: Filter by category. if ( '' !== $category && $ability->get_category() !== $category ) { continue; } // Step 1b: Filter by namespace prefix. if ( '' !== $namespace && ! str_starts_with( $ability->get_name(), $namespace ) ) { continue; } // Step 1c: Filter by meta key/value pairs (AND logic, supports nested arrays). if ( ! empty( $meta ) && ! _wp_get_abilities_match_meta( $ability->get_meta(), $meta ) ) { continue; } // Step 2: Caller-scoped per-item callback. $include = true; if ( null !== $item_include_callback ) { $include = (bool) call_user_func( $item_include_callback, $ability ); } /** * Filters whether an individual ability should be included in the result set. * * Fires after the declarative filters and the caller-scoped item_include_callback. * Plugins can use this to enforce universal inclusion rules regardless of * what the caller passed in $args. * * @since 7.1.0 * * @param bool $include Whether to include the ability. Default true (after declarative filters pass). * @param WP_Ability $ability The ability instance being evaluated. * @param array $args The full $args array passed to wp_get_abilities(). */ $include = (bool) apply_filters( 'wp_get_abilities_item_include', $include, $ability, $args ); if ( $include ) { $matched[ $name ] = $ability; } } // Step 4: Caller-scoped result callback. if ( null !== $result_callback ) { $matched = (array) call_user_func( $result_callback, $matched ); } /** * Filters the full list of matched abilities after all per-item filtering is complete. * * Fires after the caller-scoped result_callback. Plugins can use this to sort, * paginate, or reshape the final result set universally. * * @since 7.1.0 * * @param WP_Ability[] $matched The matched abilities after all filtering. * @param array $args The full $args array passed to wp_get_abilities(). */ return (array) apply_filters( 'wp_get_abilities_result', $matched, $args );}Introduced in 6.9.0. One change between 6.9.7 and 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
$args added.verified against sourcesrc/wp-includes/abilities-api.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.