| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Locale override filter and frontend option helpers. |
| 8 |
* |
| 9 |
* abj404_override_plugin_locale() lets a user run the plugin UI in a language |
| 10 |
* different from the site/user locale. abj404_is_redirect_all_requests_enabled() |
| 11 |
* is a small testable parser for the redirect_all_requests setting. |
| 12 |
* |
| 13 |
* The add_filter('plugin_locale', ...) registration stays in 404-solution.php; |
| 14 |
* this file only defines the functions. |
| 15 |
*/ |
| 16 |
// allow-no-test-found: boot-time global helpers wired via add_filter in 404-solution.php; no same-named unit file. abj404_is_redirect_all_requests_enabled (the option parser) is exercised in LoaderLazyLoadTest. |
| 17 |
|
| 18 |
if (!function_exists('abj404_is_redirect_all_requests_enabled')) { |
| 19 |
/** |
| 20 |
* Small helper for testability and to keep option-parsing logic consistent. |
| 21 |
* |
| 22 |
* @param mixed $options Value returned by get_option('abj404_settings') |
| 23 |
* @return bool |
| 24 |
*/ |
| 25 |
function abj404_is_redirect_all_requests_enabled($options) { |
| 26 |
return is_array($options) && |
| 27 |
array_key_exists('redirect_all_requests', $options) && |
| 28 |
(string)$options['redirect_all_requests'] === '1'; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Override the locale for this plugin if user has configured a language override. |
| 34 |
* This allows users to use a different language for the 404 Solution plugin |
| 35 |
* than their WordPress site language or user language preference. |
| 36 |
* |
| 37 |
* @param string $locale The current locale. |
| 38 |
* @param string $domain The text domain. |
| 39 |
* @return string The locale to use for translation loading. |
| 40 |
*/ |
| 41 |
if (!function_exists('abj404_override_plugin_locale')) { |
| 42 |
/** |
| 43 |
* @param string $locale |
| 44 |
* @param string $domain |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
function abj404_override_plugin_locale($locale, $domain) { |
| 48 |
// Only override for our plugin's text domain. |
| 49 |
// Use the value cached in $GLOBALS at plugin boot to avoid a redundant get_option() call. |
| 50 |
if ($domain === '404-solution') { |
| 51 |
$override = isset($GLOBALS['abj404_plugin_language_override']) && is_string($GLOBALS['abj404_plugin_language_override']) ? $GLOBALS['abj404_plugin_language_override'] : ''; |
| 52 |
if ($override !== '') { |
| 53 |
return $override; |
| 54 |
} |
| 55 |
} |
| 56 |
return $locale; |
| 57 |
} |
| 58 |
} |
| 59 |
|