Completed
Push — milestone/2_0/container-condit... ( c41f81...3ee472 )
by
unknown
04:49
created

Current_User_Role_Condition   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_user_roles() 0 5 2
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if the currently logged in user has a specific role
7
 * 
8
 * Operator "CUSTOM" is passed an array of all user roles
9
 */
10
class Current_User_Role_Condition extends User_Role_Condition {
11
	
12
	/**
13
	 * Get roles for a user from the environment
14
	 * 
15
	 * @param  array         $environment
16
	 * @return array<string>
17
	 */
18
	protected function get_user_roles( $environment ) {
19
		$user = wp_get_current_user();
20
		$roles = $user ? $user->roles : array();
21
		return $roles;
22
	}
23
}