User.php
1.77 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace ACP\Settings\Column;
use AC;
class User extends AC\Settings\Column\User
{
public const PROPERTY_META = 'custom_field';
public const PROPERTY_GRAVATAR = 'gravatar';
protected function get_display_options()
{
$options = parent::get_display_options();
$options[self::PROPERTY_GRAVATAR] = __('Gravatar', 'codepress-admin-columns');
natcasesort($options);
// Grouped options
return [
[
'title' => __('User', 'codepress-admin-columns'),
'options' => $options,
],
[
'title' => __('Custom Field', 'codepress-admin-columns'),
'options' => [
self::PROPERTY_META => __('Custom Field', 'codepress-admin-columns'),
],
],
];
}
public function get_dependent_settings()
{
switch ($this->get_display_author_as()) {
case self::PROPERTY_META :
return [new UserCustomField($this->column)];
case self::PROPERTY_GRAVATAR :
return [new Gravatar($this->column)];
default:
return parent::get_dependent_settings();
}
}
public function format($user_id, $original_value)
{
switch ($this->get_display_author_as()) {
case self::PROPERTY_META :
/** @var UserCustomField $setting */
$setting = $this->column->get_setting(UserCustomField::NAME);
return get_user_meta($user_id, $setting->get_field(), true);
case self::PROPERTY_GRAVATAR :
return get_avatar_url($user_id);
default:
return parent::format($user_id, $original_value);
}
}
}