PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.0.3
Post Views Counter v1.0.3
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 12 years ago counter.php 12 years ago cron.php 12 years ago frontend.php 11 years ago functions.php 12 years ago query.php 12 years ago settings.php 12 years ago update.php 12 years ago widgets.php 12 years ago
columns.php
126 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 {
10 // actions
11 add_action('current_screen', array(&$this, 'register_new_column'));
12 }
13
14
15 /**
16 *
17 */
18 public function register_new_column()
19 {
20 $screen = get_current_screen();
21
22 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'))))
23 {
24 foreach(Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count') as $post_type)
25 {
26 if($post_type === 'page' && $screen->post_type === 'page')
27 {
28 // actions
29 add_action('manage_pages_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
30
31 // filters
32 add_filter('manage_pages_columns', array(&$this, 'add_new_column'));
33 add_filter('manage_edit-page_sortable_columns', array(&$this, 'register_sortable_custom_column'));
34 }
35 elseif($post_type === 'post' && $screen->post_type === 'post')
36 {
37 // actions
38 add_action('manage_posts_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
39
40 // filters
41 add_filter('manage_posts_columns', array(&$this, 'add_new_column'));
42 add_filter('manage_edit-post_sortable_columns', array(&$this, 'register_sortable_custom_column'));
43 }
44 elseif($screen->post_type === $post_type)
45 {
46 // actions
47 add_action('manage_'.$post_type.'_posts_custom_column', array(&$this, 'add_new_column_content'), 10, 2);
48
49 // filters
50 add_filter('manage_'.$post_type.'_posts_columns', array(&$this, 'add_new_column'));
51 add_filter('manage_edit-'.$post_type.'_sortable_columns', array(&$this, 'register_sortable_custom_column'));
52 }
53 }
54 }
55 }
56
57
58 /**
59 * Registers sortable column
60 */
61 public function register_sortable_custom_column($columns)
62 {
63 // adds new sortable column
64 $columns['post_views'] = 'post_views';
65
66 return $columns;
67 }
68
69
70 /**
71 * Adds new content to specific column
72 */
73 public function add_new_column_content($column_name, $id)
74 {
75 if($column_name === 'post_views')
76 {
77 global $wpdb;
78
79 // gets post views
80 $views = $wpdb->get_var(
81 $wpdb->prepare("
82 SELECT count
83 FROM ".$wpdb->prefix."post_views
84 WHERE id = %d AND type = 4",
85 $id
86 )
87 );
88
89 echo (int)$views;
90 }
91 }
92
93
94 public function add_new_column($columns)
95 {
96 $offset = 0;
97
98 if(isset($columns['date']))
99 $offset++;
100
101 if(isset($columns['comments']))
102 $offset++;
103
104 if($offset > 0)
105 {
106 $date = array_slice($columns, -$offset, $offset, true);
107
108 foreach($date as $column => $name)
109 {
110 unset($columns[$column]);
111 }
112
113 $columns['post_views'] = __('Post Views', 'post-views-counter');
114
115 foreach($date as $column => $name)
116 {
117 $columns[$column] = $name;
118 }
119 }
120 else
121 $columns['post_views'] = __('Post Views', 'post-views-counter');
122
123 return $columns;
124 }
125 }
126 ?>