| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WP_Syntex\Polylang\Options\Business; |
| 7 |
|
| 8 |
use WP_Error; |
| 9 |
use WP_Syntex\Polylang\Options\Primitive\Abstract_Boolean; |
| 10 |
use WP_Syntex\Polylang\Options\Options; |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Class defining the "Detect browser language" boolean option. |
| 16 |
* /!\ Sanitization depends on `force_lang`: this option must be set AFTER `force_lang`. |
| 17 |
* |
| 18 |
* @since 3.7 |
| 19 |
*/ |
| 20 |
class Browser extends Abstract_Boolean { |
| 21 |
/** |
| 22 |
* Returns option key. |
| 23 |
* |
| 24 |
* @since 3.7 |
| 25 |
* |
| 26 |
* @return string |
| 27 |
* |
| 28 |
* @phpstan-return 'browser' |
| 29 |
*/ |
| 30 |
public static function key(): string { |
| 31 |
return 'browser'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Sanitizes option's value. |
| 36 |
* Can populate the `$errors` property with blocking and non-blocking errors: in case of non-blocking errors, |
| 37 |
* the value is sanitized and can be stored. |
| 38 |
* |
| 39 |
* @since 3.7 |
| 40 |
* |
| 41 |
* @param bool $value Value to sanitize. |
| 42 |
* @param Options $options All options. |
| 43 |
* @return bool|WP_Error The sanitized value. An instance of `WP_Error` in case of blocking error. |
| 44 |
*/ |
| 45 |
protected function sanitize( $value, Options $options ) { |
| 46 |
if ( 3 === $options->get( 'force_lang' ) && ! class_exists( 'PLL_Xdata_Domain', true ) ) { |
| 47 |
// Cannot share cookies between domains without Polylang Pro. |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
/** @var bool|WP_Error */ |
| 52 |
$value = parent::sanitize( $value, $options ); |
| 53 |
return $value; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Returns the description used in the JSON schema. |
| 58 |
* |
| 59 |
* @since 3.7 |
| 60 |
* |
| 61 |
* @return string |
| 62 |
*/ |
| 63 |
protected function get_description(): string { |
| 64 |
return sprintf( |
| 65 |
/* translators: %1$s and %2$s are "true/false" values. */ |
| 66 |
__( 'Detect preferred browser language on front page: %1$s to detect, %2$s to not detect.', 'polylang' ), |
| 67 |
'`true`', |
| 68 |
'`false`' |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|