Comment.php
3.07 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
/**
* @since 3.0.8
*/
class Comment extends Settings\Column
implements Settings\FormatValue {
const NAME = 'comment';
const PROPERTY_COMMENT = 'comment';
const PROPERTY_DATE = 'date';
const PROPERTY_ID = 'id';
const PROPERTY_AUTHOR = 'author';
const PROPERTY_AUTHOR_EMAIL = 'author_email';
/**
* @var string
*/
private $comment_property;
protected function set_name() {
$this->name = self::NAME;
}
protected function define_options() {
return [
'comment_property_display' => 'comment',
];
}
public function get_dependent_settings() {
switch ( $this->get_comment_property_display() ) {
case self::PROPERTY_DATE :
return [
new Settings\Column\Date( $this->column ),
new Settings\Column\CommentLink( $this->column ),
];
case self::PROPERTY_COMMENT :
return [
new Settings\Column\StringLimit( $this->column ),
new Settings\Column\CommentLink( $this->column ),
];
default :
return [ new Settings\Column\CommentLink( $this->column ) ];
}
}
/**
* @param int $id
* @param mixed $original_value
*
* @return string|int
*/
public function format( $id, $original_value ) {
switch ( $this->get_comment_property_display() ) {
case self::PROPERTY_DATE :
$value = $this->get_comment_property( 'comment_date', $id );
break;
case self::PROPERTY_AUTHOR :
$value = $this->get_comment_property( 'comment_author', $id );
break;
case self::PROPERTY_AUTHOR_EMAIL :
$value = $this->get_comment_property( 'comment_author_email', $id );
break;
case self::PROPERTY_COMMENT :
$value = $this->get_comment_property( 'comment_content', $id );
break;
default :
$value = $id;
}
return $value;
}
/**
* @param string $property
* @param int $id
*
* @return false|string
*/
private function get_comment_property( $property, $id ) {
$comment = get_comment( $id );
if ( ! isset( $comment->{$property} ) ) {
return false;
}
return $comment->{$property};
}
public function create_view() {
$select = $this->create_element( 'select' )
->set_attribute( 'data-refresh', 'column' )
->set_options( $this->get_display_options() );
$view = new View( [
'label' => __( 'Display', 'codepress-admin-columns' ),
'setting' => $select,
] );
return $view;
}
protected function get_display_options() {
$options = [
self::PROPERTY_COMMENT => __( 'Comment' ),
self::PROPERTY_ID => __( 'ID' ),
self::PROPERTY_AUTHOR => __( 'Author' ),
self::PROPERTY_AUTHOR_EMAIL => __( 'Author Email', 'codepress-admin-column' ),
self::PROPERTY_DATE => __( 'Date' ),
];
natcasesort( $options );
return $options;
}
/**
* @return string
*/
public function get_comment_property_display() {
return $this->comment_property;
}
/**
* @param string $comment_property
*
* @return bool
*/
public function set_comment_property_display( $comment_property ) {
$this->comment_property = $comment_property;
return true;
}
}