| 1 |
<?php |
| 2 |
|
| 3 |
namespace ISC; |
| 4 |
|
| 5 |
/** |
| 6 |
* Handle user-related attributes |
| 7 |
*/ |
| 8 |
class User { |
| 9 |
/** |
| 10 |
* Check if the current user is WP_User |
| 11 |
* |
| 12 |
* @return bool |
| 13 |
*/ |
| 14 |
public static function is_user(): bool { |
| 15 |
$user = wp_get_current_user(); |
| 16 |
return $user instanceof \WP_User; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Get the current user email address |
| 21 |
* |
| 22 |
* @return string|false email address or false if none is set |
| 23 |
*/ |
| 24 |
public static function get_email() { |
| 25 |
if ( ! self::is_user() ) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
$email = trim( wp_get_current_user()->user_email ); |
| 30 |
|
| 31 |
return is_email( $email ) ? $email : false; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get the current user’s public name |
| 36 |
* |
| 37 |
* @return string display name |
| 38 |
*/ |
| 39 |
public static function get_name(): string { |
| 40 |
if ( ! self::is_user() ) { |
| 41 |
return ''; |
| 42 |
} |
| 43 |
|
| 44 |
return ! empty( wp_get_current_user()->nickname ) ? wp_get_current_user()->nickname : wp_get_current_user()->display_name; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get the current user language |
| 49 |
* |
| 50 |
* @return string |
| 51 |
*/ |
| 52 |
public static function get_user_language(): string { |
| 53 |
return strpos( determine_locale(), 'de_' ) === 0 ? 'de' : 'en'; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Is the backend language in German? |
| 58 |
* |
| 59 |
* @return bool |
| 60 |
*/ |
| 61 |
public static function has_german_backend(): bool { |
| 62 |
return self::get_user_language() === 'de'; |
| 63 |
} |
| 64 |
} |