UserName.php
896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace ACP\Helper\Select\Formatter;
use AC;
use WP_User;
class UserName extends AC\Helper\Select\Formatter {
/**
* @var array
*/
private $properties;
public function __construct( AC\Helper\Select\Entities $entities, $properties = [] ) {
$this->properties = array_merge( [
'first_name',
'last_name',
], $properties );
parent::__construct( $entities );
}
/**
* @param WP_User $user
*
* @return string
*/
public function get_label( $user ) {
$name_parts = [];
foreach ( $this->properties as $key ) {
if ( $user->$key ) {
$name_parts[] = $user->$key;
}
}
$label = implode( ' ', $name_parts );
if ( ! $label ) {
$label = $user->user_login;
}
$suffix = $user->user_email ?: $user->user_login;
$label .= sprintf( ' (%s)', $suffix );
return (string) apply_filters( 'acp/select/formatter/user_name', $label, $user );
}
}