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