Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- Plugin Name: Rics Simple Page Stats
- Description: Simple plugin to count and show a total number hits (Unique visitors or page-views) to individual Pages and Posts without using any third party code. Based on the great plugin "srs-simple-hits-counter".
- Author: Rics
- Version: 0.1
- Original Author: Atif N
- Original Author URI: http://sandyrig.com
- Use it as you wish!
- */
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
- // Start Session
- add_action('init', 'rics_start_session', 1);
- function rics_start_session() {
- if(!session_id()) {
- session_start();
- }
- }
- // UPDATE COUNTER
- add_action('wp_head','rics_simple_hits_counter');
- function rics_simple_hits_counter(){
- $url = home_url(add_query_arg(array()));
- $id = url_to_postid($url);
- if( !isset( $_SESSION["rics_counter_increased_$id"] ) || ( isset( $_SESSION["rics_counter_increased_$id"] ) && $_SESSION["rics_counter_increased_$id"] != 'yes' ) ) {
- $rics_visitors = intval( get_option("rics_visitors_count_$id") );
- update_option("rics_visitors_count_$id", $rics_visitors+1);
- $_SESSION["rics_counter_increased_$id"] = 'yes';
- }
- $rics_pageViews = intval( get_option("rics_pageViews_count_$id") );
- update_option("rics_pageViews_count_$id", $rics_pageViews+1);
- }
- // ADD THE "FRONT END" TO EVERY PAGE
- add_filter( 'the_content', 'rics_simple_stats_panel' );
- function rics_simple_stats_panel( $content ) {
- if ( isset($_GET["stats"]) ) {
- $url = home_url(add_query_arg(array()));
- $id = url_to_postid($url);
- $html = '<div id="rics_hidden_stats"><strong class="rics_stats_title">ESTATÍSTICAS DE ACESSO</strong><br>';
- $html .= "Visitantes únicos: " . intval(get_option("rics_visitors_count_$id"));
- $html .= "<br>";
- $html .= "Visualizações: " . intval(get_option("rics_pageViews_count_$id"));
- $html .= '</div>';
- $content = $content . $html;
- }
- return $content;
- }
- // ADD STYLES
- add_action('wp_enqueue_scripts','rics_load_plugin_css');
- function rics_load_plugin_css(){
- wp_enqueue_style( 'rics-styles', plugins_url( 'rics-styles.css' , __FILE__ ) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement