PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.0.6
Post Views Counter v1.0.6
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / columns.php
post-views-counter / includes Last commit date
columns.php 11 years ago counter.php 11 years ago cron.php 11 years ago frontend.php 11 years ago functions.php 11 years ago query.php 11 years ago settings.php 11 years ago update.php 11 years ago widgets.php 11 years ago
columns.php
116 lines
1 <?php
2 if(!defined('ABSPATH')) exit;
3
4 new Post_Views_Counter_Columns();
5
6 class Post_Views_Counter_Columns {
7
8 public function __construct() {
9 // actions
10 add_action('current_screen', array(&$this, 'register_new_column'));
11 }
12
13 /**
14 * Register post views column for specific post types
15 */
16 public function register_new_column() {
17 $screen = get_current_screen();
18
19 if (Post_Views_Counter()->get_attribute('options', 'general', 'post_views_column') && ($screen->base == 'edit' && in_array($screen->post_type, Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count')))) {
20
21 foreach (Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count') as $post_type) {
22
23 if ($post_type === 'page' && $screen->post_type === 'page') {
24 // actions
25 add_action('manage_pages_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
26
27 // filters
28 add_filter('manage_pages_columns', array(&$this, 'add_new_column'));
29 add_filter('manage_edit-page_sortable_columns', array(&$this, 'register_sortable_custom_column'));
30 }
31 elseif ($post_type === 'post' && $screen->post_type === 'post') {
32 // actions
33 add_action('manage_posts_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
34
35 // filters
36 add_filter('manage_posts_columns', array(&$this, 'add_new_column'));
37 add_filter('manage_edit-post_sortable_columns', array(&$this, 'register_sortable_custom_column'));
38 }
39 elseif ($screen->post_type === $post_type) {
40 // actions
41 add_action('manage_'.$post_type.'_posts_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
42
43 // filters
44 add_filter('manage_'.$post_type.'_posts_columns', array(&$this, 'add_new_column'));
45 add_filter('manage_edit-'.$post_type.'_sortable_columns', array(&$this, 'register_sortable_custom_column'));
46 }
47
48 }
49 }
50 }
51
52 /**
53 * Register sortable post views column
54 */
55 public function register_sortable_custom_column($columns) {
56 // add new sortable column
57 $columns['post_views'] = 'post_views';
58
59 return $columns;
60 }
61
62 /**
63 * Add post views column
64 */
65 public function add_new_column($columns) {
66 $offset = 0;
67
68 if (isset($columns['date']))
69 $offset++;
70
71 if (isset($columns['comments']))
72 $offset++;
73
74 if ($offset > 0) {
75 $date = array_slice($columns, -$offset, $offset, true);
76
77 foreach ($date as $column => $name) {
78 unset($columns[$column]);
79 }
80
81 $columns['post_views'] = __('Post Views', 'post-views-counter');
82
83 foreach ($date as $column => $name) {
84 $columns[$column] = $name;
85 }
86 }
87 else
88 $columns['post_views'] = __('Post Views', 'post-views-counter');
89
90 return $columns;
91 }
92
93 /**
94 * Add post views column content
95 */
96 public function add_new_column_content($column_name, $id) {
97
98 if ($column_name === 'post_views') {
99
100 global $wpdb;
101
102 // get total post views
103 $views = $wpdb->get_var(
104 $wpdb->prepare("
105 SELECT count
106 FROM ".$wpdb->prefix."post_views
107 WHERE id = %d AND type = 4",
108 $id
109 )
110 );
111
112 echo (int)$views;
113 }
114 }
115 }
116 ?>