Changeset 2801279
- Timestamp:
- 10/19/2022 01:44:25 PM (22 months ago)
- Location:
- wp-post-views
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
wp-post-views/tags/1.11/includes/settings.php
r2757872 r2801279 19 19 $options = array( 20 20 'wppv_api_text_field_0' => '1' , 21 'wppv_api_text_field_1' => ' 1',21 'wppv_api_text_field_1' => '', 22 22 'wppv_api_post_checkbox_1'=> array( 23 23 'post' => 'post', -
wp-post-views/tags/1.11/includes/shortcodes.php
r2646429 r2801279 5 5 /** 6 6 * @param $post which is Post id ( Optional ) 7 * @author of shortcodeRonak Vanpariya.7 * @author Ronak Vanpariya. 8 8 * @desc Get Post Count For the Blog. 9 9 */ … … 14 14 return $view_post_meta; 15 15 } 16 if( !shortcode_exists( 'WPPV-TOTAL-VIEWS' )){16 if(shortcode_exists( 'WPPV-TOTAL-VIEWS' )){ 17 17 add_shortcode( 'WPPV-TOTAL-VIEWS', 'wppv_current_post_view_callback' ); 18 } 18 } 19 20 /** 21 * @param $post_type which is post ( Default ) 22 * @author Ronak Vanpariya. 23 * @desc Get Post Total Count For the Blog. 24 */ 25 26 function wppv_current_post_view_per_post_type_callback($atts = array() , $content = ''){ 27 global $wp_post_views; 28 29 $parsed = wp_parse_args( 30 $atts, 31 array( 32 'post_type' => 'post', 33 ) 34 ); 35 return $wp_post_views->get_total_views( $parsed['post_type'] ); 36 } 37 if( ! shortcode_exists( 'WPPV-TOTAL-VIEWS-PER-POST-TYPE' )){ 38 add_shortcode( 'WPPV-TOTAL-VIEWS-PER-POST-TYPE', 'wppv_current_post_view_per_post_type_callback' ); 39 } 19 40 } -
wp-post-views/tags/1.11/readme.txt
r2757872 r2801279 1 1 === Wp Post Views - Wordpress Post views counter === 2 Contributors: vanpariyar, ankitatanti, Brijeshdhanani, 2 Contributors: vanpariyar, ankitatanti, Brijeshdhanani, 3 3 Tags: post views, count wordpress site views, show post views, post view counter, WP Post Views, post view count based on ip 4 4 Requires at least: 5.0 5 5 Requires PHP: 5.3 6 Tested up to: 6. 07 Stable tag: 1.1 06 Tested up to: 6. 7 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 25 25 26 26 [WPPV-TOTAL-VIEWS] 27 28 29 30 31 27 32 28 33 ### Tutorial … … 50 55 51 56 == Changelog == 57 58 59 60 52 61 53 62 = 1.10 - 18/07/2022 = -
wp-post-views/tags/1.11/wp-post-views.php
r2757872 r2801279 12 12 * Plugin URI: https://github.com/vanpariyar/wp-post-views 13 13 * Description: WP Post Views. 14 * Version: 1. 914 * Version: 1. 15 15 * Requires at least: 5.0 16 16 * Requires PHP: 5.3 … … 21 21 * License: GPL v2 or later 22 22 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 23 24 WP Post Views is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version.25 26 WP Post Views is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.27 28 You should have received a copy of the GNU General Public License along with WP Post Views. If not, see * License URI: http://www.gnu.org/licenses/gpl-2.0.txt29 30 23 */ 31 24 … … 38 31 /* Plugin Constants */ 39 32 if (!defined('WP_POST_VIEW_URL')) { 40 33 define('WP_POST_VIEW_URL', plugin_dir_url(__FILE__)); 41 34 } 42 35 43 36 if (!defined('WP_POST_VIEW_PLUGIN_PATH')) { 44 37 define('WP_POST_VIEW_PLUGIN_PATH', plugin_dir_path(__FILE__)); 45 38 } 46 39 … … 54 47 * MAIN CLASS 55 48 */ 56 class WP_Post_Views 57 { 58 function __construct() 59 { 60 add_action( 'init', array( $this ,'load_textdomain' ) ); 61 add_action( 'wp_head', array( $this , 'counter'), 10, 1 ); 62 add_filter( 'manage_posts_columns', array( $this,'wppv_posts_column_views') ); 63 add_filter( 'manage_pages_columns', array( $this,'wppv_posts_column_views') ); 64 add_action( 'manage_posts_custom_column', array( $this,'wppv_posts_custom_column_views') ); 65 add_action( 'manage_pages_custom_column', array( $this,'wppv_posts_custom_column_views') ); 49 class WP_Post_Views { 50 /** 51 * Initialize the plugin. 52 * 53 * @return void 54 */ 55 public function __construct() { 56 57 $this->options = get_option( 'wppv_api_settings' ); 58 $this->meta_key = 'entry_views'; 59 $this->total_views_transient_key = 'wppv_post_total_views'; 60 $this->total_views_transient_expiration = 1 * MINUTE_IN_SECONDS; 61 62 add_action( 'init', array( $this, 'load_textdomain' ) ); 63 add_action( 'wp_head', array( $this, 'counter' ), 10, 1 ); 64 add_filter( 'manage_posts_columns', array( $this, 'wppv_posts_column_views' ) ); 65 add_filter( 'manage_pages_columns', array( $this, 'wppv_posts_column_views' ) ); 66 add_action( 'manage_posts_custom_column', array( $this, 'wppv_posts_custom_column_views' ) ); 67 add_action( 'manage_pages_custom_column', array( $this, 'wppv_posts_custom_column_views' ) ); 66 68 Wp_post_view_settings::settings_init(); 67 69 } … … 73 75 public function wppv_posts_column_views( $columns ) { 74 76 75 $options = get_option( 'wppv_api_settings' ); 76 77 //$options['wppv_api_text_field_0']; 78 if ( !empty($options['wppv_api_text_field_0']) ) { 77 if ( ! empty( $this->options['wppv_api_text_field_0'] ) ) { 79 78 $columns['post_views'] = 'Views'; 80 79 } 81 80 return $columns; 82 81 } 83 82 84 83 public function wppv_posts_custom_column_views( $column ) { 85 $ options = get_option( 'wppv_api_settings' );86 if ( !empty($ options['wppv_api_text_field_0']) ) {84 $options = get_option( 'wppv_api_settings' ); 85 if ( !empty($options['wppv_api_text_field_0']) ) { 87 86 if ( $column === 'post_views') { 88 87 $view_post_meta = get_post_meta(get_the_ID(), 'entry_views', true); 89 88 echo $view_post_meta; 90 91 } 92 89 } 90 } 91 93 92 } 94 93 95 94 public function get_ip_address() 96 95 { 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 96 // check for shared internet/ISP IP 97 if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP'])) 98 return $_SERVER['HTTP_CLIENT_IP']; 99 // check for IPs passing through proxies 100 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 101 // check if multiple ips exist in var 102 $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); 103 foreach ($iplist as $ip) { 104 if ($this->validate_ip($ip)) 105 return $ip; 106 } 107 } 108 if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED'])) 109 return $_SERVER['HTTP_X_FORWARDED']; 110 if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) 111 return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; 112 if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) 113 return $_SERVER['HTTP_FORWARDED_FOR']; 114 if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED'])) 115 return $_SERVER['HTTP_FORWARDED']; 116 // return unreliable ip since all else failed 117 return $_SERVER['REMOTE_ADDR']; 119 118 } 120 119 121 120 public function validate_ip($ip) { 122 if (filter_var($ip, FILTER_VALIDATE_IP, 123 FILTER_FLAG_IPV4 | 124 FILTER_FLAG_IPV6 | 125 FILTER_FLAG_NO_PRIV_RANGE | 126 FILTER_FLAG_NO_RES_RANGE) === false) 127 return false; 128 return true; 121 if ( 122 filter_var( $ip, 123 FILTER_VALIDATE_IP, 124 FILTER_FLAG_IPV4 | 125 FILTER_FLAG_IPV6 | 126 FILTER_FLAG_NO_PRIV_RANGE | 127 FILTER_FLAG_NO_RES_RANGE 128 ) === false 129 ) { 130 return false; 131 } 132 return true; 129 133 } 130 134 … … 132 136 global $post; 133 137 $stored_ip_addresses = 0; 134 $options = get_option( 'wppv_api_settings' );135 138 $selected_type = array(); 136 isset($ options['wppv_api_post_checkbox_1']) ? $selected_type = $options['wppv_api_post_checkbox_1'] : '';139 isset($options['wppv_api_post_checkbox_1'] : ''; 137 140 138 141 if( is_object($post) && in_array($post->post_type , $selected_type)){ 139 if ( !empty($ options['wppv_api_text_field_1']) ) {142 if ( !empty($options['wppv_api_text_field_1']) ) { 140 143 $stored_ip_addresses = get_post_meta(get_the_ID(),'view_ip',true); 141 144 … … 145 148 if(!in_array($current_ip, $stored_ip_addresses)) 146 149 { 147 $meta_key = 'entry_views'; 148 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 150 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 149 151 $new_viewed_count = intval($view_post_meta) + 1; 150 update_post_meta(get_the_ID(), $ meta_key, $new_viewed_count);152 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 151 153 $stored_ip_addresses[] = $current_ip; 152 154 update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); … … 154 156 } else { 155 157 $stored_ip_addresses = array(); 156 $meta_key = 'entry_views'; 157 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 158 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 158 159 $new_viewed_count = intval($view_post_meta) + 1; 159 update_post_meta(get_the_ID(), $ meta_key, $new_viewed_count);160 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 160 161 $stored_ip_addresses[] = $current_ip; 161 162 update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); 162 163 } 163 164 } else { 164 $meta_key = 'entry_views'; 165 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 165 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 166 166 $new_viewed_count = intval($view_post_meta) + 1; 167 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 168 } 169 } 170 171 } 172 173 } 174 175 $post_view = new WP_Post_Views(); 167 update_post_meta(get_the_ID(), $this->meta_key, $new_viewed_count); 168 } 169 } 170 171 } 172 173 private function count_total_view( $post_type = 'post' ) { 174 $total = 0; 175 176 if( $total = get_transient( $this->total_views_transient_key.$post_type ) ) { 177 return $total; 178 } 179 180 $arguments = array( 181 'post_type' => $post_type, 182 'posts_per_page' => '-1', 183 'status' => 'publish', 184 ); 185 $total_count_query = new WP_Query( $arguments ); 186 187 if( $total_count_query->have_posts() ){ 188 while( $total_count_query->have_posts() ) { 189 $total_count_query->the_post(); 190 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 191 $total += $view_post_meta; 192 } 193 } 194 set_transient( $this->total_views_transient_key.$post_type, $total, $this->total_views_transient_expiration ); 195 196 return $total; 197 } 198 199 public function get_total_views( $post_type = 'post' ) { 200 return $this->count_total_view($post_type); 201 } 202 203 } 204 205 global $wp_post_views; 206 207 $wp_post_views = new WP_Post_Views(); -
wp-post-views/trunk/includes/settings.php
r2757872 r2801279 19 19 $options = array( 20 20 'wppv_api_text_field_0' => '1' , 21 'wppv_api_text_field_1' => ' 1',21 'wppv_api_text_field_1' => '', 22 22 'wppv_api_post_checkbox_1'=> array( 23 23 'post' => 'post', -
wp-post-views/trunk/includes/shortcodes.php
r2646429 r2801279 5 5 /** 6 6 * @param $post which is Post id ( Optional ) 7 * @author of shortcodeRonak Vanpariya.7 * @author Ronak Vanpariya. 8 8 * @desc Get Post Count For the Blog. 9 9 */ … … 14 14 return $view_post_meta; 15 15 } 16 if( !shortcode_exists( 'WPPV-TOTAL-VIEWS' )){16 if(shortcode_exists( 'WPPV-TOTAL-VIEWS' )){ 17 17 add_shortcode( 'WPPV-TOTAL-VIEWS', 'wppv_current_post_view_callback' ); 18 } 18 } 19 20 /** 21 * @param $post_type which is post ( Default ) 22 * @author Ronak Vanpariya. 23 * @desc Get Post Total Count For the Blog. 24 */ 25 26 function wppv_current_post_view_per_post_type_callback($atts = array() , $content = ''){ 27 global $wp_post_views; 28 29 $parsed = wp_parse_args( 30 $atts, 31 array( 32 'post_type' => 'post', 33 ) 34 ); 35 return $wp_post_views->get_total_views( $parsed['post_type'] ); 36 } 37 if( ! shortcode_exists( 'WPPV-TOTAL-VIEWS-PER-POST-TYPE' )){ 38 add_shortcode( 'WPPV-TOTAL-VIEWS-PER-POST-TYPE', 'wppv_current_post_view_per_post_type_callback' ); 39 } 19 40 } -
wp-post-views/trunk/readme.txt
r2757872 r2801279 1 1 === Wp Post Views - Wordpress Post views counter === 2 Contributors: vanpariyar, ankitatanti, Brijeshdhanani, 2 Contributors: vanpariyar, ankitatanti, Brijeshdhanani, 3 3 Tags: post views, count wordpress site views, show post views, post view counter, WP Post Views, post view count based on ip 4 4 Requires at least: 5.0 5 5 Requires PHP: 5.3 6 Tested up to: 6. 07 Stable tag: 1.1 06 Tested up to: 6. 7 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 25 25 26 26 [WPPV-TOTAL-VIEWS] 27 28 29 30 31 27 32 28 33 ### Tutorial … … 50 55 51 56 == Changelog == 57 58 59 60 52 61 53 62 = 1.10 - 18/07/2022 = -
wp-post-views/trunk/wp-post-views.php
r2757872 r2801279 12 12 * Plugin URI: https://github.com/vanpariyar/wp-post-views 13 13 * Description: WP Post Views. 14 * Version: 1. 914 * Version: 1. 15 15 * Requires at least: 5.0 16 16 * Requires PHP: 5.3 … … 21 21 * License: GPL v2 or later 22 22 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 23 24 WP Post Views is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version.25 26 WP Post Views is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.27 28 You should have received a copy of the GNU General Public License along with WP Post Views. If not, see * License URI: http://www.gnu.org/licenses/gpl-2.0.txt29 30 23 */ 31 24 … … 38 31 /* Plugin Constants */ 39 32 if (!defined('WP_POST_VIEW_URL')) { 40 33 define('WP_POST_VIEW_URL', plugin_dir_url(__FILE__)); 41 34 } 42 35 43 36 if (!defined('WP_POST_VIEW_PLUGIN_PATH')) { 44 37 define('WP_POST_VIEW_PLUGIN_PATH', plugin_dir_path(__FILE__)); 45 38 } 46 39 … … 54 47 * MAIN CLASS 55 48 */ 56 class WP_Post_Views 57 { 58 function __construct() 59 { 60 add_action( 'init', array( $this ,'load_textdomain' ) ); 61 add_action( 'wp_head', array( $this , 'counter'), 10, 1 ); 62 add_filter( 'manage_posts_columns', array( $this,'wppv_posts_column_views') ); 63 add_filter( 'manage_pages_columns', array( $this,'wppv_posts_column_views') ); 64 add_action( 'manage_posts_custom_column', array( $this,'wppv_posts_custom_column_views') ); 65 add_action( 'manage_pages_custom_column', array( $this,'wppv_posts_custom_column_views') ); 49 class WP_Post_Views { 50 /** 51 * Initialize the plugin. 52 * 53 * @return void 54 */ 55 public function __construct() { 56 57 $this->options = get_option( 'wppv_api_settings' ); 58 $this->meta_key = 'entry_views'; 59 $this->total_views_transient_key = 'wppv_post_total_views'; 60 $this->total_views_transient_expiration = 1 * MINUTE_IN_SECONDS; 61 62 add_action( 'init', array( $this, 'load_textdomain' ) ); 63 add_action( 'wp_head', array( $this, 'counter' ), 10, 1 ); 64 add_filter( 'manage_posts_columns', array( $this, 'wppv_posts_column_views' ) ); 65 add_filter( 'manage_pages_columns', array( $this, 'wppv_posts_column_views' ) ); 66 add_action( 'manage_posts_custom_column', array( $this, 'wppv_posts_custom_column_views' ) ); 67 add_action( 'manage_pages_custom_column', array( $this, 'wppv_posts_custom_column_views' ) ); 66 68 Wp_post_view_settings::settings_init(); 67 69 } … … 73 75 public function wppv_posts_column_views( $columns ) { 74 76 75 $options = get_option( 'wppv_api_settings' ); 76 77 //$options['wppv_api_text_field_0']; 78 if ( !empty($options['wppv_api_text_field_0']) ) { 77 if ( ! empty( $this->options['wppv_api_text_field_0'] ) ) { 79 78 $columns['post_views'] = 'Views'; 80 79 } 81 80 return $columns; 82 81 } 83 82 84 83 public function wppv_posts_custom_column_views( $column ) { 85 $ options = get_option( 'wppv_api_settings' );86 if ( !empty($ options['wppv_api_text_field_0']) ) {84 $options = get_option( 'wppv_api_settings' ); 85 if ( !empty($options['wppv_api_text_field_0']) ) { 87 86 if ( $column === 'post_views') { 88 87 $view_post_meta = get_post_meta(get_the_ID(), 'entry_views', true); 89 88 echo $view_post_meta; 90 91 } 92 89 } 90 } 91 93 92 } 94 93 95 94 public function get_ip_address() 96 95 { 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 96 // check for shared internet/ISP IP 97 if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_CLIENT_IP'])) 98 return $_SERVER['HTTP_CLIENT_IP']; 99 // check for IPs passing through proxies 100 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 101 // check if multiple ips exist in var 102 $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); 103 foreach ($iplist as $ip) { 104 if ($this->validate_ip($ip)) 105 return $ip; 106 } 107 } 108 if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED'])) 109 return $_SERVER['HTTP_X_FORWARDED']; 110 if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) 111 return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; 112 if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) 113 return $_SERVER['HTTP_FORWARDED_FOR']; 114 if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED'])) 115 return $_SERVER['HTTP_FORWARDED']; 116 // return unreliable ip since all else failed 117 return $_SERVER['REMOTE_ADDR']; 119 118 } 120 119 121 120 public function validate_ip($ip) { 122 if (filter_var($ip, FILTER_VALIDATE_IP, 123 FILTER_FLAG_IPV4 | 124 FILTER_FLAG_IPV6 | 125 FILTER_FLAG_NO_PRIV_RANGE | 126 FILTER_FLAG_NO_RES_RANGE) === false) 127 return false; 128 return true; 121 if ( 122 filter_var( $ip, 123 FILTER_VALIDATE_IP, 124 FILTER_FLAG_IPV4 | 125 FILTER_FLAG_IPV6 | 126 FILTER_FLAG_NO_PRIV_RANGE | 127 FILTER_FLAG_NO_RES_RANGE 128 ) === false 129 ) { 130 return false; 131 } 132 return true; 129 133 } 130 134 … … 132 136 global $post; 133 137 $stored_ip_addresses = 0; 134 $options = get_option( 'wppv_api_settings' );135 138 $selected_type = array(); 136 isset($ options['wppv_api_post_checkbox_1']) ? $selected_type = $options['wppv_api_post_checkbox_1'] : '';139 isset($options['wppv_api_post_checkbox_1'] : ''; 137 140 138 141 if( is_object($post) && in_array($post->post_type , $selected_type)){ 139 if ( !empty($ options['wppv_api_text_field_1']) ) {142 if ( !empty($options['wppv_api_text_field_1']) ) { 140 143 $stored_ip_addresses = get_post_meta(get_the_ID(),'view_ip',true); 141 144 … … 145 148 if(!in_array($current_ip, $stored_ip_addresses)) 146 149 { 147 $meta_key = 'entry_views'; 148 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 150 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 149 151 $new_viewed_count = intval($view_post_meta) + 1; 150 update_post_meta(get_the_ID(), $ meta_key, $new_viewed_count);152 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 151 153 $stored_ip_addresses[] = $current_ip; 152 154 update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); … … 154 156 } else { 155 157 $stored_ip_addresses = array(); 156 $meta_key = 'entry_views'; 157 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 158 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 158 159 $new_viewed_count = intval($view_post_meta) + 1; 159 update_post_meta(get_the_ID(), $ meta_key, $new_viewed_count);160 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 160 161 $stored_ip_addresses[] = $current_ip; 161 162 update_post_meta(get_the_ID(),'view_ip',$stored_ip_addresses); 162 163 } 163 164 } else { 164 $meta_key = 'entry_views'; 165 $view_post_meta = get_post_meta(get_the_ID(), $meta_key, true); 165 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 166 166 $new_viewed_count = intval($view_post_meta) + 1; 167 update_post_meta(get_the_ID(), $meta_key, $new_viewed_count); 168 } 169 } 170 171 } 172 173 } 174 175 $post_view = new WP_Post_Views(); 167 update_post_meta(get_the_ID(), $this->meta_key, $new_viewed_count); 168 } 169 } 170 171 } 172 173 private function count_total_view( $post_type = 'post' ) { 174 $total = 0; 175 176 if( $total = get_transient( $this->total_views_transient_key.$post_type ) ) { 177 return $total; 178 } 179 180 $arguments = array( 181 'post_type' => $post_type, 182 'posts_per_page' => '-1', 183 'status' => 'publish', 184 ); 185 $total_count_query = new WP_Query( $arguments ); 186 187 if( $total_count_query->have_posts() ){ 188 while( $total_count_query->have_posts() ) { 189 $total_count_query->the_post(); 190 $view_post_meta = get_post_meta(get_the_ID(), $this->meta_key, true); 191 $total += $view_post_meta; 192 } 193 } 194 set_transient( $this->total_views_transient_key.$post_type, $total, $this->total_views_transient_expiration ); 195 196 return $total; 197 } 198 199 public function get_total_views( $post_type = 'post' ) { 200 return $this->count_total_view($post_type); 201 } 202 203 } 204 205 global $wp_post_views; 206 207 $wp_post_views = new WP_Post_Views();
Note: See TracChangeset
for help on using the changeset viewer.