Changeset 3362814
- Timestamp:
- 09/16/2025 11:01:54 PM (5 months ago)
- Location:
- mwr-hit-counter/trunk
- Files:
-
- 2 edited
-
README.txt (modified) (1 diff)
-
index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
mwr-hit-counter/trunk/README.txt
r2115135 r3362814 1 === MWR HitCounter === 1 === MWR Hit Counter === 2 Contributors: scriptsworks 3 Author: Daniel Martín Ochoa 2 4 Author URI: https://miwebrentable.com 3 Author: Daniel Martín Ochoa 4 Contributors: scriptsworks 5 Donate link: https://www.paypal.me/miwebrentable 5 6 Tags: hit counter, page counter, page visit, wordpress page view, page view count, post view count, easy counter, counter, single counter 6 Donate link: https://www.paypal.me/miwebrentable 7 Requires at least: 4.4.14 8 Tested up to: 5.2.2 9 Requires PHP: 7.0 10 Stable tag: 1.0.0 7 Requires at least: 5.0 8 Tested up to: 6.8.2 9 Requires PHP: 7.4 10 Stable tag: 1.1.0 11 11 License: GPLv2 or later 12 License URI: http ://www.gnu.org/licenses/gpl-2.0.html12 License URI: https://www.gnu.org/licenses/gpl-2.0.html 13 13 14 14 == Description == 15 15 16 - This plugin allows you to add a visitor 'text-plain' counter on your website easily. 17 - No IP tracking control, this plugin use cookie tracking. 16 MWR Hit Counter is a simple and lightweight text-based counter for your website. 17 It uses a single database table and a cookie to count unique visitors over 30 days. 18 No IP tracking, no bloated features — just a clean counter you can display anywhere. 18 19 19 20 == Installation == 21 20 22 1. Upload the plugin files to the `/wp-content/plugins/mwr-hit-counter` directory, or install the plugin through the WordPress plugins screen directly. 21 23 2. Activate the plugin through the 'Plugins' screen in WordPress. 22 3. Open your theme and look for the eg. : "footer.php" where will to insert the counter. 23 Where "start=500" will begin counting, this values can be from 0 to n positives values. 24 4. Or use the "shortcode" [mwrcounter start=500] into entries or pages. 24 3. Add the shortcode where you want the counter to appear. 25 25 26 = Template code is =26 = Examples = 27 27 28 <code><?php echo do_shortcode( '[mwrcounter start=500]' ); ?></code> 28 Template code (in PHP): 29 <code> 30 <?php echo do_shortcode( '[mwrcounter start=500]' ); ?> 31 </code> 29 32 30 = Post code is = 31 32 <code>[mwrcounter start=500]</code> 33 Post/Page code: 34 <code> 35 [mwrcounter start=500] 36 </code> 33 37 34 38 == Frequently Asked Questions == 35 = In which WordPress version this Plugin is compatible? =36 39 37 It is compatible from 4.4.14 to 5.2.2 WordPress version. 40 = Which WordPress versions are supported? = 41 Tested with WordPress 6.8.2 and should work with any version from 5.0+. 38 42 39 = When I refresh o revisit my web the counter doesn't nothing. = 43 = Why does the counter not increase on page refresh? = 44 This plugin uses a cookie (valid for 30 days) to prevent counting the same user repeatedly. 40 45 41 It's normal because this counter do use the cookie tracking for doesn't recount the visit. 42 43 = Cookie expiration time? = 44 45 30 days left. 46 = Can I change the starting value? = 47 Yes, use the `start` attribute in the shortcode: `[mwrcounter start=100]`. 46 48 47 49 == Screenshots == 48 1. The screenshot corresponds to shortcode insert screenshot-1.png 50 51 1. Shortcode usage example (screenshot-1.png) 49 52 50 53 == Changelog == 54 55 = 1.1.0 = 56 * Updated for compatibility with WordPress 6.8.2 57 * Improved database table creation using `dbDelta()` with primary key 58 * Added safety checks for PHP 8+ 59 * Secure cookie parameters for better compatibility 60 * Code cleanup and better escaping for database operations 61 51 62 = 0.1 = 52 * Initial release .63 * Initial release 53 64 54 65 == Upgrade Notice == 55 = 0.1 =56 Added plugin support57 66 67 = 1.1.0 = 68 This update improves security, fixes compatibility with the latest WordPress and PHP versions, and ensures reliable counting. 69 -
mwr-hit-counter/trunk/index.php
r2113762 r3362814 2 2 /** 3 3 * Plugin Name: MWR Hit Counter 4 * Description: Simple hit counter for your website .5 * Version: 1. 0.04 * Description: Simple hit counter for your website with shortcode [mwrcounter start="0"]. 5 * Version: 1.1.0 6 6 * Author: Daniel M. Ochoa 7 7 * Author URI: https://miwebrentable.com 8 * Requires at least: 5.0 9 * Tested up to: 6.8.2 10 * Requires PHP: 7.4 8 11 */ 9 10 12 11 13 /** 12 * If this file is called directly, abort.14 * Exit if accessed directly. 13 15 */ 14 15 if ( ! defined( 'WPINC' ) ) { 16 die; 16 if ( ! defined( 'ABSPATH' ) ) { 17 exit; 17 18 } 18 19 19 require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' ); 20 21 function mwr_counter( $content ) { 22 23 global $wpdb; 24 $p = shortcode_atts( array ( 25 'start' => '0' 26 ), $content ); 27 28 $tableName = $wpdb->prefix . "mwr_counter"; 29 $myrows = $wpdb->get_results ( "SELECT ID, counter FROM $tableName WHERE ID='0'" ); 30 31 if ( !isset ( $_COOKIE['mwrcounter'] ) ) 32 { 33 $count = $myrows[0]->counter + 1; 34 $wpdb->update ( $tableName, array ( 35 'counter' => $count 36 ), array ( 37 'ID' => 0 38 ) ); 39 40 } 41 else 42 { 43 $count = $myrows[0]->counter; 44 } 45 46 return $content = $count+$p['start']; 47 } 48 /** 49 * start counter shortcode. 50 */ 51 52 add_shortcode( 'mwrcounter', 'mwr_counter' ); 53 54 function setting_mwr_counter_cookie() { 55 setcookie( 'mwrcounter', '1', time() + ( 86400 * 30 ), "/" ); 56 } 20 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 57 21 58 22 /** 59 * set cookie first time to 30 days. 23 * Shortcode to display hit counter. 24 * 25 * Usage: [mwrcounter start="100"] 60 26 */ 61 62 add_action( 'init', 'setting_mwr_counter_cookie' );27 function mwr_counter_shortcode( $atts ) { 28 global $wpdb; 63 29 64 function delete_mwr_counter_table() { 30 $atts = shortcode_atts( array( 31 'start' => 0, 32 ), $atts, 'mwrcounter' ); 65 33 66 global $wpdb; 67 $tableName = $wpdb->prefix . "mwr_counter"; 68 $sql = "DROP TABLE IF EXISTS $tableName"; 69 $wpdb->query($sql); 34 $table_name = $wpdb->prefix . 'mwr_counter'; 35 $myrows = $wpdb->get_results( "SELECT counter FROM $table_name WHERE ID = 0" ); 70 36 71 } 37 // Si la tabla está vacía, inicializamos manualmente 38 $count = isset( $myrows[0]->counter ) ? intval( $myrows[0]->counter ) : 0; 72 39 73 function create_mwr_counter_table() { 40 if ( ! isset( $_COOKIE['mwrcounter'] ) ) { 41 $count++; 42 $wpdb->update( 43 $table_name, 44 array( 'counter' => $count ), 45 array( 'ID' => 0 ), 46 array( '%d' ), 47 array( '%d' ) 48 ); 49 } 74 50 75 global $wpdb; 76 $tableName = $wpdb->prefix . "mwr_counter"; 77 78 $created = dbDelta ( "CREATE TABLE IF NOT EXISTS $tableName ( 79 `ID` bigint(20) NOT NULL DEFAULT '0', 80 `counter` int(9) NOT NULL DEFAULT '0')" ); 81 82 $wpdb->insert ( $tableName, array( 83 'ID' => '0', 84 'counter' => '0' 85 )); 86 87 } 88 51 return $count + intval( $atts['start'] ); 52 } 53 add_shortcode( 'mwrcounter', 'mwr_counter_shortcode' ); 54 89 55 /** 90 * activate and deactivate hook.56 * Set a cookie to avoid recounting within 30 days. 91 57 */ 92 93 register_activation_hook( __FILE__, 'create_mwr_counter_table' ); 94 register_deactivation_hook( __FILE__, 'delete_mwr_counter_table' ); 58 function mwr_set_counter_cookie() { 59 if ( ! isset( $_COOKIE['mwrcounter'] ) ) { 60 setcookie( 'mwrcounter', '1', time() + ( 86400 * 30 ), COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true ); 61 } 62 } 63 add_action( 'init', 'mwr_set_counter_cookie' ); 95 64 65 /** 66 * Create database table on plugin activation. 67 */ 68 function mwr_create_counter_table() { 69 global $wpdb; 70 $table_name = $wpdb->prefix . 'mwr_counter'; 96 71 72 $charset_collate = $wpdb->get_charset_collate(); 73 74 $sql = "CREATE TABLE $table_name ( 75 ID bigint(20) NOT NULL DEFAULT 0, 76 counter int(11) NOT NULL DEFAULT 0, 77 PRIMARY KEY (ID) 78 ) $charset_collate;"; 79 80 dbDelta( $sql ); 81 82 // Insert row if not exists 83 $exists = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name WHERE ID = 0" ); 84 if ( ! $exists ) { 85 $wpdb->insert( $table_name, array( 86 'ID' => 0, 87 'counter' => 0 88 ), array( '%d', '%d' ) ); 89 } 90 } 91 register_activation_hook( __FILE__, 'mwr_create_counter_table' ); 92 93 /** 94 * Drop table on plugin deactivation (optional). 95 */ 96 function mwr_delete_counter_table() { 97 global $wpdb; 98 $table_name = $wpdb->prefix . 'mwr_counter'; 99 $wpdb->query( "DROP TABLE IF EXISTS $table_name" ); 100 } 101 register_deactivation_hook( __FILE__, 'mwr_delete_counter_table' );
Note: See TracChangeset
for help on using the changeset viewer.