| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Get telephone number with prefix |
| 5 |
* |
| 6 |
* @param $telephone |
| 7 |
* @return string |
| 8 |
*/ |
| 9 |
function spoki_get_formatted_telephone($telephone): string |
| 10 |
{ |
| 11 |
// By default IT prefix |
| 12 |
$default_prefix = '+39'; |
| 13 |
$response = $telephone; |
| 14 |
if (isset($telephone) && $telephone != '' && substr($response, 0, 1) != '+') { |
| 15 |
$response = $default_prefix . $response; |
| 16 |
} |
| 17 |
return $response; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Load last .po and .pot |
| 22 |
* |
| 23 |
* @hook init |
| 24 |
* @return $loaded |
| 25 |
*/ |
| 26 |
function spoki_update_po_file() |
| 27 |
{ |
| 28 |
$domain = SPOKI_PLUGIN_NAME; |
| 29 |
$locale = apply_filters('plugin_locale', get_locale(), $domain); |
| 30 |
$loaded = load_textdomain($domain, SPOKI_DIR . 'languages/' . $domain . '-' . $locale . '.mo'); |
| 31 |
if ($loaded) { |
| 32 |
return $loaded; |
| 33 |
} else { |
| 34 |
return load_plugin_textdomain($domain, false, SPOKI_DIR . 'languages/'); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Check if a string starts with another |
| 40 |
* |
| 41 |
* @param $string |
| 42 |
* @param $startString |
| 43 |
* @return bool |
| 44 |
*/ |
| 45 |
function spoki_starts_with($string, $startString) |
| 46 |
{ |
| 47 |
$len = strlen($startString); |
| 48 |
return (substr($string, 0, $len) === $startString); |
| 49 |
} |