'Youjeeb', 'askbot_language' => 'fr', 'askbot_sound_enabled' => '1', 'askbot_auto_open_delay' => '0', 'askbot_bottom_offset' => '24', 'askbot_show_credit' => '0', ); foreach ( $defaults as $key => $value ) { if ( false === get_option( $key ) ) { update_option( $key, $value ); } } askbot_install_tables(); if ( ! wp_next_scheduled( 'askbot_daily_reindex_event' ) ) { wp_schedule_event( time(), 'daily', 'askbot_daily_reindex_event' ); } } // Mise à jour des réglages enregistrés par les versions précédentes. add_action( 'plugins_loaded', 'askbot_upgrade_settings' ); function askbot_upgrade_settings() { $stored = (string) get_option( 'askbot_settings_version', '' ); if ( version_compare( $stored, '2.1.3', '>=' ) ) { return; } // Jusqu'à la 2.1.2, le message de bienvenue était rangé par langue : on // reprend celui de la langue choisie dans le réglage unique. $language = (string) get_option( 'askbot_language', 'fr' ); $legacy = get_option( 'askbot_welcome_messages', array() ); if ( is_array( $legacy ) && ! empty( $legacy[ $language ] ) ) { update_option( 'askbot_welcome_message', (string) $legacy[ $language ] ); } update_option( 'askbot_settings_version', ASKBOT_VERSION ); } register_deactivation_hook( __FILE__, 'askbot_deactivate' ); function askbot_deactivate() { wp_clear_scheduled_hook( 'askbot_daily_reindex_event' ); } // Crée / met à jour la table des embeddings. Appelée à l'activation, puis // uniquement quand la version du schéma change (plus à chaque chargement de page). function askbot_install_tables() { global $wpdb; $table = $wpdb->prefix . 'askbot_embeddings'; $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( id bigint(20) NOT NULL AUTO_INCREMENT, post_id varchar(40) NOT NULL, doc_type varchar(10) NOT NULL, doc_title text NOT NULL, chunk_index int NOT NULL, chunk_text mediumtext NOT NULL, embedding longtext NOT NULL, updated_at datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY post_id (post_id) ) {$charset};"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); update_option( 'askbot_db_version', ASKBOT_DB_VERSION ); } add_action( 'plugins_loaded', 'askbot_maybe_upgrade' ); function askbot_maybe_upgrade() { if ( get_option( 'askbot_db_version' ) !== ASKBOT_DB_VERSION ) { askbot_install_tables(); } } // Filet de sécurité : garantit que le cron est planifié même si le plugin a été // mis à jour par simple remplacement de fichiers (sans réactivation). add_action( 'init', 'askbot_ensure_reindex_cron_scheduled' ); function askbot_ensure_reindex_cron_scheduled() { if ( ! wp_next_scheduled( 'askbot_daily_reindex_event' ) ) { wp_schedule_event( time(), 'daily', 'askbot_daily_reindex_event' ); } }