PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / root-boot / LocaleAndFrontendOptions.php

LocaleAndFrontendOptions.php in 404 Solution trunk, at includes/root-boot/LocaleAndFrontendOptions.php

59 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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