filtrod 2.0.0
user_has_cap
Opis
Filtruje uprawnienia użytkownika przy sprawdzaniu current_user_can().
Przykład użycia
add_filter( 'user_has_cap', ... )php
add_filter( 'user_has_cap', 'wpdocs_grant_librarian_cap', 10, 4 );
function wpdocs_grant_librarian_cap( $allcaps, $caps, $args, $user ) {
if ( in_array( 'manage_books', $caps, true ) && in_array( 'bibliotekarz', $user->roles, true ) ) {
$allcaps['manage_books'] = true;
}
return $allcaps;
}
add_filter( 'user_has_cap', 'wpdocs_grant_librarian_cap', 10, 4 );
function wpdocs_grant_librarian_cap( $allcaps, $caps, $args, $user ) {
if ( in_array( 'manage_books', $caps, true ) && in_array( 'bibliotekarz', $user->roles, true ) ) {
$allcaps['manage_books'] = true;
}
return $allcaps;
}Parametry
| Parametr | Typ | Opis |
|---|---|---|
$allcaps | bool[] | Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability. |
$caps | string[] | Required primitive capabilities for the requested capability. |
$args | array | { Arguments that accompany the requested capability check. @type string $0 Requested capability. @type int $1 Concerned user ID. @type mixed ...$2 Optional second and further parameters, typically object ID. } |
$user | \WP_User | The user object. |
Wywołanie
Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'user_has_cap', 'twoja_funkcja', 10, 4 );
function twoja_funkcja($param_1, $param_2, $param_3, $param_4) {
// Twój kod
}
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'user_has_cap', 'twoja_funkcja', 10, 4 );
function twoja_funkcja($param_1, $param_2, $param_3, $param_4) {
// Twój kod
}Popularne w tej kategorii