Entry Views - Version 1.0.0

Version Description

Download this release

Release Info

Developer greenshady
Plugin Icon wp plugin Entry Views
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

entry-views.php ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Entry Views
4
+ * Plugin URI: http://themehybrid.com/plugins/entry-views
5
+ * Description: A WordPress plugin for tracking the number of post views.
6
+ * Version: 1.0.0
7
+ * Author: Justin Tadlock
8
+ * Author URI: http://justintadlock.com
9
+ * Text Domain: entry-views
10
+ * Domain Path: /languages
11
+ *
12
+ * Entry views is a script for calculating the number of views a post gets. It is meant to be basic and
13
+ * not a full-featured solution. The idea is to allow theme/plugin authors to quickly load this file and
14
+ * build functions on top of it to suit their project needs. This is an AJAX-based solution, so only visitors
15
+ * to your site with JavaScript enabled in their browser will update the view count. It is possible to do this
16
+ * without AJAX but not recommend (see notes below).
17
+ *
18
+ * Not using AJAX: You can call up ev_set_post_view_count() at any time and pass it a post ID to update the
19
+ * count, but this has problems. Any links with rel="next" or rel="prefetch" will cause some browsers to prefetch
20
+ * the data for that particular page. This can cause the view count to be skewed. To try and avoid this
21
+ * issue, you need to disable/remove adjacent_posts_rel_link_wp_head(). However, this is not bullet-proof
22
+ * as it cannot control links it doesn't know about.
23
+ * @link http://core.trac.wordpress.org/ticket/14568
24
+ *
25
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
26
+ * General Public License as published by the Free Software Foundation; either version 2 of the License,
27
+ * or (at your option) any later version.
28
+ *
29
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
30
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31
+ *
32
+ * @package EntryViews
33
+ * @version 1.0.0
34
+ * @author Justin Tadlock <justin@justintadlock.com>
35
+ * @copyright Copyright (c) 2010 - 2014, Justin Tadlock
36
+ * @link http://themehybrid.com/plugins/entry-views
37
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
38
+ */
39
+
40
+ /**
41
+ * Plugin loader class.
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ final class Entry_Views_Plugin {
46
+
47
+ /**
48
+ * Holds the instances of this class.
49
+ *
50
+ * @since 1.0.0
51
+ * @access private
52
+ * @var object
53
+ */
54
+ private static $instance;
55
+
56
+ /**
57
+ * The post ID to update the entry views for.
58
+ *
59
+ * @since 1.0.0
60
+ * @access public
61
+ * @var int
62
+ */
63
+ public $post_id = 0;
64
+
65
+ /**
66
+ * Sets up needed actions/filters for the plugin to initialize.
67
+ *
68
+ * @since 1.0.0
69
+ * @access public
70
+ * @return void
71
+ */
72
+ public function __construct() {
73
+
74
+ add_action( 'plugins_loaded', array( $this, 'i18n' ), 2 );
75
+ add_action( 'plugins_loaded', array( $this, 'includes' ), 3 );
76
+ add_action( 'init', array( $this, 'post_type_support' ), 10 );
77
+ add_action( 'widgets_init', array( $this, 'register_widgets' ), 10 );
78
+ add_action( 'template_redirect', array( $this, 'load' ), 99 );
79
+ add_action( 'wp_ajax_entry_views', array( $this, 'update_ajax' ), 10 );
80
+ add_action( 'wp_ajax_nopriv_entry_views', array( $this, 'update_ajax' ), 10 );
81
+ }
82
+
83
+ /**
84
+ * Loads the translation files.
85
+ *
86
+ * @since 1.0.0
87
+ * @access public
88
+ * @return void
89
+ */
90
+ function i18n() {
91
+ load_plugin_textdomain( 'entry-views', false, 'entry-views/languages' );
92
+ }
93
+
94
+ /**
95
+ * Loads the initial files needed by the plugin.
96
+ *
97
+ * @since 1.0.0
98
+ * @access public
99
+ * @return void
100
+ */
101
+ function includes() {
102
+ $path = trailingslashit( plugin_dir_path( __FILE__ ) );
103
+
104
+ require_once( "{$path}inc/functions.php" );
105
+ require_once( "{$path}inc/template.php" );
106
+ require_once( "{$path}inc/shortcodes.php" );
107
+ require_once( "{$path}inc/widget-entry-views.php" );
108
+ }
109
+
110
+ /**
111
+ * Adds support for 'entry-views' to the 'post', 'page', and 'attachment' post types (default WordPress
112
+ * post types). For all other post types, the theme should explicitly register support for this feature.
113
+ *
114
+ * @since 1.0.0
115
+ * @access public
116
+ * @return void
117
+ */
118
+ function post_type_support() {
119
+
120
+ /* Core post types. */
121
+ add_post_type_support( 'post', array( 'entry-views' ) );
122
+ add_post_type_support( 'page', array( 'entry-views' ) );
123
+ add_post_type_support( 'attachment', array( 'entry-views' ) );
124
+
125
+ /* Plugin post types. */
126
+ add_post_type_support( 'literature', array( 'entry-views' ) );
127
+ add_post_type_support( 'portfolio_item', array( 'entry-views' ) );
128
+ add_post_type_support( 'recipe', array( 'entry-views' ) );
129
+ add_post_type_support( 'restaurant_item', array( 'entry-views' ) );
130
+ }
131
+
132
+ /**
133
+ * Registers the plugin's widgets.
134
+ *
135
+ * @since 1.0.0
136
+ * @access public
137
+ * @return void
138
+ */
139
+ public function register_widgets() {
140
+
141
+ register_widget( 'EV_Widget_Entry_Views' );
142
+ }
143
+
144
+ /**
145
+ * Checks if we're on a singular post view and if the current post type supports the 'entry-views'
146
+ * extension. If so, set the $post_id variable and load the needed JavaScript.
147
+ *
148
+ * @since 1.0.0
149
+ * @access public
150
+ * @return void
151
+ */
152
+ function load() {
153
+
154
+ /* Check if we're on a singular post view. */
155
+ if ( is_singular() && !is_preview() ) {
156
+
157
+ /* Get the post object. */
158
+ $post = get_queried_object();
159
+
160
+ /* Check if the post type supports the 'entry-views' feature. */
161
+ if ( post_type_supports( $post->post_type, 'entry-views' ) ) {
162
+
163
+ /* Set the post ID for later use because we wouldn't want a custom query to change this. */
164
+ $this->post_id = get_queried_object_id();
165
+
166
+ /* Enqueue the jQuery library. */
167
+ wp_enqueue_script( 'jquery' );
168
+
169
+ /* Load the entry views JavaScript in the footer. */
170
+ add_action( 'wp_footer', array( $this, 'load_scripts' ) );
171
+ }
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Callback function hooked to 'wp_ajax_entry_views' and 'wp_ajax_nopriv_entry_views'. It checks the
177
+ * AJAX nonce and passes the given $post_id to the entry views update function.
178
+ *
179
+ * @since 1.0.0
180
+ * @access public
181
+ * @return void
182
+ */
183
+ function update_ajax() {
184
+
185
+ /* Check the AJAX nonce to make sure this is a valid request. */
186
+ check_ajax_referer( 'entry_views_ajax' );
187
+
188
+ /* If the post ID is set, set it to the $post_id variable and make sure it's an integer. */
189
+ if ( isset( $_POST['post_id'] ) )
190
+ $post_id = absint( $_POST['post_id'] );
191
+
192
+ /* If $post_id isn't empty, pass it to the ev_set_post_view_count() function to update the view count. */
193
+ if ( !empty( $post_id ) )
194
+ ev_set_post_view_count( $post_id );
195
+ }
196
+
197
+ /**
198
+ * Displays a small script that sends an AJAX request for the page. It passes the $post_id to the AJAX
199
+ * callback function for updating the meta.
200
+ *
201
+ * @since 1.0.0
202
+ * @access public
203
+ * @return void
204
+ */
205
+ function load_scripts() {
206
+
207
+ /* Create a nonce for the AJAX request. */
208
+ $nonce = wp_create_nonce( 'entry_views_ajax' );
209
+
210
+ /* Display the JavaScript needed. */
211
+ echo '<script type="text/javascript">/* <![CDATA[ */ jQuery(document).ready( function() { jQuery.post( "' . admin_url( 'admin-ajax.php' ) . '", { action : "entry_views", _ajax_nonce : "' . $nonce . '", post_id : ' . absint( $this->post_id ) . ' } ); } ); /* ]]> */</script>' . "\n";
212
+ }
213
+
214
+ /**
215
+ * Returns the instance.
216
+ *
217
+ * @since 1.0.0
218
+ * @access public
219
+ * @return object
220
+ */
221
+ public static function get_instance() {
222
+
223
+ if ( !self::$instance )
224
+ self::$instance = new self;
225
+
226
+ return self::$instance;
227
+ }
228
+ }
229
+
230
+ Entry_Views_Plugin::get_instance();
inc/functions.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin functions.
4
+ *
5
+ * @package EntryViews
6
+ * @version 1.0.0
7
+ * @author Justin Tadlock <justin@justintadlock.com>
8
+ * @copyright Copyright (c) 2010 - 2014, Justin Tadlock
9
+ * @link http://themehybrid.com/plugins/entry-views
10
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ /**
14
+ * Returns the meta key used throughout the plugin for getting/setting the post view count, which is
15
+ * saved as post metadata. Developers can also filter this via the `ev_meta_key` hook if they need
16
+ * to alter it to match a meta key that was previously used by another plugin.
17
+ *
18
+ * @since 1.0.0
19
+ * @access public
20
+ * @return string
21
+ */
22
+ function ev_get_meta_key() {
23
+ return apply_filters( 'ev_meta_key', 'Views' );
24
+ }
25
+
26
+ /**
27
+ * Sets the post view count of specific post by adding +1 to the total count. This function should only
28
+ * be used if you want to add an addtional +1 to the count.
29
+ *
30
+ * @since 1.0.0
31
+ * @access public
32
+ * @param int $post_id
33
+ * @return void
34
+ */
35
+ function ev_set_post_view_count( $post_id ) {
36
+
37
+ /* Get the number of views the post currently has. */
38
+ $old_views = get_post_meta( $post_id, ev_get_meta_key(), true );
39
+
40
+ /* Add +1 to the number of current views. */
41
+ $new_views = absint( $old_views ) + 1;
42
+
43
+ /* Update the view count with the new view count. */
44
+ update_post_meta( $post_id, ev_get_meta_key(), $new_views, $old_views );
45
+ }
46
+
47
+ /**
48
+ * Gets the view count of a specific post.
49
+ *
50
+ * @since 1.0.0
51
+ * @access public
52
+ * @param int $post_id
53
+ * @return int
54
+ */
55
+ function ev_get_post_view_count( $post_id ) {
56
+
57
+ /* Get the number of views the post has. */
58
+ $views = get_post_meta( $post_id, ev_get_meta_key(), true );
59
+
60
+ /* Return the view count and make sure it's an integer. */
61
+ return !empty( $views ) ? number_format_i18n( absint( $views ) ) : 0;
62
+ }
inc/shortcodes.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shortcodes for the plgin.
4
+ *
5
+ * @package EntryViews
6
+ * @version 1.0.0
7
+ * @author Justin Tadlock <justin@justintadlock.com>
8
+ * @copyright Copyright (c) 2010 - 2014, Justin Tadlock
9
+ * @link http://themehybrid.com/plugins/entry-views
10
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ /* Register shortcodes. */
14
+ add_action( 'init', 'ev_register_shortcodes' );
15
+
16
+ /**
17
+ * Registers shortcodes for the plugin.
18
+ *
19
+ * @since 1.0.0
20
+ * @access public
21
+ * @return void
22
+ */
23
+ function ev_register_shortcodes() {
24
+
25
+ add_shortcode( 'entry-views', 'ev_entry_views_shortcode' );
26
+ }
27
+
28
+ /**
29
+ * Gets the number of views a specific post has.
30
+ *
31
+ * @since 1.0.0
32
+ * @access public
33
+ * @param array $attr Attributes for use in the shortcode.
34
+ * @return string
35
+ */
36
+ function ev_entry_views_shortcode( $attr = '' ) {
37
+
38
+ $defaults = array(
39
+ 'before' => '',
40
+ 'after' => '',
41
+ 'text' => '',
42
+ 'post_id' => get_the_ID()
43
+ );
44
+
45
+ $attr = shortcode_atts( $defaults, $attr, 'entry-views' );
46
+
47
+ return ev_get_post_views( $attr );
48
+ }
inc/template.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Template functions for the plugin for use in WordPress themes.
4
+ *
5
+ * @package EntryViews
6
+ * @version 1.0.0
7
+ * @author Justin Tadlock <justin@justintadlock.com>
8
+ * @copyright Copyright (c) 2010 - 2014, Justin Tadlock
9
+ * @link http://themehybrid.com/plugins/entry-views
10
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ /**
14
+ * Outputs a specific post's view count. This is a wrapper function for ev_get_post_views(). It simply
15
+ * prints the output of that function to the screen.
16
+ *
17
+ * @since 1.0.0
18
+ * @access public
19
+ * @param array $args
20
+ * @return void
21
+ */
22
+ function ev_post_views( $args = array() ) {
23
+ echo ev_get_post_views( $args );
24
+ }
25
+
26
+ /**
27
+ * Template tag for getting a specific post's view count. It will default to the current post in The
28
+ * Loop. To use the 'text' argument, either pass a nooped plural using _n_noop() or a single text string.
29
+ *
30
+ * @since 1.0.0
31
+ * @access public
32
+ * @param array $args
33
+ * @return string
34
+ */
35
+ function ev_get_post_views( $args = array() ) {
36
+
37
+ $defaults = array(
38
+ 'post_id' => get_the_ID(),
39
+ 'before' => '',
40
+ 'after' => '',
41
+ /* Translators: %s is the number of views a post has. */
42
+ 'text' => _n_noop( '%s View', '%s Views', 'entry-views' ),
43
+ 'wrap' => '<span %s>%s</span>'
44
+ );
45
+
46
+ $args = wp_parse_args( $args, $defaults );
47
+
48
+ $views = ev_get_post_view_count( $args['post_id'] );
49
+
50
+ $text = is_array( $args['text'] ) ? translate_nooped_plural( $args['text'], $views ) : $args['text'];
51
+
52
+ $html = sprintf(
53
+ $args['wrap'],
54
+ 'class="entry-views" itemprop="interactionCount" itemscope="itemscope" itemtype="http://schema.org/UserPageVisits"',
55
+ sprintf( $text, $views )
56
+ );
57
+
58
+ return $args['before'] . $html . $args['after'];
59
+ }
inc/widget-entry-views.php ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package EntryViews
4
+ * @version 1.0.0
5
+ * @author Justin Tadlock <justin@justintadlock.com>
6
+ * @copyright Copyright (c) 2010 - 2014, Justin Tadlock
7
+ * @link http://themehybrid.com/plugins/entry-views
8
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9
+ */
10
+
11
+ /**
12
+ * Entry Views widget.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class EV_Widget_Entry_Views extends WP_Widget {
17
+
18
+ /**
19
+ * Default arguments for the widget settings.
20
+ *
21
+ * @since 1.0.0
22
+ * @access public
23
+ * @var array
24
+ */
25
+ public $defaults = array();
26
+
27
+ /**
28
+ * Set up the widget's unique name, ID, class, description, and other options.
29
+ *
30
+ * @since 1.0.0
31
+ * @access public
32
+ * @return void
33
+ */
34
+ function __construct() {
35
+
36
+ /* Set up the widget options. */
37
+ $widget_options = array(
38
+ 'classname' => 'widget-entry-views',
39
+ 'description' => esc_html__( 'Display posts based on their view count.', 'entry-views' )
40
+ );
41
+
42
+ /* Set up the widget control options. */
43
+ $control_options = array(
44
+ 'width' => 200,
45
+ 'height' => 350
46
+ );
47
+
48
+ /* Create the widget. */
49
+ $this->WP_Widget(
50
+ 'ev-entry-views',
51
+ __( 'Entry Views', 'entry-views' ),
52
+ $widget_options,
53
+ $control_options
54
+ );
55
+
56
+ /* Set up defaults. */
57
+ $this->defaults = array(
58
+ 'title' => esc_attr__( 'Views', 'entry-views' ),
59
+ 'posts_per_page' => 10,
60
+ 'post_type' => 'post',
61
+ 'order' => 'DESC',
62
+ 'show_view_count' => true
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Outputs the widget based on the arguments input through the widget controls.
68
+ *
69
+ * @since 1.0.0
70
+ * @access public
71
+ * @param array $sidebar
72
+ * @param array $instance
73
+ * @return void
74
+ */
75
+ function widget( $sidebar, $instance ) {
76
+
77
+ /* Set the $args for wp_get_archives() to the $instance array. */
78
+ $args = wp_parse_args( $instance, $this->defaults );
79
+
80
+ /* Output the sidebar's $before_widget wrapper. */
81
+ echo $sidebar['before_widget'];
82
+
83
+ /* If a title was input by the user, display it. */
84
+ if ( !empty( $args['title'] ) )
85
+ echo $sidebar['before_title'] . apply_filters( 'widget_title', $args['title'], $instance, $this->id_base ) . $sidebar['after_title'];
86
+
87
+ /* Query the most/least viewed posts. */
88
+ $loop = new WP_Query(
89
+ array(
90
+ 'post_type' => $args['post_type'],
91
+ 'posts_per_page' => $args['posts_per_page'],
92
+ 'order' => $args['order'],
93
+ 'orderby' => 'meta_value_num',
94
+ 'ignore_sticky_posts' => true,
95
+ 'meta_key' => ev_get_meta_key()
96
+ )
97
+ );
98
+
99
+ if ( $loop->have_posts() ) : ?>
100
+
101
+ <ul class="ev-entry-views-list">
102
+
103
+ <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
104
+
105
+ <li>
106
+ <?php the_title( '<a href="' . get_permalink() . '">', '</a>' ); ?>
107
+ <?php if ( true == $args['show_view_count'] ) : ?>
108
+ <?php ev_post_views( array( 'text' => '(%s)', 'wrap' => '<span class="entry-view-count">%2$s</span>' ) ); ?>
109
+ <?php endif; ?>
110
+ </li>
111
+
112
+ <?php endwhile; ?>
113
+
114
+ </ul><!-- .ev-entry-views-list -->
115
+
116
+ <?php endif;
117
+
118
+ /* Close the sidebar's widget wrapper. */
119
+ echo $sidebar['after_widget'];
120
+ }
121
+
122
+ /**
123
+ * The update callback for the widget control options. This method is used to sanitize and/or
124
+ * validate the options before saving them into the database.
125
+ *
126
+ * @since 1.0.0
127
+ * @access public
128
+ * @param array $new_instance
129
+ * @param array $old_instance
130
+ * @return array
131
+ */
132
+ function update( $new_instance, $old_instance ) {
133
+
134
+ /* Strip tags. */
135
+ $instance['title'] = strip_tags( $new_instance['title'] );
136
+
137
+ /* Array map sanitize key. */
138
+ $instance['post_type'] = array_map( 'sanitize_key', $new_instance['post_type'] );
139
+
140
+ /* Whitelist options. */
141
+ $order = array( 'ASC', 'DESC' );
142
+
143
+ $instance['order'] = in_array( $new_instance['order'], $order ) ? $new_instance['order'] : 'DESC';
144
+
145
+ /* Integers. */
146
+ $instance['posts_per_page'] = absint( $new_instance['posts_per_page'] );
147
+
148
+ /* Checkboxes. */
149
+ $instance['show_view_count'] = isset( $new_instance['show_view_count'] ) ? 1 : 0;
150
+
151
+ /* Return sanitized options. */
152
+ return $instance;
153
+ }
154
+
155
+ /**
156
+ * Displays the widget control options in the Widgets admin screen.
157
+ *
158
+ * @since 1.0.0
159
+ * @access public
160
+ * @param array $instance
161
+ * @param void
162
+ */
163
+ function form( $instance ) {
164
+
165
+ /* Merge the user-selected arguments with the defaults. */
166
+ $instance = wp_parse_args( (array) $instance, $this->defaults );
167
+
168
+ $post_types = array();
169
+ $_post_types = get_post_types( array( 'public' => true ), 'objects' );
170
+
171
+ foreach ( $_post_types as $_post_type ) {
172
+ if ( post_type_supports( $_post_type->name, 'entry-views' ) )
173
+ $post_types[] = $_post_type;
174
+ }
175
+
176
+ /* Create an array of order options. */
177
+ $order = array(
178
+ 'ASC' => esc_attr__( 'Ascending', 'entry-views' ),
179
+ 'DESC' => esc_attr__( 'Descending', 'entry-views' )
180
+ );
181
+
182
+ ?>
183
+ <p>
184
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'entry-views' ); ?></label>
185
+ <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" placeholder="<?php echo esc_attr( $this->defaults['title'] ); ?>" />
186
+ </p>
187
+ <p>
188
+ <label for="<?php echo $this->get_field_id( 'post_type' ); ?>"><?php _e( 'Post Type:', 'entry-views' ); ?></label>
189
+ <select class="widefat" id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>[]" size="4" multiple="multiple">
190
+ <?php foreach ( $post_types as $post_type ) { ?>
191
+ <option value="<?php echo esc_attr( $post_type->name ); ?>" <?php selected( in_array( $post_type->name, (array)$instance['post_type'] ) ); ?>><?php echo esc_html( $post_type->labels->singular_name ); ?></option>
192
+ <?php } ?>
193
+ </select>
194
+ </p>
195
+ <p>
196
+ <label for="<?php echo $this->get_field_id( 'posts_per_page' ); ?>"><?php _e( 'Limit:', 'entry-views' ); ?></label>
197
+ <input type="number" class="widefat code" size="5" min="1" id="<?php echo $this->get_field_id( 'posts_per_page' ); ?>" name="<?php echo $this->get_field_name( 'posts_per_page' ); ?>" value="<?php echo esc_attr( $instance['posts_per_page'] ); ?>" placeholder="10" />
198
+ </p>
199
+ <p>
200
+ <label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', 'entry-views' ); ?></label>
201
+ <select class="widefat" id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>">
202
+ <?php foreach ( $order as $option_value => $option_label ) { ?>
203
+ <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['order'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
204
+ <?php } ?>
205
+ </select>
206
+ </p>
207
+ <p>
208
+ <label for="<?php echo $this->get_field_id( 'show_view_count' ); ?>">
209
+ <input class="checkbox" type="checkbox" <?php checked( $instance['show_view_count'], true ); ?> id="<?php echo $this->get_field_id( 'show_view_count' ); ?>" name="<?php echo $this->get_field_name( 'show_view_count' ); ?>" /> <?php _e( 'Show view count?', 'entry-views' ); ?></label>
210
+ </p>
211
+ <?php
212
+ }
213
+ }
languages/entry-views.pot ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2014 Entry Views
2
+ # This file is distributed under the same license as the Entry Views package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Entry Views 1.0.0-alpha-1\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/entry-views\n"
7
+ "POT-Creation-Date: 2014-05-18 17:02:46+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+
15
+ #. Translators: %s is the number of views a post has.
16
+
17
+ #: inc/template.php:42
18
+ msgid "%s View"
19
+ msgid_plural "%s Views"
20
+ msgstr[0] ""
21
+ msgstr[1] ""
22
+
23
+ #: inc/widget-entry-views.php:39
24
+ msgid "Display posts based on their view count."
25
+ msgstr ""
26
+
27
+ #: inc/widget-entry-views.php:51
28
+ msgid "Entry Views"
29
+ msgstr ""
30
+
31
+ #: inc/widget-entry-views.php:58
32
+ msgid "Views"
33
+ msgstr ""
34
+
35
+ #: inc/widget-entry-views.php:178
36
+ msgid "Ascending"
37
+ msgstr ""
38
+
39
+ #: inc/widget-entry-views.php:179
40
+ msgid "Descending"
41
+ msgstr ""
42
+
43
+ #: inc/widget-entry-views.php:184
44
+ msgid "Title:"
45
+ msgstr ""
46
+
47
+ #: inc/widget-entry-views.php:188
48
+ msgid "Post Type:"
49
+ msgstr ""
50
+
51
+ #: inc/widget-entry-views.php:196
52
+ msgid "Limit:"
53
+ msgstr ""
54
+
55
+ #: inc/widget-entry-views.php:200
56
+ msgid "Order:"
57
+ msgstr ""
58
+
59
+ #: inc/widget-entry-views.php:209
60
+ msgid "Show view count?"
61
+ msgstr ""
62
+ #. Plugin Name of the plugin/theme
63
+ msgid "Entry Views"
64
+ msgstr ""
65
+
66
+ #. Plugin URI of the plugin/theme
67
+ msgid "http://themehybrid.com/plugins/entry-views"
68
+ msgstr ""
69
+
70
+ #. Description of the plugin/theme
71
+ msgid "A WordPress plugin for tracking the number of post views."
72
+ msgstr ""
73
+
74
+ #. Author of the plugin/theme
75
+ msgid "Justin Tadlock"
76
+ msgstr ""
77
+
78
+ #. Author URI of the plugin/theme
79
+ msgid "http://justintadlock.com"
80
+ msgstr ""
readme.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Entry Views #
2
+
3
+ A WordPress plugin for tracking post/page view statistics.
4
+
5
+ Entry Views keeps track of the number of views a post/page (or any post type) has. It comes handy with a widget for showing the most viewed posts, a shortcode for displaying a post's view count, and handy template tags for use within theme template files.
6
+
7
+ ## Changelog ##
8
+
9
+ ### Version 1.0.0 ###
10
+
11
+ * Everything is new!
readme.txt ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Entry Views ===
2
+
3
+ Contributors: greenshady
4
+ Donate link: http://themehybrid.com/donate
5
+ Tags: ajax, counter, post, posts, statistics, stats, tracking
6
+ Requires at least: 3.8
7
+ Tested up to: 3.9.1
8
+ Stable tag: 1.0.0
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ A WordPress plugin for tracking post/page view statistics.
13
+
14
+ == Description ==
15
+
16
+ Entry Views keeps track of the number of views a post/page (or any post type) has. It comes handy with a widget for showing the most viewed posts, a shortcode for displaying a post's view count, and handy template tags for use within theme template files.
17
+
18
+ ### Professional Support ###
19
+
20
+ If you need professional plugin support from me, the plugin author, you can access the support forums at [Theme Hybrid](http://themehybrid.com/support), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 40,000+ users (and growing).
21
+
22
+ ### Plugin Development ###
23
+
24
+ If you're a plugin author or just a code hobbyist, you can follow the development of this plugin on it's [GitHub repository](https://github.com/justintadlock/entry-views).
25
+
26
+ ### Donations ###
27
+
28
+ Yes, I do accept donations. If you want to buy me a beer or whatever, you can do so from my [donations page](http://themehybrid.com/donate). I appreciate all donations, no matter the size. Further development of this plugin is not contingent on donations, but they are always a nice incentive.
29
+
30
+ == Installation ==
31
+
32
+ 1. Uzip the `entry-views.zip` folder.
33
+ 2. Upload the `entry-views` folder to your `/wp-content/plugins` directory.
34
+ 3. In your WordPress dashboard, head over to the *Plugins* section.
35
+ 4. Activate *Entry Views*.
36
+
37
+ == Frequently Asked Questions ==
38
+
39
+ ### Why was this plugin created? ###
40
+
41
+ The plugin was originally created as a script for use with some of my themes. However, it's not a good idea to package something like this with a theme because it'd stop working when switching between themes. Therefore, the script was ported over into a plugin for everyone to use, regardless of the theme they're using.
42
+
43
+ ### How do I use the plugin? ###
44
+
45
+ As soon as you install and activate the plugin, it'll start tracking post views immediately. From that point, you can use the "Entry Views" widget in one of your theme's sidebars to display the most viewed posts.
46
+
47
+ ### Can I show the view count for each post? ###
48
+
49
+ Yes, you can certainly do this. It will require editing your theme's templates and inserting a simple line of code within The Loop. You'll need to enter the following:
50
+
51
+ <?php if ( function_exists( 'ev_post_views' ) ) ev_post_views(); ?>
52
+
53
+ ### What post types does this plugin support? ###
54
+
55
+ By default, it supports the following post types:
56
+
57
+ * Post
58
+ * Page
59
+ * Media/Attachment
60
+ * Portfolio Item - [Custom Content Portfolio Plugin](http://wordpress.org/plugins/custom-content-portfolio)
61
+ * Restaurant Item - [Restaurant Plugin](http://wordpress.org/plugins/restaurant)
62
+ * Recipe - Upcoming recipe plugin
63
+ * Literature - Upcoming literature/writing plugin
64
+
65
+ ### Will you add support for other post types? ###
66
+
67
+ Yes, I definitely will. If you give me the name of the post type or of the plugin that you use, I will be more than happy to add support for it.
68
+
69
+ ### Can I add support for a custom post type? ###
70
+
71
+ Yes, you can absolutely do this. If you're registering the post type yourself, simply add support for `entry-views` in your `supports` array.
72
+
73
+ If you're adding support for a post type that you're not registering, add the following code to your plugin file or theme's `functions.php`:
74
+
75
+ add_action( 'init', 'my_register_post_type_support' );
76
+
77
+ function my_register_post_type_support() {
78
+ add_post_type_support( 'your_post_type_name', 'entry-views' );
79
+ }
80
+
81
+ ### What features do you plan to add in the future? ###
82
+
83
+ One feature I'd like to add is to the admin area. It'd be neat to show each post's views on the edit posts screen and even allow you to sort the posts by number of views.
84
+
85
+ Other features are really up to you all. If you have a feature request, please don't hesitate to ask.
86
+
87
+ ### Can you help me? ###
88
+
89
+ Unfortunately, I cannot provide free support for this plugin to everyone. I honestly wish I could. My day job requires too much of my time for that, which is how I pay the bills and eat. However, you can sign up for my [support forums](http://themehybrid.com/support) for full support of this plugin, all my other plugins, and all my themes for one price.
90
+
91
+ == Screenshots ==
92
+
93
+ == Changelog ==
94
+
95
+ ### Version 1.0.0 ###
96
+
97
+ * Everything is new!
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file