PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 6.0.1
WP Popular Posts v6.0.1
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Translate.php
wordpress-popular-posts / src Last commit date
Activation 3 years ago Admin 3 years ago Block 3 years ago Container 3 years ago Front 3 years ago Rest 3 years ago Traits 3 years ago Widget 3 years ago Bootstrap.php 3 years ago Cache.php 3 years ago Helper.php 3 years ago I18N.php 3 years ago Image.php 3 years ago Output.php 3 years ago Query.php 3 years ago Settings.php 3 years ago Themer.php 3 years ago Translate.php 3 years ago WordPressPopularPosts.php 3 years ago deprecated.php 3 years ago template-tags.php 3 years ago
Translate.php
158 lines
1 <?php
2 /**
3 * Obtains translation data from objects.
4 *
5 * @link http://cabrerahector.com
6 * @since 4.0.0
7 *
8 * @package WordPressPopularPosts
9 */
10
11 namespace WordPressPopularPosts;
12
13 class Translate {
14 /**
15 * Default language code.
16 *
17 * @since 4.0.0
18 * @access private
19 * @var string
20 */
21 private $default_language;
22
23 /**
24 * Current language code.
25 *
26 * @since 4.0.0
27 * @access private
28 * @var string
29 */
30 private $current_language;
31
32 /**
33 * Initialize the collections used to maintain the actions and filters.
34 *
35 * @since 4.0.0
36 */
37 public function __construct()
38 {
39 //
40 }
41
42 /**
43 * Retrieves the code of the default language.
44 *
45 * @since 4.0.0
46 * @return string|null
47 */
48 public function get_default_language()
49 {
50 if ( ! $this->default_language )
51 $this->default_language = ( function_exists('pll_default_language') ) ? pll_default_language() : apply_filters('wpml_default_language', NULL);
52 return $this->default_language;
53 }
54
55 /**
56 * Retrieves the code of the currently active language.
57 *
58 * @since 4.0.0
59 * @return string|null
60 */
61 public function get_current_language()
62 {
63 if ( ! $this->current_language )
64 $this->current_language = ( function_exists('pll_current_language') ) ? pll_current_language() : apply_filters('wpml_current_language', NULL);
65 return $this->current_language;
66 }
67
68 /**
69 * Sets the code of the currently active language.
70 *
71 * @since 4.0.0
72 * @return string
73 */
74 public function set_current_language(string $code)
75 {
76 $this->current_language = $code;
77 }
78
79 /**
80 * Gets language locale.
81 *
82 * @since 5.0.0
83 * @param string $lang Language code (eg. 'es')
84 * @return string|bool
85 */
86 public function get_locale(string $lang)
87 {
88 // Polylang support
89 if ( function_exists('PLL') ) {
90 $lang_object = PLL()->model->get_language($lang);
91 if ( $lang_object && isset($lang_object->locale) )
92 return $lang_object->locale;
93 } else {
94 // WPML support
95 global $sitepress;
96 if ( is_object($sitepress) && method_exists($sitepress, 'get_locale_from_language_code') ) {
97 return $sitepress->get_locale_from_language_code($lang);
98 }
99 }
100
101 return false;
102 }
103
104 /**
105 * Retrieves the ID of an object.
106 *
107 * @since 4.0.0
108 * @param integer $object_id
109 * @param string $object_type
110 * @param boolean $return_original_if_missing
111 * @param string $lang_code
112 * @return integer
113 */
114 public function get_object_id(int $object_id, string $object_type = 'post', bool $return_original_if_missing = true, ?string $lang_code = '')
115 {
116 return apply_filters(
117 'wpml_object_id',
118 $object_id,
119 $object_type,
120 $return_original_if_missing,
121 null == $lang_code ? $this->get_current_language() : $lang_code
122 );
123 }
124
125 /**
126 * Translates URL.
127 *
128 * @since 5.0.0
129 * @param string $original_permalink
130 * @param string $lang
131 * @return string
132 */
133 public function url(string $original_permalink, ?string $lang)
134 {
135 return apply_filters('wpml_permalink', $original_permalink, $lang);
136 }
137
138 /*
139 * Retrieves the language code of an object.
140 *
141 * @since 4.0.0
142 * @param integer $object_id
143 * @param string $object_type
144 * @return string|null
145 */
146 public function get_object_lang_code(int $object_id, string $object_type = 'post')
147 {
148 return apply_filters(
149 'wpml_element_language_code',
150 null,
151 [
152 'element_id' => $object_id,
153 'element_type' => $object_type
154 ]
155 );
156 }
157 }
158