PluginProbe ʕ •ᴥ•ʔ
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) / 3.5.0
CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice) v3.5.0
3.5.1 3.5.0 3.4.2 trunk 1.0.1 1.0.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.3.9.1 3.4.0 3.4.1
cookie-law-info / legacy / includes / class-cookie-law-info-languages.php
cookie-law-info / legacy / includes Last commit date
class-cookie-law-info-activator.php 1 month ago class-cookie-law-info-cookieyes.php 1 month ago class-cookie-law-info-deactivator.php 1 month ago class-cookie-law-info-i18n.php 1 month ago class-cookie-law-info-languages.php 1 month ago class-cookie-law-info-loader.php 1 month ago class-cookie-law-info-review-request.php 1 month ago class-cookie-law-info.php 1 month ago index.php 1 month ago
class-cookie-law-info-languages.php
150 lines
1 <?php
2
3 /**
4 * Cookies module to handle all the cookies related operations
5 *
6 * @version 1.9.6
7 * @package CookieLawInfo
8 */
9
10 // https://wpml.org/wpml-hook/wpml_set_element_language_details/
11 // https://wpml.org/forums/topic/programmatically-create-post-in-different-languages/
12 // https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 class Cookie_Law_Info_Languages {
19
20
21 private static $instance;
22
23 public function __construct() {
24
25 }
26
27 public static function get_instance() {
28 if ( null === self::$instance ) {
29 self::$instance = new self();
30 }
31
32 return self::$instance;
33 }
34 /**
35 * Check whether a multi language plugin is active or not
36 *
37 * @access public
38 * @return boolean
39 */
40 public function is_multilanguage_plugin_active() {
41 $status = false;
42
43 if ( defined( 'ICL_LANGUAGE_CODE' ) || defined( 'POLYLANG_FILE' ) ) {
44 $status = true;
45 }
46
47 return $status;
48 }
49
50 /**
51 * Get default language of the site
52 *
53 * @access public
54 * @return string
55 */
56 public function get_default_language_code() {
57 $default = null;
58
59 if ( $this->is_multilanguage_plugin_active() ) {
60 // Polylang
61 if ( function_exists( 'pll_default_language' ) ) {
62 $default = pll_default_language();
63 } else {
64 // WPML
65 $null = null;
66 $default = apply_filters( 'wpml_default_language', $null );
67 }
68 } else {
69 $default = CLI_DEFAULT_LANGUAGE;
70 }
71
72 return $default;
73 }
74
75 /**
76 * Returns the current language of the site
77 *
78 * @access public
79 * @return string
80 */
81 public function get_current_language_code() {
82 $current_language = null;
83
84 if ( $this->is_multilanguage_plugin_active() ) {
85 // Polylang
86 if ( function_exists( 'pll_current_language' ) ) {
87
88 $current_language = pll_current_language();
89
90 // If current_language is still empty, we have to get the default language
91 if ( empty( $current_language ) ) {
92 $current_language = pll_default_language();
93 }
94 } else {
95 // WPML
96 $null = null;
97 $current_language = apply_filters( 'wpml_current_language', $null );
98 }
99
100 // Fallback
101 if ( $current_language === 'all' ) {
102 $current_language = $this->get_default_language_code();
103 }
104 } else {
105 $current_language = CLI_DEFAULT_LANGUAGE;
106 }
107
108 return $current_language;
109 }
110 public function get_term_by_language( $term_id, $language ) {
111 $term = false;
112 if ( $this->is_multilanguage_plugin_active() ) {
113 // Polylang
114 if ( function_exists( 'pll_get_term_translations' ) ) {
115 $terms = pll_get_term_translations( $term_id );
116 if ( isset( $terms[ $language ] ) ) {
117 $original_term_id = $terms[ $language ];
118 $term = get_term_by( 'id', $original_term_id, 'cookielawinfo-category' );
119 }
120 } else {
121 // WPML
122 if ( function_exists( 'icl_object_id' ) ) {
123 global $sitepress;
124 if ( $sitepress ) {
125 if ( version_compare( ICL_SITEPRESS_VERSION, '3.2.0' ) >= 0 ) {
126 $original_term_id = apply_filters( 'wpml_object_id', $term_id, 'category', true, $language );
127 } else {
128 $original_term_id = icl_object_id( $term_id, 'category', true, $language );
129 }
130 remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1 );
131 $term = get_term_by( 'id', $original_term_id, 'cookielawinfo-category' );
132 add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 );
133 }
134 }
135 }
136 }
137 return $term;
138 }
139
140 public function maybe_set_term_language( $term_id ) {
141 if ( $this->is_multilanguage_plugin_active() ) {
142 // Polylang
143 if ( function_exists( 'pll_set_term_language' ) ) {
144 $language = $this->get_default_language_code();
145 pll_set_term_language( $term_id, $language );
146 }
147 }
148 }
149 }
150