Plugin Directory

Changeset 3444913


Ignore:
Timestamp:
01/22/2026 02:42:29 PM (2 months ago)
Author:
monant
Message:

v2.1.3 - Auto-create statistics table if missing

Location:
mametech-chat-button/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mametech-chat-button/trunk/mametech-chat-button.php

    r3444879 r3444913  
    44 * Plugin URI: https://www.mametech.com/mametech-chat-button
    55 * Description: Plugin completo con widget, shortcode, orari, numeri multipli, statistiche e temi per chat flottante
    6  * Version: 2.1.2
     6 * Version: 2.1.3
    77 * Author: Mario Merola
    88 * Author URI: https://www.mametech.com
     
    1919
    2020// Definizione delle costanti del plugin
    21 define('MAMETECH_CB_VERSION', '2.1.2');
     21define('MAMETECH_CB_VERSION', '2.1.3');
    2222define('MAMETECH_CB_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2323define('MAMETECH_CB_PLUGIN_URL', plugin_dir_url(__FILE__));
     
    124124   
    125125    /**
     126     * Assicura che la tabella statistiche esista
     127     */
     128    private function ensure_stats_table_exists() {
     129        global $wpdb;
     130        $table_name = $wpdb->prefix . 'mametech_cb_stats';
     131       
     132        // Controlla se la tabella esiste
     133        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     134        $table_exists = $wpdb->get_var(
     135            $wpdb->prepare(
     136                "SHOW TABLES LIKE %s",
     137                $table_name
     138            )
     139        );
     140       
     141        // Se non esiste, creala
     142        if ($table_exists !== $table_name) {
     143            $charset_collate = $wpdb->get_charset_collate();
     144           
     145            $sql = "CREATE TABLE $table_name (
     146                id bigint(20) NOT NULL AUTO_INCREMENT,
     147                button_id varchar(50) NOT NULL DEFAULT 'main',
     148                click_date datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
     149                user_ip varchar(45),
     150                user_agent text,
     151                page_url text,
     152                PRIMARY KEY  (id),
     153                KEY button_id (button_id),
     154                KEY click_date (click_date)
     155            ) $charset_collate;";
     156           
     157            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     158            dbDelta($sql);
     159        }
     160    }
     161   
     162    /**
    126163     * Aggiungi menu admin
    127164     */
     
    412449        }
    413450       
    414         return ($current_time >= $day_schedule['start'] && $current_time <= $day_schedule['end']);
     451        return ($current_time >= $day_schedule['start'] && $current_time < $day_schedule['end']);
    415452    }
    416453   
     
    715752        global $wpdb;
    716753       
     754        // Assicurati che la tabella esista
     755        $this->ensure_stats_table_exists();
     756       
    717757        // Ottieni periodo selezionato
    718758        // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     
    10711111       
    10721112        global $wpdb;
     1113       
     1114        // Assicurati che la tabella esista
     1115        $this->ensure_stats_table_exists();
     1116       
    10731117        $table_stats = $wpdb->prefix . 'mametech_cb_stats';
    10741118       
  • mametech-chat-button/trunk/readme.txt

    r3444879 r3444913  
    44Requires at least: 5.0
    55Tested up to: 6.9
    6 Stable tag: 2.1.2
     6Stable tag: 2.1.3
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    111111
    112112== Changelog ==
     113
     114= 2.1.3 =
     115* Fixed: Statistics table auto-creation - now creates automatically if missing
     116* Fixed: Statistics now work even if activation hook failed
     117* Improved: Auto-repair mechanism for stats table
     118* Added: ensure_stats_table_exists() function for reliability
    113119
    114120= 2.1.2 =
Note: See TracChangeset for help on using the changeset viewer.