WP HOOKS
filtrod 2.0.0

user_has_cap

Args 4Plik wp-includes/class-wp-user.phpDokumentacja WP ↗

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;
}

Parametry

ParametrTypOpis
$allcapsbool[]Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.
$capsstring[]Required primitive capabilities for the requested capability.
$argsarray{ 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_UserThe 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
}

Popularne w tej kategorii