Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Antontokarchuk0302 committed Apr 26, 2020
1 parent c451f5f commit 7b024d5
Showing 5 changed files with 52 additions and 25 deletions.
Empty file modified includes/settings.php
100644 → 100755
Empty file.
19 changes: 19 additions & 0 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

add_action( 'wp', 'wppv_add_custom_shortcode' );
function wppv_add_custom_shortcode() {
/**
* @param $post which is Post id ( Optional )
* @author of shortcode Ronak Vanpariya.
* @desc Get Post Count For the Blog.
*/

function wppv_current_post_view_callback($atts = array() , $content = ''){
$meta_key = 'entry_views';
$view_post_meta = get_post_meta(get_the_ID(), $meta_key, true);
return $view_post_meta;
}
if(!shortcode_exists( 'WPPV-TOTAL-VIEWS' )){
add_shortcode( 'WPPV-TOTAL-VIEWS', 'wppv_current_post_view_callback' );
}
}
Empty file modified index.php
100644 → 100755
Empty file.
17 changes: 16 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ Contributors: vanpariyar, ankitatanti, Brijeshdhanani,
Tags: post views, count wordpress site views, show post views, post view counter, WP Post Views, post view count based on ip
Requires at least: 4.0
Requires PHP: 5.3
Tested up to: 5.3.2
Tested up to: 5.4.0
Stable tag: 1.7.6
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -19,6 +19,15 @@ Wordpress post views counter counts the view of your Built in post type and Cust
* Option to filter views on IP address to get accurate post count.
* Option to select the custom post type.

### How to Get Post Count in Frontend

Use this shortcode.

[WPPV-TOTAL-VIEWS]

### Tutorial

[youtube https://youtu.be/11NH5xOBs68]

== Installation ==

@@ -37,6 +46,10 @@ Wordpress post views counter counts the view of your Built in post type and Cust

== Changelog ==

= 1.2 - 26/04/2020 =
- Enhancement: Fix the Views Count.
- Features: Added The Shortcode For Frontend Users.

= 1.1 - 23/02/2020 =
- Enhancement: Fix the error when WP_DEBUG is true.

@@ -45,3 +58,5 @@ Wordpress post views counter counts the view of your Built in post type and Cust

== Upgrade Notice ==
Please update Your plugin for better performance.


41 changes: 17 additions & 24 deletions wp-post-views.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
* Plugin Name: WP Post Views
* Plugin URI: https://github.com/vanpariyar/wp-post-views
* Description: WP Post Views.
* Version: 1.0
* Version: 1.2
* Requires at least: 5.0
* Requires PHP: 5.0
* Author: Ronak J Vanpariya
@@ -45,6 +45,8 @@

require_once (WP_POST_VIEW_PLUGIN_PATH . '/includes/settings.php');

require_once (WP_POST_VIEW_PLUGIN_PATH . '/includes/shortcodes.php');

register_activation_hook( __FILE__, array('Wp_post_view_settings','wppv_activation_hook') );

/**
@@ -129,36 +131,27 @@ public function counter(){
if(in_array($post->post_type , $selected_type)){
if ( !empty($options['wppv_api_text_field_1']) ) {
$stored_ip_addresses = get_post_meta(get_the_ID(),'view_ip',true);
}

$new_viewed_count = 0;
if($stored_ip_addresses)
{
if(sizeof($stored_ip_addresses))
if($stored_ip_addresses)
{
$current_ip = $this->get_ip_address();
if(!in_array($current_ip, $stored_ip_addresses))
if(count($stored_ip_addresses))
{
$meta_key = 'entry_views';
$view_post_meta = get_post_meta(get_the_ID(), $meta_key, true);
$new_viewed_count = $view_post_meta + 1;
update_post_meta(get_the_ID(), $meta_key, $new_viewed_count);
$stored_ip_addresses[] = $current_ip;
update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses);
$current_ip = $this->get_ip_address();
if(!in_array($current_ip, $stored_ip_addresses))
{
$meta_key = 'entry_views';
$view_post_meta = get_post_meta(get_the_ID(), $meta_key, true);
$new_viewed_count = intval($view_post_meta) + 1;
update_post_meta(get_the_ID(), $meta_key, $new_viewed_count);
$stored_ip_addresses[] = $current_ip;
update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses);
}
}
}
}

else {
} else {
$meta_key = 'entry_views';
$view_post_meta = get_post_meta(get_the_ID(), $meta_key, true);
if( ! is_int($view_post_meta) ){
$view_post_meta = 0;
}
$new_viewed_count = $view_post_meta + 1;
$new_viewed_count = intval($view_post_meta) + 1;
update_post_meta(get_the_ID(), $meta_key, $new_viewed_count);
$ip_arr[] = $this->get_ip_address();
update_post_meta(get_the_ID(),'view_ip',$ip_arr);
}
}

0 comments on commit 7b024d5

Please sign in to comment.