comment-count.php
2.8 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
<?php
/**
* Column displaying the number of comments for an item, displaying either the total
* amount of comments, or the amount per status (e.g. "Approved", "Pending").
*
* @since 2.0
*/
class CPAC_Column_Post_Comment_Count extends CPAC_Column {
/**
* @see CPAC_Column::init()
* @since 2.2.1
*/
public function init() {
parent::init();
// Properties
$this->properties['type'] = 'column-comment_count';
$this->properties['label'] = __( 'Comment count', 'codepress-admin-columns' );
$this->properties['is_cloneable'] = true;
// Options
$this->options['comment_status'] = '';
}
/**
* get_comment_stati
* @since 2.0
*/
function get_comment_stati() {
return array(
'total_comments' => __( 'Total', 'codepress-admin-columns' ),
'approved' => __( 'Approved', 'codepress-admin-columns' ),
'moderated' => __( 'Pending', 'codepress-admin-columns' ),
'spam' => __( 'Spam', 'codepress-admin-columns' ),
'trash' => __( 'Trash', 'codepress-admin-columns' ),
);
}
/**
* @see CPAC_Column::get_value()
* @since 2.0
*/
function get_value( $post_id ) {
$value = '';
$status = $this->options->comment_status;
$count = $this->get_raw_value( $post_id );
if ( $count !== '' ) {
$names = $this->get_comment_stati();
$url = esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => $status ), admin_url( 'edit-comments.php' ) ) );
$value = "<a href='{$url}' class='cp-{$status}' title='" . $names[ $status ] . "'>{$count}</a>";
}
return $value;
}
/**
* @see CPAC_Column::get_raw_value()
* @since 2.0.3
*/
function get_raw_value( $post_id ) {
$value = '';
$status = $this->options->comment_status;
$count = wp_count_comments( $post_id );
if ( isset( $count->{$status} ) ) {
$value = $count->{$status};
}
return $value;
}
/**
* @see CPAC_Column::apply_conditional()
* @since 2.0
*/
function apply_conditional() {
return post_type_supports( $this->storage_model->key, 'comments' );
}
/**
* Display Settings
*
* @see CPAC_Column::display_settings()
* @since 2.0
*/
function display_settings() {
?>
<tr class="column_comment-count">
<?php $this->label_view( __( 'Comment status', 'codepress-admin-columns' ), __( 'Select which comment status you like to display.', 'codepress-admin-columns' ), 'comment-status' ); ?>
<td class="input">
<select name="<?php $this->attr_name( 'comment_status' ); ?>" id="<?php $this->attr_id( 'comment-status' ); ?>">
<?php foreach ( $this->get_comment_stati() as $key => $label ) : ?>
<option value="<?php echo $key; ?>"<?php selected( $key, $this->options->comment_status ) ?>><?php echo $label; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php
}
}