| 1 |
<?php |
| 2 |
|
| 3 |
class LSD_API extends LSD_Base |
| 4 |
{ |
| 5 |
public string $namespace = 'listdom/v1'; |
| 6 |
public string $version = '1'; |
| 7 |
protected LSD_db $db; |
| 8 |
|
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
// DB Library |
| 12 |
$this->db = new LSD_db(); |
| 13 |
} |
| 14 |
|
| 15 |
public function init() |
| 16 |
{ |
| 17 |
add_action('rest_api_init', [$this, 'language'], 20); |
| 18 |
|
| 19 |
$routes = new LSD_API_Routes(); |
| 20 |
$routes->init(); |
| 21 |
} |
| 22 |
|
| 23 |
public function language() |
| 24 |
{ |
| 25 |
// Requested Language |
| 26 |
$locale = null; |
| 27 |
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && is_string($_SERVER['HTTP_ACCEPT_LANGUAGE'])) |
| 28 |
{ |
| 29 |
$locale = sanitize_text_field(wp_unslash($_SERVER['HTTP_ACCEPT_LANGUAGE'])); |
| 30 |
} |
| 31 |
|
| 32 |
// No Locale |
| 33 |
if (!$locale) return; |
| 34 |
|
| 35 |
// Switch the Language |
| 36 |
LSD_i18n::set($locale); |
| 37 |
} |
| 38 |
} |
| 39 |
|