Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



current_user_can_for_blog ›

Seit3.0.0
Veraltetn/v
current_user_can_for_blog ( $blog_id, $capability )
Parameter: (2)
  • (int) $blog_id Site ID.
    Erforderlich: Ja
  • (string) $capability Capability or role name.
    Erforderlich: Ja
Gibt zurück:
  • (bool)
Definiert in:
Codex:

Whether current user has a capability or role for a given site.



Quellcode

function current_user_can_for_blog( $blog_id, $capability ) {
	$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;

	$current_user = wp_get_current_user();

	if ( empty( $current_user ) ) {
		if ( $switched ) {
			restore_current_blog();
		}
		return false;
	}

	$args = array_slice( func_get_args(), 2 );
	$args = array_merge( array( $capability ), $args );

	$can = call_user_func_array( array( $current_user, 'has_cap' ), $args );

	if ( $switched ) {
		restore_current_blog();
	}

	return $can;
}