PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.0.1
Post Views Counter v1.0.1
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 12 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
131 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_counts'));
16 }
17
18
19 /**
20 *
21 */
22 public function register_shortcode()
23 {
24 add_shortcode('post-views', array(&$this, 'post_views_shortcode'));
25 }
26
27
28 /**
29 *
30 */
31 public function post_views_shortcode($args)
32 {
33 $defaults = array(
34 'id' => get_the_ID()
35 );
36
37 $args = shortcode_atts($defaults, $args);
38
39 return pvc_post_views($args['id'], false);
40 }
41
42
43 /**
44 *
45 */
46 public function add_post_counts($content)
47 {
48 if(is_singular() && in_array(get_post_type(), Post_Views_Counter()->get_attribute('options', 'display', 'post_types_display'), true))
49 {
50 // gets groups to check it faster
51 $groups = Post_Views_Counter()->get_attribute('options', 'display', 'restrict_display', 'groups');
52
53 // whether to display views
54 if(is_user_logged_in())
55 {
56 // exclude logged in users?
57 if(in_array('users', $groups, true))
58 return $content;
59 // exclude specific roles?
60 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')))
61 return $content;
62 }
63 // exclude guests?
64 elseif(in_array('guests', $groups, true))
65 return $content;
66
67 switch(Post_Views_Counter()->get_attribute('options', 'display', 'position'))
68 {
69 case 'after':
70 return $content.'[post-views]';
71
72 case 'before':
73 return '[post-views]'.$content;
74
75 default:
76 case 'manual':
77 return $content;
78 }
79 }
80
81 return $content;
82 }
83
84
85 /**
86 *
87 */
88 public function frontend_scripts_styles()
89 {
90 $post_types = Post_Views_Counter()->get_attribute('options', 'display', 'post_types_display');
91
92 // loads dashicons
93 wp_enqueue_style('dashicons');
94
95 wp_register_style(
96 'post-views-counter-frontend',
97 POST_VIEWS_COUNTER_URL.'/css/frontend.css'
98 );
99
100 wp_enqueue_style('post-views-counter-frontend');
101
102 if(Post_Views_Counter()->get_attribute('options', 'general', 'counter_mode') === 'js')
103 {
104 $post_types = Post_Views_Counter()->get_attribute('options', 'general', 'post_types_count');
105
106 // whether to count this post type
107 if(empty($post_types) || !is_singular($post_types))
108 return;
109
110 wp_register_script(
111 'post-views-counter-frontend',
112 POST_VIEWS_COUNTER_URL.'/js/frontend.js',
113 array('jquery')
114 );
115
116 wp_enqueue_script('post-views-counter-frontend');
117
118 wp_localize_script(
119 'post-views-counter-frontend',
120 'pvcArgsFrontend',
121 array(
122 'ajaxURL' => admin_url('admin-ajax.php'),
123 'postID' => get_the_ID(),
124 'nonce' => wp_create_nonce('pvc-check-post'),
125 'postType' => get_post_type()
126 )
127 );
128 }
129 }
130 }
131 ?>