wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_get_abilities › WordPress Function
Since6.9.0
Deprecatedn/a
› wp_get_abilities ( $args = array() )
| Parameters: |
|
| See: |
|
| Returns: |
|
| Defined at: |
|
| Codex: | |
| Change Log: |
|
Retrieves registered abilities, optionally filtered by the given arguments.
When called without arguments, returns all registered abilities. When called with an $args array, returns only abilities that match every specified condition. Filtering pipeline (executed in order): 1. Declarative filters (category, namespace, meta) — per-item, AND logic between
arg types.
2. item_include_callback — per-item, caller-scoped. Return true to include, false to exclude.
3. wp_get_abilities_item_include filter — per-item, ecosystem-scoped. Plugins can enforce
universal inclusion rules regardless of what the caller passed.
4. result_callback — on the full matched array, caller-scoped. Sort, slice, or reshape.
5. wp_get_abilities_result filter — on the full array, ecosystem-scoped.
Steps 1–3 run inside a single loop over the registry — no extra iteration.
Examples:
// All abilities (unchanged behaviour).
$abilities = wp_get_abilities();
// Filter by category.
$abilities = wp_get_abilities( array( 'category' => 'content' ) );
// Filter by namespace.
$abilities = wp_get_abilities( array( 'namespace' => 'woocommerce' ) );
// Filter by meta.
$abilities = wp_get_abilities( array( 'meta' => array( 'show_in_rest' => true ) ) );
// Combine filters (AND logic between arg types).
$abilities = wp_get_abilities( array(
'category' => 'content',
'namespace' => 'core',
'meta' => array( 'show_in_rest' => true ),
) );
// Caller-scoped per-item callback.
$abilities = wp_get_abilities( array(
'item_include_callback' => function ( WP_Ability $ability ) {
return current_user_can( 'manage_options' );
},
) );
// Caller-scoped result callback (sort + paginate).
$abilities = wp_get_abilities( array(
'result_callback' => function ( array $abilities ) {
usort( $abilities, fn( $a, $b ) => strcasecmp( $a->get_label(), $b->get_label() ) );
return array_slice( $abilities, 0, 10 );
},
) );
The pipeline always runs, even when called with no arguments. This ensures that the
wp_get_abilities_item_include and wp_get_abilities_result filters always fire,
giving plugins a reliable place to enforce universal inclusion or shaping rules.
For raw, unfiltered registry data that bypasses the filter pipeline entirely, use
WP_Abilities_Registry::get_all_registered directly.Related Functions: wp_get_ability, wp_get_sites, wp_get_ability_categories, _wp_get_abilities_match_meta, wp_get_ability_category