/
admin.php
66 lines (47 loc) · 1.5 KB
/
admin.php
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
<?php
class WP_Piwik_More_Stats_Admin {
public function __construct() {
$post_types = get_post_types( array( 'public' => true ), 'names' );
foreach( $post_types as $name ) {
add_filter( 'manage_edit-' . $name . '_columns', array( $this, 'columns' ), 10, 1 );
add_filter( 'manage_edit-' . $name . '_sortable_columns', array( $this, 'sortable_columns' ) );
add_action( 'manage_' . $name . '_posts_custom_column', array( $this, 'column_value' ), 10, 2 );
}
add_filter( 'request', array( $this, 'filter_table_view' ) );
add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ) );
}
public function columns( $columns ) {
$columns['piwik_count'] = __( 'Count', 'wp-piwik-more-stats' );
return $columns;
}
public function sortable_columns( $columns ) {
$columns['piwik_count'] = 'piwik_count';
return $columns;
}
public function column_value( $column, $post_id ) {
if ( 'piwik_count' == $column ) {
echo WP_Piwik_More_Stats_API::get_count_from_post( $post_id );
}
}
public function filter_table_view( $vars ) {
if ( array_key_exists( 'orderby', $vars ) ) {
if ( 'piwik_count' == $vars['orderby'] ) {
$vars['orderby'] = 'meta_value_num';
$vars['meta_key'] = 'piwik_post_count_730';
}
}
return $vars;
}
public function admin_print_styles() {
$screen = get_current_screen();
if ( 'edit' == $screen->base ) {
echo '
<style type="text/css">
.column-piwik_count {
width: 8%;
}
</style>
' . PHP_EOL;
}
}
}