PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.7
Post Views Counter v1.3.7
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 / functions.php
post-views-counter / includes Last commit date
ajax.php 7 years ago columns.php 4 years ago counter.php 4 years ago crawler-detect.php 6 years ago cron.php 6 years ago dashboard.php 4 years ago frontend.php 6 years ago functions.php 4 years ago query.php 6 years ago settings-api.php 4 years ago settings.php 4 years ago update.php 6 years ago widgets.php 4 years ago
functions.php
608 lines
1 <?php
2 /**
3 * Post Views Counter pluggable template functions
4 *
5 * Override any of those functions by copying it to your theme or replace it via plugin
6 *
7 * @author Digital Factory
8 * @package Post Views Counter
9 * @since 1.0.0
10 */
11 // exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) )
13 exit;
14
15 /**
16 * Get post views for a post or array of posts.
17 *
18 * @global $wpdb
19 * @param int|array $post_id
20 * @return int
21 */
22 if ( ! function_exists( 'pvc_get_post_views' ) ) {
23
24 function pvc_get_post_views( $post_id = 0 ) {
25 if ( empty( $post_id ) )
26 $post_id = get_the_ID();
27
28 if ( is_array( $post_id ) )
29 $post_id = implode( ',', array_map( 'intval', $post_id ) );
30 else
31 $post_id = (int) $post_id;
32
33 global $wpdb;
34
35 $query = "SELECT SUM(count) AS views
36 FROM " . $wpdb->prefix . "post_views
37 WHERE id IN (" . $post_id . ") AND type = 4";
38
39 // get cached data
40 $post_views = wp_cache_get( md5( $query ), 'pvc-get_post_views' );
41
42 // cached data not found?
43 if ( $post_views === false ) {
44 $post_views = (int) $wpdb->get_var( $query );
45
46 // set the cache expiration, 5 minutes by default
47 $expire = absint( apply_filters( 'pvc_object_cache_expire', 5 * 60 ) );
48
49 wp_cache_add( md5( $query ), $post_views, 'pvc-get_post_views', $expire );
50 }
51
52 return apply_filters( 'pvc_get_post_views', $post_views, $post_id );
53 }
54
55 }
56
57 /**
58 * Get views query.
59 *
60 * @global $wpdb
61 * @param array $args
62 * @return int|array
63 */
64 if ( ! function_exists( 'pvc_get_views' ) ) {
65
66 function pvc_get_views( $args = array() ) {
67 $range = array();
68 $defaults = array(
69 'fields' => 'views',
70 'post_id' => '',
71 'post_type' => '',
72 'views_query' => array(
73 'year' => '',
74 'month' => '',
75 'week' => '',
76 'day' => '',
77 'after' => '', // string or array
78 'before' => '', // string or array
79 'inclusive' => true
80 )
81 );
82
83 // merge default options with new arguments
84 $args = array_merge( $defaults, $args );
85
86 // check views query
87 if ( ! is_array( $args['views_query'] ) )
88 $args['views_query'] = $defaults['views_query'];
89
90 // merge views query too
91 $args['views_query'] = array_merge( $defaults['views_query'], $args['views_query'] );
92
93 $args = apply_filters( 'pvc_get_views_args', $args );
94
95 // check post types
96 if ( is_array( $args['post_type'] ) && ! empty( $args['post_type'] ) ) {
97 $post_types = array();
98
99 foreach( $args['post_type'] as $post_type ) {
100 $post_types[] = "'" . $post_type . "'";
101 }
102
103 $args['post_type'] = implode( ', ', $post_types );
104 } elseif ( ! is_string( $args['post_type'] ) )
105 $args['post_type'] = $defaults['post_type'];
106 else
107 $args['post_type'] = "'" . $args['post_type'] . "'";
108
109 // check post ids
110 if ( is_array( $args['post_id'] ) && ! empty( $args['post_id'] ) )
111 $args['post_id'] = implode( ', ', array_unique( array_map( 'intval', $args['post_id'] ) ) );
112 else
113 $args['post_id'] = (int) $args['post_id'];
114
115 // check fields
116 if ( ! in_array( $args['fields'], array( 'views', 'date=>views' ), true ) )
117 $args['fields'] = $defaults['fields'];
118
119 $query_chunks = array();
120 $views_query = '';
121
122 // views query after/before parameters work only when fields == views
123 if ( $args['fields'] === 'views' ) {
124 // check views query inclusive
125 if ( ! isset( $args['views_query']['inclusive'] ) ) {
126 $args['views_query']['inclusive'] = $defaults['views_query']['inclusive'];
127 } else
128 $args['views_query']['inclusive'] = (bool) $args['views_query']['inclusive'];
129
130 // check after and before dates
131 foreach ( array( 'after' => '>', 'before' => '<' ) as $date => $type ) {
132 $year_ = null;
133 $month_ = null;
134 $week_ = null;
135 $day_ = null;
136
137 // check views query date
138 if ( ! empty( $args['views_query'][$date] ) ) {
139 // is it a date array?
140 if ( is_array( $args['views_query'][$date] ) ) {
141 // check views query $date date year
142 if ( ! empty( $args['views_query'][$date]['year'] ) )
143 $year_ = str_pad( (int) $args['views_query'][$date]['year'], 4, 0, STR_PAD_LEFT );
144
145 // check views query date month
146 if ( ! empty( $args['views_query'][$date]['month'] ) )
147 $month_ = str_pad( (int) $args['views_query'][$date]['month'], 2, 0, STR_PAD_LEFT );
148
149 // check views query date week
150 if ( ! empty( $args['views_query'][$date]['week'] ) )
151 $week_ = str_pad( (int) $args['views_query'][$date]['week'], 2, 0, STR_PAD_LEFT );
152
153 // check views query date day
154 if ( ! empty( $args['views_query'][$date]['day'] ) )
155 $day_ = str_pad( (int) $args['views_query'][$date]['day'], 2, 0, STR_PAD_LEFT );
156 // is it a date string?
157 } elseif ( is_string( $args['views_query'][$date] ) ) {
158 $time_ = strtotime( $args['views_query'][$date] );
159
160 // valid datetime?
161 if ( $time_ !== false ) {
162 // week does not exists here, string dates are always treated as year + month + day
163 list( $day_, $month_, $year_ ) = explode( ' ', date( "d m Y", $time_ ) );
164 }
165 }
166
167 // valid date?
168 if ( ! ( $year_ === null && $month_ === null && $week_ === null && $day_ === null ) ) {
169 $query_chunks[] = array(
170 'year' => $year_,
171 'month' => $month_,
172 'day' => $day_,
173 'week' => $week_,
174 'type' => $type . ( $args['views_query']['inclusive'] ? '=' : '' )
175 );
176 }
177 }
178 }
179
180 if ( ! empty( $query_chunks ) ) {
181 $valid_dates = true;
182
183 // after and before?
184 if ( count( $query_chunks ) === 2 ) {
185 // before and after dates should be the same
186 foreach ( array( 'year', 'month', 'day', 'week' ) as $date_type ) {
187 if ( ! ( ( $query_chunks[0][$date_type] !== null && $query_chunks[1][$date_type] !== null ) || ( $query_chunks[0][$date_type] === null && $query_chunks[1][$date_type] === null ) ) )
188 $valid_dates = false;
189 }
190 }
191
192 if ( $valid_dates ) {
193 foreach ( $query_chunks as $chunk ) {
194 // year
195 if ( isset( $chunk['year'] ) ) {
196 // year, week
197 if ( isset( $chunk['week'] ) )
198 $views_query .= " AND pvc.type = 1 AND pvc.period " . $chunk['type'] . " '" . $chunk['year'] . $chunk['week'] . "'";
199 // year, month
200 elseif ( isset( $chunk['month'] ) ) {
201 // year, month, day
202 if ( isset( $chunk['day'] ) )
203 $views_query .= " AND pvc.type = 0 AND pvc.period " . $chunk['type'] . " '" . $chunk['year'] . $chunk['month'] . $chunk['day'] . "'";
204 // year, month
205 else
206 $views_query .= " AND pvc.type = 2 AND pvc.period " . $chunk['type'] . " '" . $chunk['year'] . $chunk['month'] . "'";
207 // year
208 } else
209 $views_query .= " AND pvc.type = 3 AND pvc.period " . $chunk['type'] . " '" . $chunk['year'] . "'";
210 // month
211 } elseif ( isset( $chunk['month'] ) ) {
212 // month, day
213 if ( isset( $chunk['day'] ) ) {
214 $views_query .= " AND pvc.type = 0 AND RIGHT( pvc.period, 4 ) " . $chunk['type'] . " '" . $chunk['month'] . $chunk['day'] . "'";
215 // month
216 } else
217 $views_query .= " AND pvc.type = 2 AND RIGHT( pvc.period, 2 ) " . $chunk['type'] . " '" . $chunk['month'] . "'";
218 // week
219 } elseif ( isset( $chunk['week'] ) )
220 $views_query .= " AND pvc.type = 1 AND RIGHT( pvc.period, 2 ) " . $chunk['type'] . " '" . $chunk['week'] . "'";
221 // day
222 elseif ( isset( $chunk['day'] ) )
223 $views_query .= " AND pvc.type = 0 AND RIGHT( pvc.period, 2 ) " . $chunk['type'] . " '" . $chunk['day'] . "'";
224 }
225 }
226 }
227 }
228
229 $special_views_query = ( $views_query !== '' );
230
231 if ( $args['fields'] === 'date=>views' || $views_query === '' ) {
232 // check views query year
233 if ( ! empty( $args['views_query']['year'] ) )
234 $year = str_pad( (int) $args['views_query']['year'], 4, 0, STR_PAD_LEFT );
235
236 // check views query month
237 if ( ! empty( $args['views_query']['month'] ) )
238 $month = str_pad( (int) $args['views_query']['month'], 2, 0, STR_PAD_LEFT );
239
240 // check views query week
241 if ( ! empty( $args['views_query']['week'] ) )
242 $week = str_pad( (int) $args['views_query']['week'], 2, 0, STR_PAD_LEFT );
243
244 // check views query day
245 if ( ! empty( $args['views_query']['day'] ) )
246 $day = str_pad( (int) $args['views_query']['day'], 2, 0, STR_PAD_LEFT );
247
248 // year
249 if ( isset( $year ) ) {
250 // year, week
251 if ( isset( $week ) ) {
252 if ( $args['fields'] === 'date=>views' ) {
253 // create date based on week number
254 $date = new DateTime( $year . 'W' . $week );
255
256 // get monday
257 $monday = $date->format( 'd' );
258
259 // get month of monday
260 $monday_month = $date->format( 'm' );
261
262 // prepare range
263 for( $i = 1; $i <= 6; $i++ ) {
264 $range[(string) ( $date->format( 'Y' ) . $date->format( 'm' ) . $date->format( 'd' ) )] = 0;
265
266 $date->modify( '+1days' );
267 }
268
269 $range[(string) ( $date->format( 'Y' ) . $date->format( 'm' ) . $date->format( 'd' ) )] = 0;
270
271 // get month of sunday
272 $sunday_month = $date->format( 'm' );
273
274 $views_query = " AND pvc.type = 0 AND pvc.period >= '" . $year . $monday_month . $monday . "' AND pvc.period <= '" . $date->format( 'Y' ) . $sunday_month . $date->format( 'd' ) . "'";
275 } else
276 $views_query = " AND pvc.type = 1 AND pvc.period = '" . $year . $week . "'";
277 // year, month
278 } elseif ( isset( $month ) ) {
279 // year, month, day
280 if ( isset( $day ) ) {
281 if ( $args['fields'] === 'date=>views' )
282 // prepare range
283 $range[(string) ( $year . $month . $day )] = 0;
284
285 $views_query = " AND pvc.type = 0 AND pvc.period = '" . $year . $month . $day . "'";
286 // year, month
287 } else {
288 if ( $args['fields'] === 'date=>views' ) {
289 // create date
290 $date = new DateTime( $year . '-' . $month . '-01' );
291
292 // get last day
293 $last = $date->format( 't' );
294
295 // prepare range
296 for( $i = 1; $i <= $last; $i++ ) {
297 $range[(string) ( $year . $month . str_pad( $i, 2, 0, STR_PAD_LEFT ) )] = 0;
298 }
299
300 $views_query = " AND pvc.type = 0 AND pvc.period >= '" . $year . $month . "01' AND pvc.period <= '" . $year . $month . $last . "'";
301 } else
302 $views_query = " AND pvc.type = 2 AND pvc.period = '" . $year . $month . "'";
303 }
304 // year
305 } else {
306 if ( $args['fields'] === 'date=>views' ) {
307 // prepare range
308 for( $i = 1; $i <= 12; $i++ ) {
309 $range[(string) ( $year . str_pad( $i, 2, 0, STR_PAD_LEFT ) )] = 0;
310 }
311
312 // create date
313 $date = new DateTime( $year . '-12-01' );
314
315 $views_query = " AND pvc.type = 2 AND pvc.period >= '" . $year . "01' AND pvc.period <= '" . $year . "12'";
316 } else
317 $views_query = " AND pvc.type = 3 AND pvc.period = '" . $year . "'";
318 }
319 // month
320 } elseif ( isset( $month ) ) {
321 // month, day
322 if ( isset( $day ) ) {
323 $views_query = " AND pvc.type = 0 AND RIGHT( pvc.period, 4 ) = '" . $month . $day . "'";
324 // month
325 } else {
326 $views_query = " AND pvc.type = 2 AND RIGHT( pvc.period, 2 ) = '" . $month . "'";
327 }
328 // week
329 } elseif ( isset( $week ) ) {
330 $views_query = " AND pvc.type = 1 AND RIGHT( pvc.period, 2 ) = '" . $week . "'";
331 // day
332 } elseif ( isset( $day ) ) {
333 $views_query = " AND pvc.type = 0 AND RIGHT( pvc.period, 2 ) = '" . $day . "'";
334 }
335 }
336
337 global $wpdb;
338
339 $query = "SELECT " . ( $args['fields'] === 'date=>views' ? 'pvc.period, ' : '' ) . "SUM( IFNULL( pvc.count, 0 ) ) AS post_views
340 FROM " . $wpdb->prefix . "posts wpp
341 LEFT JOIN " . $wpdb->prefix . "post_views pvc ON pvc.id = wpp.ID" . ( $views_query !== '' ? ' ' . $views_query : ' AND pvc.type = 4' ) . ( ! empty( $args['post_id'] ) ? ' AND pvc.id IN (' . $args['post_id'] . ')' : '' ) . "
342 " . ( $args['post_type'] !== '' ? "WHERE wpp.post_type IN (" . $args['post_type'] . ")" : '' ) . "
343 " . ( $views_query !== '' && $special_views_query === false ? 'GROUP BY pvc.period' : '' ) . "
344 HAVING post_views > 0";
345
346 // get cached data
347 $post_views = wp_cache_get( md5( $query ), 'pvc-get_views' );
348
349 // cached data not found?
350 if ( $post_views === false ) {
351 if ( $args['fields'] === 'date=>views' && ! empty( $range ) ) {
352 $results = $wpdb->get_results( $query );
353
354 if ( ! empty( $results ) ) {
355 foreach( $results as $row ) {
356 $range[$row->period] = (int) $row->post_views;
357 }
358 }
359
360 $post_views = $range;
361 } else
362 $post_views = (int) $wpdb->get_var( $query );
363
364 // set the cache expiration, 5 minutes by default
365 $expire = absint( apply_filters( 'pvc_object_cache_expire', 300 ) );
366
367 wp_cache_add( md5( $query ), $post_views, 'pvc-get_views', $expire );
368 }
369
370 return apply_filters( 'pvc_get_views', $post_views );
371 }
372
373 }
374
375 /**
376 * Display post views for a given post.
377 *
378 * @param int|array $post_id
379 * @param bool $display
380 * @return mixed
381 */
382 if ( ! function_exists( 'pvc_post_views' ) ) {
383
384 function pvc_post_views( $post_id = 0, $echo = true ) {
385 // get all data
386 $post_id = (int) ( empty( $post_id ) ? get_the_ID() : $post_id );
387 $options = Post_Views_Counter()->options['display'];
388 $views = pvc_get_post_views( $post_id );
389
390 // prepare display
391 $label = apply_filters( 'pvc_post_views_label', ( function_exists( 'icl_t' ) ? icl_t( 'Post Views Counter', 'Post Views Label', $options['label'] ) : $options['label'] ), $post_id );
392
393 // get icon class
394 $icon_class = ( $options['icon_class'] !== '' ? esc_attr( $options['icon_class'] ) : '' );
395
396 // add dashicons class if needed
397 $icon_class = strpos( $icon_class, 'dashicons ' ) === 0 ? $icon_class : 'dashicons ' . $icon_class;
398
399 // prepare icon output
400 $icon = apply_filters( 'pvc_post_views_icon', '<span class="post-views-icon ' . $icon_class . '"></span>', $post_id );
401
402 $html = apply_filters(
403 'pvc_post_views_html',
404 '<div class="post-views post-' . $post_id . ' entry-meta">
405 ' . ( $options['display_style']['icon'] && $icon_class !== '' ? $icon : '' ) . '
406 ' . ( $options['display_style']['text'] && $label !== '' ? '<span class="post-views-label">' . esc_html( $label ) . '</span>' : '' ) . '
407 <span class="post-views-count">' . number_format_i18n( $views ) . '</span>
408 </div>',
409 $post_id,
410 $views,
411 $label,
412 $icon
413 );
414
415 if ( $echo )
416 echo $html;
417 else
418 return $html;
419 }
420
421 }
422
423 /**
424 * Get most viewed posts.
425 *
426 * @param array $args
427 * @return array
428 */
429 if ( ! function_exists( 'pvc_get_most_viewed_posts' ) ) {
430
431 function pvc_get_most_viewed_posts( $args = array() ) {
432 $args = array_merge(
433 array(
434 'posts_per_page' => 10,
435 'order' => 'desc',
436 'post_type' => 'post'
437 ), $args
438 );
439
440 $args = apply_filters( 'pvc_get_most_viewed_posts_args', $args );
441
442 // force to use filters
443 $args['suppress_filters'] = false;
444
445 // force to use post views as order
446 $args['orderby'] = 'post_views';
447
448 // force to get all fields
449 $args['fields'] = '';
450
451 return apply_filters( 'pvc_get_most_viewed_posts', get_posts( $args ), $args );
452 }
453
454 }
455
456 /**
457 * Display a list of most viewed posts.
458 *
459 * @param array $post_id
460 * @param bool $display
461 * @return mixed
462 */
463 if ( ! function_exists( 'pvc_most_viewed_posts' ) ) {
464
465 function pvc_most_viewed_posts( $args = array(), $display = true ) {
466 $defaults = array(
467 'number_of_posts' => 5,
468 'post_type' => array( 'post' ),
469 'order' => 'desc',
470 'thumbnail_size' => 'thumbnail',
471 'list_type' => 'unordered',
472 'show_post_views' => true,
473 'show_post_thumbnail' => false,
474 'show_post_author' => false,
475 'show_post_excerpt' => false,
476 'no_posts_message' => __( 'No Posts', 'post-views-counter' ),
477 'item_before' => '',
478 'item_after' => ''
479 );
480
481 $args = apply_filters( 'pvc_most_viewed_posts_args', wp_parse_args( $args, $defaults ) );
482
483 $args['show_post_views'] = (bool) $args['show_post_views'];
484 $args['show_post_thumbnail'] = (bool) $args['show_post_thumbnail'];
485 $args['show_post_author'] = (bool) $args['show_post_author'];
486 $args['show_post_excerpt'] = (bool) $args['show_post_excerpt'];
487
488 $posts = pvc_get_most_viewed_posts(
489 array(
490 'posts_per_page' => ( isset( $args['number_of_posts'] ) ? (int) $args['number_of_posts'] : $defaults['number_of_posts'] ),
491 'order' => ( isset( $args['order'] ) ? $args['order'] : $defaults['order'] ),
492 'post_type' => ( isset( $args['post_type'] ) ? $args['post_type'] : $defaults['post_type'] )
493 )
494 );
495
496 if ( ! empty( $posts ) ) {
497 $html = ( $args['list_type'] === 'unordered' ? '<ul>' : '<ol>' );
498
499 foreach ( $posts as $post ) {
500 setup_postdata( $post );
501
502 $html .= '
503 <li>';
504
505 $html .= apply_filters( 'pvc_most_viewed_posts_item_before', $args['item_before'], $post );
506
507 if ( $args['show_post_thumbnail'] && has_post_thumbnail( $post->ID ) ) {
508 $html .= '
509 <span class="post-thumbnail">
510 ' . get_the_post_thumbnail( $post->ID, $args['thumbnail_size'] ) . '
511 </span>';
512 }
513
514 $html .= '
515 <a class="post-title" href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a>' . ( $args['show_post_author'] ? ' <span class="author">(' . get_the_author_meta( 'display_name', $post->post_author ) . ')</span> ' : '' ) . ( $args['show_post_views'] ? ' <span class="count">(' . number_format_i18n( pvc_get_post_views( $post->ID ) ) . ')</span>' : '' );
516
517 $excerpt = '';
518
519 if ( $args['show_post_excerpt'] ) {
520 if ( empty( $post->post_excerpt ) )
521 $text = $post->post_content;
522 else
523 $text = $post->post_excerpt;
524
525 if ( ! empty( $text ) )
526 $excerpt = wp_trim_words( str_replace( ']]>', ']]&gt;', strip_shortcodes( $text ) ), apply_filters( 'excerpt_length', 55 ), apply_filters( 'excerpt_more', ' ' . '[&hellip;]' ) );
527 }
528
529 if ( ! empty( $excerpt ) )
530 $html .= '
531
532 <div class="post-excerpt">' . esc_html( $excerpt ) . '</div>';
533
534 $html .= apply_filters( 'pvc_most_viewed_posts_item_after', $args['item_after'], $post );
535
536 $html .= '
537 </li>';
538 }
539
540 wp_reset_postdata();
541
542 $html .= ( $args['list_type'] === 'unordered' ? '</ul>' : '</ol>' );
543 } else
544 $html = $args['no_posts_message'];
545
546 $html = apply_filters( 'pvc_most_viewed_posts_html', $html, $args );
547
548 if ( $display )
549 echo $html;
550 else
551 return $html;
552 }
553
554 }
555
556 /**
557 * Update total number of post views for a post.
558 *
559 * @global $wpdb
560 * @param int $post_id Post ID
561 * @param int $post_views Number of post views
562 * @return true|string True on success, error string otherwise
563 */
564 function pvc_update_post_views( $post_id = 0, $post_views = 0 ) {
565 // cast post ID
566 $post_id = (int) $post_id;
567
568 // get post
569 $post = get_post( $post_id );
570
571 // check if post exists
572 if ( empty( $post ) )
573 return false;
574
575 // cast number of views
576 $post_views = (int) $post_views;
577 $post_views = $post_views < 0 ? 0 : $post_views;
578
579 global $wpdb;
580
581 // chnage post views?
582 $post_views = apply_filters( 'pvc_update_post_views_count', $post_views, $post_id );
583
584 // insert or update db post views count
585 $wpdb->query( $wpdb->prepare( "INSERT INTO " . $wpdb->prefix . "post_views (id, type, period, count) VALUES (%d, %d, %s, %d) ON DUPLICATE KEY UPDATE count = %d", $post_id, 4, 'total', $post_views, $post_views ) );
586
587 // query fails only if it returns false
588 return apply_filters( 'pvc_update_post_views', $post_id );
589 }
590
591 /**
592 * View post manually function.
593 *
594 * @since 1.2.0
595 * @param int $post_id
596 * @return bool
597 */
598 function pvc_view_post( $post_id = 0 ) {
599 $post_id = (int) ( empty( $post_id ) ? get_the_ID() : $post_id );
600
601 if ( ! $post_id )
602 return false;
603
604 Post_Views_Counter()->counter->check_post( $post_id );
605
606 return true;
607 }
608