function check_create_new_wallet($user_id) { global $wpdb; $wallet_table_name = get_wallet_table_name(); $points_initial_bonus_table_name = get_points_initial_bonus_table_name(); $flag = $wpdb->get_var("SELECT COUNT(*) FROM {$wallet_table_name} WHERE user_id = {$user_id}"); if ($flag === '0') { $currency_qty = $wpdb->get_var("SELECT quantity FROM {$points_initial_bonus_table_name} WHERE id = 1"); $wpdb->insert($wallet_table_name, array('user_id' => $user_id, 'available_currency' => $currency_qty), array('%d', '%d')); } }
function build_wallet_sql() { $wallet_table = get_wallet_table_name(); $sql = "CREATE TABLE {$wallet_table} (\n `id` int(10) NOT NULL AUTO_INCREMENT,\n `user_id` bigint(20) unsigned NOT NULL,\n `available_currency` int(11) NOT NULL,\n PRIMARY KEY(`id`),\n FOREIGN KEY (`user_id`) REFERENCES wp_users(`ID`)\n );"; return $sql; }