false, 'apiKey' => null, 'appId' => null, 'authDomain' => null, 'messagingSenderId' => null, 'projectId' => null, 'storageBucket' => null, ]; add_option( 'acb_firebase_authentication_value', json_encode($acb_default_options) ); // Create database tables on plugin activation add_action('init', [$this, 'create_tables']); } /** * Create database tables * * @since 1.0.0 */ public function create_tables() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); // Messages table $table_messages = $wpdb->prefix . 'acb_messages'; $sql_messages = "CREATE TABLE $table_messages ( id mediumint(9) NOT NULL AUTO_INCREMENT, user_id varchar(255) NOT NULL, user_name varchar(255) NOT NULL, user_email varchar(255) NOT NULL, user_avatar varchar(500) DEFAULT '', message text NOT NULL, message_type varchar(50) DEFAULT 'text', file_url varchar(500) DEFAULT '', created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY created_at (created_at) ) $charset_collate;"; // Users table for session management $table_users = $wpdb->prefix . 'acb_users'; $sql_users = "CREATE TABLE $table_users ( id mediumint(9) NOT NULL AUTO_INCREMENT, firebase_uid varchar(255) NOT NULL, user_name varchar(255) NOT NULL, user_email varchar(255) NOT NULL, user_avatar varchar(500) DEFAULT '', auth_provider varchar(50) DEFAULT 'email', is_admin tinyint(1) DEFAULT 0, last_seen datetime DEFAULT CURRENT_TIMESTAMP, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY firebase_uid (firebase_uid), KEY user_email (user_email) ) $charset_collate;"; // Settings table $table_settings = $wpdb->prefix . 'acb_settings'; $sql_settings = "CREATE TABLE $table_settings ( id mediumint(9) NOT NULL AUTO_INCREMENT, setting_key varchar(255) NOT NULL, setting_value longtext NOT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY setting_key (setting_key) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql_messages); dbDelta($sql_users); dbDelta($sql_settings); // Insert default settings $this->insert_default_settings(); } /** * Insert default settings * * @since 1.0.0 */ private function insert_default_settings() { global $wpdb; $table_settings = $wpdb->prefix . 'acb_settings'; $default_settings = [ 'chat_enabled' => '1', 'frontend_enabled' => '1', 'admin_enabled' => '1', 'position' => 'right', 'primary_color' => '#5A5EB9', 'welcome_message' => 'Hello! How can I help you today?', 'max_message_length' => '1000', 'file_upload_enabled' => '1', 'max_file_size' => '5242880', // 5MB 'allowed_file_types' => 'jpg,jpeg,png,gif,pdf,doc,docx' ]; foreach ($default_settings as $key => $value) { $wpdb->replace( $table_settings, [ 'setting_key' => $key, 'setting_value' => $value ], ['%s', '%s'] ); } } }