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 / frontend.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
frontend.php
143 lines
1 <?php
2 if(!defined('ABSPATH')) exit;
3
4 new Post_Views_Counter_Frontend();
5
6 class Post_Views_Counter_Frontend
7 {
8 public function __construct()
9 {
10 // actions
11 add_action('wp_loaded', array(&$this, 'register_shortcode'));
12 add_action('wp_enqueue_scripts', array(&$this, 'frontend_scripts_styles'));
13
14 // filters
15 add_filter('the_content', array(&$this, 'add_post_views_count'));
16 add_filter('the_excerpt', array(&$this, 'remove_post_views_count'));
17 }
18
19
20 /**
21 *
22 */
23 public function register_shortcode()
24 {
25 add_shortcode('post-views', array(&$this, 'post_views_shortcode'));
26 }
27
28
29 /**
30 *
31 */
32 public function post_views_shortcode($args)
33 {
34 $defaults = array(
35 'id' => get_the_ID()
36 );
37
38 $args = shortcode_atts($defaults, $args);
39
40 return pvc_post_views($args['id'], false);
41 }
42
43
44 /**
45 *
46 */
47 public function add_post_views_count($content)
48 {
49 if(is_singular() && in_array(get_post_type(), Post_Views_Counter()->get_attribute('options', 'display', 'post_types_display'), true))
50 {
51 // gets groups to check it faster
52 $groups = Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'groups');
53
54 // whether to display views
55 if(is_user_logged_in())
56 {
57 // exclude logged in users?
58 if(in_array('users', $groups, true))
59 return $content;
60 // exclude specific roles?
61 elseif(in_array('roles', $groups, true) && Post_Views_Counter()->get_instance('counter')->is_user_roles_excluded(Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'roles')))
62 return $content;
63 }
64 // exclude guests?
65 elseif(in_array('guests', $groups, true))
66 return $content;
67
68 switch(Post_Views_Counter()->get_attribute('options', 'display', 'position'))
69 {
70 case 'after':
71 return $content.'[post-views]';
72
73 case 'before':
74 return '[post-views]'.$content;
75
76 default:
77 case 'manual':
78 return $content;
79 }
80 }
81
82 return $content;
83 }
84
85
86 /**
87 * Remove post views shortcode from excerpt
88 */
89 public function remove_post_views_count($excerpt)
90 {
91 remove_shortcode('post-views');
92 $excerpt = preg_replace ('/\[post-views[^\]]*\]/', '', $excerpt);
93 return $excerpt;
94 }
95
96
97 /**
98 *
99 */
100 public function frontend_scripts_styles()
101 {
102 $post_types = Post_Views_Counter()->get_attribute('options', 'display', 'post_types_display');
103
104 // loads dashicons
105 wp_enqueue_style('dashicons');
106
107 wp_register_style(
108 'post-views-counter-frontend',
109 POST_VIEWS_COUNTER_URL.'/css/frontend.css'
110 );
111
112 wp_enqueue_style('post-views-counter-frontend');
113
114 if(Post_Views_Counter()->get_attribute('options', 'general', 'counter_mode') === 'js')
115 {
116 $post_types = Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count');
117
118 // whether to count this post type
119 if(empty($post_types) || !is_singular($post_types))
120 return;
121
122 wp_register_script(
123 'post-views-counter-frontend',
124 POST_VIEWS_COUNTER_URL.'/js/frontend.js',
125 array('jquery')
126 );
127
128 wp_enqueue_script('post-views-counter-frontend');
129
130 wp_localize_script(
131 'post-views-counter-frontend',
132 'pvcArgsFrontend',
133 array(
134 'ajaxURL' => admin_url('admin-ajax.php'),
135 'postID' => get_the_ID(),
136 'nonce' => wp_create_nonce('pvc-check-post'),
137 'postType' => get_post_type()
138 )
139 );
140 }
141 }
142 }
143 ?>