Yoast_Notification::match_capabilities
Does the current user match required capabilities.
Метод класса: Yoast_Notification{}
Возвращает
true|false.
Использование
$Yoast_Notification = new Yoast_Notification(); $Yoast_Notification->match_capabilities();
Код Yoast_Notification::match_capabilities() Yoast Notification::match capabilities Yoast 26.5
public function match_capabilities() {
// Super Admin can do anything.
if ( is_multisite() && is_super_admin( $this->options['user_id'] ) ) {
return true;
}
/**
* Filter capabilities that enable the displaying of this notification.
*
* @param array $capabilities The capabilities that must be present for this notification.
* @param Yoast_Notification $notification The notification object.
*
* @return array Array of capabilities or empty for no restrictions.
*
* @since 3.2
*/
$capabilities = apply_filters( 'wpseo_notification_capabilities', $this->options['capabilities'], $this );
// Should be an array.
if ( ! is_array( $capabilities ) ) {
$capabilities = (array) $capabilities;
}
/**
* Filter capability check to enable all or any capabilities.
*
* @param string $capability_check The type of check that will be used to determine if an capability is present.
* @param Yoast_Notification $notification The notification object.
*
* @return string self::MATCH_ALL or self::MATCH_ANY.
*
* @since 3.2
*/
$capability_check = apply_filters( 'wpseo_notification_capability_check', $this->options['capability_check'], $this );
if ( ! in_array( $capability_check, [ self::MATCH_ALL, self::MATCH_ANY ], true ) ) {
$capability_check = self::MATCH_ALL;
}
if ( ! empty( $capabilities ) ) {
$has_capabilities = array_filter( $capabilities, [ $this, 'has_capability' ] );
switch ( $capability_check ) {
case self::MATCH_ALL:
return $has_capabilities === $capabilities;
case self::MATCH_ANY:
return ! empty( $has_capabilities );
}
}
return true;
}