I’m trying to filter a capability check in order to work around the lack of filters to customize the user edit page in the admin area. But I can’t seem to add filters to a hook, and I’m sure I’m missing something basic here.
The hook in question is role_has_cap
, located at line 343 of wp-includes/capabilities.php
. It reads:
$capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name );
I’m trying to test my filter by adding this to my functions.php
:
add_filter('role_has_cap', 'my_role_has_cap_filter', 10, 3);
function my_role_has_cap_filter($var_one, $var_two, $var_three) {
print_r($var_one);
print_r($var_two);
print_r($var_three);
}
But absolutely nothing happens. Even if I add the filter with less parameters than my function requires (which, in my limited knowledge, should trigger a PHP error) I’m completely ignored by WordPress.
What I’m actually trying to achieve is returning false to a current_user_can( 'edit_posts' )
or current_user_can( 'edit_pages' )
when viewing user-edit.php
on the admin area, without actually removing those capabilities, but the fact that a filter is not applying seems to me more relevant that my ultimate goal.