PluginProbe
Polylang / 2.8
Polylang v2.8
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/translated-term.php +22 -31 3.02.8 View file →
@@ -27,21 +27,20 @@
27 27 parent::__construct( $model );
28 28
29 29 // Filters to prime terms cache
30 30 add_filter( 'get_terms', array( $this, '_prime_terms_cache' ), 10, 2 );
31 - add_filter( 'get_object_terms', array( $this, 'wp_get_object_terms' ), 10, 3 );
31 + add_filter( 'wp_get_object_terms', array( $this, 'wp_get_object_terms' ), 10, 3 );
32 32
33 33 add_action( 'clean_term_cache', array( $this, 'clean_term_cache' ) );
34 34 }
35 35
36 36 /**
37 - * Stores the term language in the database.
37 + * Stores the term language in the database
38 38 *
39 39 * @since 0.6
40 40 *
41 - * @param int $term_id Term id.
42 - * @param int|string|PLL_Language $lang Language (term_id or slug or object).
43 - * @return void
41 + * @param int $term_id term id
42 + * @param int|string|object $lang language ( term_id or slug or object )
44 43 */
45 44 public function set_language( $term_id, $lang ) {
46 45 $term_id = (int) $term_id;
47 46
@@ -46,12 +45,10 @@
46 45 $term_id = (int) $term_id;
47 46
48 47 $old_lang = $this->get_language( $term_id );
49 48 $old_lang = $old_lang ? $old_lang->tl_term_id : '';
49 + $lang = $lang ? $this->model->get_language( $lang )->tl_term_id : '';
50 50
51 - $lang = $this->model->get_language( $lang );
52 - $lang = $lang ? $lang->tl_term_id : '';
53 -
54 51 if ( $old_lang !== $lang ) {
55 52 wp_set_object_terms( $term_id, $lang, 'term_language' );
56 53
57 54 // Add translation group for correct WXR export
@@ -69,9 +66,8 @@
69 66 *
70 67 * @since 0.5
71 68 *
72 69 * @param int $term_id term id
73 - * @return void
74 70 */
75 71 public function delete_language( $term_id ) {
76 72 wp_delete_object_term_relationships( $term_id, 'term_language' );
77 73 }
@@ -82,9 +78,9 @@
82 78 * @since 0.1
83 79 *
84 80 * @param int|string $value term id or term slug
85 81 * @param string $taxonomy optional taxonomy needed when the term slug is passed as first parameter
86 - * @return PLL_Language|false PLL_Language object, false if no language is associated to that term
82 + * @return bool|object PLL_Language object, false if no language is associated to that term
87 83 */
88 84 public function get_language( $value, $taxonomy = '' ) {
89 85 if ( is_numeric( $value ) ) {
90 86 $term_id = $value;
@@ -91,12 +87,9 @@
91 87 }
92 88
93 89 // get_term_by still not cached in WP 3.5.1 but internally, the function is always called by term_id
94 90 elseif ( is_string( $value ) && $taxonomy ) {
95 - $term = get_term_by( 'slug', $value, $taxonomy );
96 - if ( $term instanceof WP_Term ) {
97 - $term_id = $term->term_id;
98 - }
91 + $term_id = get_term_by( 'slug', $value, $taxonomy )->term_id;
99 92 }
100 93
101 94 // Get the language and make sure it is a PLL_Language object
102 95 return isset( $term_id ) && ( $lang = $this->get_object_term( $term_id, 'term_language' ) ) ? $this->model->get_language( $lang->term_id ) : false;
@@ -102,15 +95,14 @@
102 95 return isset( $term_id ) && ( $lang = $this->get_object_term( $term_id, 'term_language' ) ) ? $this->model->get_language( $lang->term_id ) : false;
103 96 }
104 97
105 98 /**
106 - * Tells whether a translation term must updated.
99 + * Tells whether a translation term must updated
107 100 *
108 101 * @since 2.3
109 102 *
110 - * @param int $id Post id or term id.
111 - * @param int[] $translations An associative array of translations with language code as key and translation id as value.
112 - * @return bool
103 + * @param array $id Post id or term id
104 + * @param array $translations An associative array of translations with language code as key and translation id as value
113 105 */
114 106 protected function should_update_translation_group( $id, $translations ) {
115 107 // Don't do anything if no translations have been added to the group
116 108 $old_translations = $this->get_translations( $id );
@@ -128,9 +120,8 @@
128 120 *
129 121 * @since 0.5
130 122 *
131 123 * @param int $id term id
132 - * @return void
133 124 */
134 125 public function delete_translation( $id ) {
135 126 global $wpdb;
136 127 $slug = array_search( $id, $this->get_translations( $id ) ); // in case some plugin stores the same value with different key
@@ -160,15 +151,15 @@
160 151 return " INNER JOIN $wpdb->term_relationships AS pll_tr ON pll_tr.object_id = $alias.term_id";
161 152 }
162 153
163 154 /**
164 - * Caches the language and translations when terms are queried by get_terms().
155 + * Cache language and translations when terms are queried by get_terms
165 156 *
166 157 * @since 1.2
167 158 *
168 - * @param WP_Term[]|int[] $terms Queried terms.
169 - * @param string[] $taxonomies Queried taxonomies.
170 - * @return WP_Term[]|int[] Unmodified $terms.
159 + * @param array $terms queried terms
160 + * @param array $taxonomies queried taxonomies
161 + * @return array unmodified $terms
171 162 */
172 163 public function _prime_terms_cache( $terms, $taxonomies ) {
173 164 $term_ids = array();
174 165
@@ -184,18 +175,19 @@
184 175 return $terms;
185 176 }
186 177
187 178 /**
188 - * When terms are found for posts, add their language and translations to cache.
179 + * When terms are found for posts, add their language and translations to cache
189 180 *
190 181 * @since 1.2
191 182 *
192 - * @param WP_Term[] $terms Array of terms for the given object or objects.
193 - * @param int[] $object_ids Array of object IDs for which terms were retrieved.
194 - * @param string[] $taxonomies Array of taxonomy names from which terms were retrieved.
195 - * @return WP_Term[] Unmodified $terms.
183 + * @param array $terms terms found
184 + * @param array $object_ids not used
185 + * @param array $taxonomies terms taxonomies
186 + * @return array unmodified $terms
196 187 */
197 188 public function wp_get_object_terms( $terms, $object_ids, $taxonomies ) {
189 + $taxonomies = explode( "', '", trim( $taxonomies, "'" ) );
198 190 if ( ! in_array( 'term_translations', $taxonomies ) ) {
199 191 $this->_prime_terms_cache( $terms, $taxonomies );
200 192 }
201 193 return $terms;
@@ -201,14 +193,13 @@
201 193 return $terms;
202 194 }
203 195
204 196 /**
205 - * When the term cache is cleaned, cleans the object term cache too.
197 + * When the term cache is cleaned, clean the object term cache too
206 198 *
207 199 * @since 2.0
208 200 *
209 - * @param int[] $ids An array of term IDs.
210 - * @return void
201 + * @param array $ids An array of term IDs.
211 202 */
212 203 public function clean_term_cache( $ids ) {
213 204 clean_object_term_cache( $ids, 'term' );
214 205 }