PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Rules / Condition / WordPress / IsLanguage.php

IsLanguage.php in Depicter — Popup & Slider Builder trunk, at app/src/Rules/Condition/WordPress/IsLanguage.php

119 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Depicter\Rules\Condition\WordPress;
4
5 use Averta\Core\Utility\Arr;
6 use Depicter\Rules\Condition\Base as ConditionBase;
7
8 class IsLanguage extends ConditionBase
9 {
10 /**
11 * @inheritdoc
12 */
13 public $slug = 'WordPress_IsLanguage';
14
15 /**
16 * @inheritdoc
17 */
18 public $control = 'dropdown';
19
20 /**
21 * @inheritdoc
22 */
23 protected $belongsTo = 'WordPress';
24
25 /**
26 * Tier of this condition
27 *
28 * @var string
29 */
30 protected $tier = 'pro-user';
31
32 /**
33 * @inheritdoc
34 */
35 public function getLabel(): ?string{
36 return __('WP Language', 'depicter' );
37 }
38
39 /**
40 * @inheritDoc
41 */
42 public function getDescription(): ?string{
43 return __( 'When displayed page is in the specified language.', 'depicter' );
44 }
45
46 /**
47 * @inheritDoc
48 */
49 public function getControlOptions(){
50 $options = parent::getControlOptions();
51
52 if (function_exists('PLL')) {
53 $polylang = PLL();
54 if ( $polylang ) {
55 $languages = $polylang->model->get_languages_list();
56 $languageOptions = [];
57 foreach ($languages as $key => $language) {
58 $languageOptions[$key] = [
59 'label' => $language->name,
60 'value' => $language->slug
61 ];
62 }
63 $options = Arr::merge( $options, [ 'options' => $languageOptions ]);
64 }
65 } else if ( function_exists('icl_get_languages') ) {
66 $languages = apply_filters( 'wpml_active_languages', NULL, array( 'skip_missing' => 0 ) );
67
68 if ( !empty( $languages ) ) {
69 $languageOptions = [];
70 foreach( $languages as $lang ) {
71 $languageOptions[] = [
72 'label' => $lang['translated_name'],
73 'value' => $lang['language_code']
74 ];
75 }
76
77 $options = Arr::merge( $options, [ 'options' => $languageOptions ]);
78 }
79
80 }
81
82 return $options;
83 }
84
85 /**
86 * @inheritdoc
87 */
88 public function check( $value = null ): bool{
89
90 $value = $value ?? $this->value;
91 if ( empty( $value ) ) {
92 $value = $this->defaultValue;
93 }
94
95 $isIncluded = false;
96
97 if ( function_exists('pll_current_language') ) {
98 $currentLanguage = pll_current_language();
99 $isIncluded = $currentLanguage === $value[0] || $value[0] == 'all';
100 } else if ( function_exists('icl_get_languages') ) {
101 $currentLanguage = apply_filters( 'wpml_current_language', NULL );
102 $isIncluded = $currentLanguage === $value[0] || $value[0] == 'all';
103 } else if ( $value[0] == 'all' ) {
104 $isIncluded = true;
105 }
106
107 return $this->selectionMode === 'include' ? $isIncluded : ! $isIncluded;
108 }
109
110 /**
111 * Check if the condition is visible or not
112 *
113 * @return boolean
114 */
115 public function isVisible() {
116 return function_exists('PLL') || function_exists('icl_get_languages');
117 }
118 }
119