| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Polylang |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace WP_Syntex\Polylang\Options\Business; |
| 7 |
|
| 8 |
use WP_Syntex\Polylang\Options\Abstract_Option; |
| 9 |
use WP_Syntex\Polylang\Options\Options; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class defining the "Determine how the current language is defined" option. |
| 15 |
* |
| 16 |
* @since 3.7 |
| 17 |
*/ |
| 18 |
class Force_Lang extends Abstract_Option { |
| 19 |
/** |
| 20 |
* Returns option key. |
| 21 |
* |
| 22 |
* @since 3.7 |
| 23 |
* |
| 24 |
* @return string |
| 25 |
* |
| 26 |
* @phpstan-return 'force_lang' |
| 27 |
*/ |
| 28 |
public static function key(): string { |
| 29 |
return 'force_lang'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Adds information to the site health info array. |
| 34 |
* |
| 35 |
* @since 3.8 |
| 36 |
* |
| 37 |
* @param Options $options An instance of the Options class providing additional configuration. |
| 38 |
* |
| 39 |
* @return array The updated site health information. |
| 40 |
*/ |
| 41 |
public function get_site_health_info( Options $options ): array { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 42 |
switch ( $this->get() ) { |
| 43 |
case '0': |
| 44 |
$value = '0: ' . __( 'The language is set from content', 'polylang' ); |
| 45 |
break; |
| 46 |
case '1': |
| 47 |
$value = '1: ' . __( 'The language is set from the directory name in pretty permalinks', 'polylang' ); |
| 48 |
break; |
| 49 |
case '2': |
| 50 |
$value = '2: ' . __( 'The language is set from the subdomain name in pretty permalinks', 'polylang' ); |
| 51 |
break; |
| 52 |
case '3': |
| 53 |
$value = '3: ' . __( 'The language is set from different domains', 'polylang' ); |
| 54 |
break; |
| 55 |
default: |
| 56 |
$value = ''; |
| 57 |
break; |
| 58 |
} |
| 59 |
|
| 60 |
return $this->format_single_value_for_site_health_info( $value ); |
| 61 |
} |
| 62 |
/** |
| 63 |
* Returns the default value. |
| 64 |
* |
| 65 |
* @since 3.7 |
| 66 |
* |
| 67 |
* @return int |
| 68 |
*/ |
| 69 |
protected function get_default() { |
| 70 |
return 1; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns the JSON schema part specific to this option. |
| 75 |
* |
| 76 |
* @since 3.7 |
| 77 |
* |
| 78 |
* @return array Partial schema. |
| 79 |
* |
| 80 |
* @phpstan-return array{type: 'integer', enum: list<0|1|2|3>|list<1|2|3>} |
| 81 |
*/ |
| 82 |
protected function get_data_structure(): array { |
| 83 |
return array( |
| 84 |
'type' => 'integer', |
| 85 |
'enum' => 'yes' === get_option( 'pll_language_from_content_available' ) ? array( 0, 1, 2, 3 ) : array( 1, 2, 3 ), |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Returns the description used in the JSON schema. |
| 91 |
* |
| 92 |
* @since 3.7 |
| 93 |
* |
| 94 |
* @return string |
| 95 |
*/ |
| 96 |
protected function get_description(): string { |
| 97 |
return __( 'Determine how the current language is defined.', 'polylang' ); |
| 98 |
} |
| 99 |
} |
| 100 |
|