CommentLink.php
1.55 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
<?php
namespace AC\Settings\Column;
use AC\Settings;
use AC\View;
/**
* @since 3.4.6
*/
class CommentLink extends Settings\Column
implements Settings\FormatValue {
/**
* @var string
*/
protected $comment_link_to;
protected function define_options() {
return [
'comment_link_to' => '',
];
}
public function format( $value, $original_value ) {
$id = $original_value;
switch ( $this->get_comment_link_to() ) {
case 'view_comment' :
$link = get_comment_link( $id );
break;
case 'edit_comment' :
$comment = get_comment( $id );
$link = $comment
? get_edit_comment_link( $comment )
: false;
break;
default :
$link = false;
}
if ( $link ) {
$value = ac_helper()->html->link( $link, $value );
}
return $value;
}
public function create_view() {
$select = $this->create_element( 'select' )->set_options( $this->get_link_options() );
$view = new View( [
'label' => __( 'Link To', 'codepress-admin-columns' ),
'setting' => $select,
] );
return $view;
}
protected function get_link_options() {
return [
'' => __( 'None' ),
'view_comment' => __( 'View Comment', 'codepress-admin-columns' ),
'edit_comment' => __( 'Edit Comment', 'codepress-admin-columns' ),
];
}
/**
* @return string
*/
public function get_comment_link_to() {
return $this->comment_link_to;
}
/**
* @param string $comment_link_to
*
* @return bool
*/
public function set_comment_link_to( $comment_link_to ) {
$this->comment_link_to = $comment_link_to;
return true;
}
}