post-count.php
2.2 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
<?php
/**
* CPAC_Column_User_Post_Count
*
* @since 2.0
*/
class CPAC_Column_User_Post_Count extends CPAC_Column {
/**
* @see CPAC_Column::init()
* @since 2.2.1
*/
public function init() {
parent::init();
// Properties
$this->properties['type'] = 'column-user_postcount';
$this->properties['label'] = __( 'Post Count', 'codepress-admin-columns' );
$this->properties['is_cloneable'] = true;
// Options
$this->options['post_type'] = '';
}
/**
* Get count
*
* @since 2.0
*/
public function get_count( $user_id ) {
return $this->get_user_postcount( $user_id, $this->options->post_type );
}
/**
* @see CPAC_Column::get_value()
* @since 2.0
*/
function get_value( $user_id ) {
$value = '0';
$count = $this->get_raw_value( $user_id );
if ( $count > 0 )
$value = "<a href='edit.php?post_type={$this->options->post_type}&author={$user_id}'>{$count}</a>";
return $value;
}
/**
* @see CPAC_Column::get_raw_value()
* @since 2.0.3
*/
function get_raw_value( $user_id ) {
return $this->get_count( $user_id );
}
/**
* Display Settings
*
* @see CPAC_Column::display_settings()
* @since 2.0
*/
function display_settings() {
$ptypes = array();
if ( post_type_exists( 'post' ) )
$ptypes['post'] = 'post';
if ( post_type_exists( 'page' ) )
$ptypes['page'] = 'page';
$ptypes = array_merge( $ptypes, get_post_types( array(
'_builtin' => false
)));
// get posttypes and name
$post_types = array();
foreach ( $ptypes as $type ) {
$obj = get_post_type_object( $type );
$post_types[ $type ] = $obj->labels->name;
}
?>
<tr class="<?php $this->properties->type; ?>">
<?php $this->label_view( __( 'Post Type', 'codepress-admin-columns' ), '', 'post_type' ); ?>
<td class="input">
<select name="<?php $this->attr_name( 'post_type' ); ?>" id="<?php $this->attr_id( 'post_type' ); ?>">
<?php foreach ( $post_types as $key => $label ) : ?>
<option value="<?php echo $key; ?>"<?php selected( $key, $this->options->post_type ) ?>><?php echo $label; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php
}
}