← All changes
|
includes/contact-segmentation/conditions/browser-language.php
+40
-0
1.2.2
→
2.7.0
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Sellkit\Contact_Segmentation\Conditions; |
| 4 | 4 | |
| 5 | 5 | use Sellkit\Contact_Segmentation\Conditions\Condition_Base; |
| 6 | +use Sellkit\Contact_Segmentation\Operators; | |
| 6 | 7 | |
| 7 | 8 | defined( 'ABSPATH' ) || die(); |
| 8 | 9 | |
| 9 | 10 | /** |
| @@ -47,8 +48,18 @@ | ||
| 47 | 48 | * @since 1.1.0 |
| 48 | 49 | * @return string[] |
| 49 | 50 | */ |
| 50 | 51 | public function get_options() { |
| 52 | + return self::browser_languages_array(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Browser languages array. | |
| 57 | + * | |
| 58 | + * @since 1.5.0 | |
| 59 | + * @return string[] | |
| 60 | + */ | |
| 61 | + public static function browser_languages_array() { | |
| 51 | 62 | // It's from here http://www.lingoes.net/en/translator/langcode.htm. |
| 52 | 63 | return [ |
| 53 | 64 | 'aa-DJ' => 'Afar (Djibouti)', |
| 54 | 65 | 'aa-ER' => 'Afar (Eritrea)', |
| @@ -301,7 +312,36 @@ | ||
| 301 | 312 | * |
| 302 | 313 | * @since 1.1.0 |
| 303 | 314 | */ |
| 304 | 315 | public function is_pro() { |
| 316 | + return false; | |
| 317 | + } | |
| 318 | + | |
| 319 | + /** | |
| 320 | + * If it's valid or not. | |
| 321 | + * | |
| 322 | + * @since 1.3.1 | |
| 323 | + * @param array $condition_value Condition value. | |
| 324 | + * @param string $operator_name Operator name. | |
| 325 | + * @return bool | |
| 326 | + */ | |
| 327 | + public function is_valid( $condition_value, $operator_name ) { | |
| 328 | + if ( empty( $this->data['browser_language'] ) ) { | |
| 329 | + return false; | |
| 330 | + } | |
| 331 | + | |
| 332 | + $operator = Operators::$operators[ $operator_name ]; | |
| 333 | + $condition = $condition_value; | |
| 334 | + | |
| 335 | + if ( strpos( $this->data['browser_language'], '-' ) === false ) { | |
| 336 | + $condition = explode( '-', $condition_value )[0]; | |
| 337 | + } | |
| 338 | + | |
| 339 | + $is_valid = $operator->is_valid( $this->data['browser_language'], $condition ); | |
| 340 | + | |
| 341 | + if ( $is_valid ) { | |
| 342 | + return true; | |
| 343 | + } | |
| 344 | + | |
| 305 | 345 | return false; |
| 306 | 346 | } |
| 307 | 347 | } |