| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
class MxChat_User { |
| 7 |
|
| 8 |
// Function to get user identifier (username, email, or session ID) |
| 9 |
public static function mxchat_get_user_identifier() { |
| 10 |
if (is_user_logged_in()) { |
| 11 |
$current_user = wp_get_current_user(); |
| 12 |
//error_log('Current User: ' . print_r($current_user, true)); |
| 13 |
return $current_user->user_login; // Use username as identifier |
| 14 |
} else { |
| 15 |
//error_log('User is not logged in. Using IP as identifier.'); |
| 16 |
return sanitize_text_field($_SERVER['REMOTE_ADDR']); // Use IP address as fallback |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
// Function to get user email |
| 21 |
public static function mxchat_get_user_email() { |
| 22 |
if (is_user_logged_in()) { |
| 23 |
$current_user = wp_get_current_user(); |
| 24 |
return $current_user->user_email; |
| 25 |
} |
| 26 |
return null; // No email if not logged in |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
|