PluginProbe
Polylang / 2.6.2
Polylang v2.6.2
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-object.php +7 -33 2.92.6.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Setups the objects languages and translations model
8 5 *
@@ -45,13 +42,8 @@
45 42 return false;
46 43 }
47 44
48 45 $object_id = (int) $object_id;
49 -
50 - if ( $object_id < 0 ) {
51 - return false;
52 - }
53 -
54 46 $term = get_object_term_cache( $object_id, $taxonomy );
55 47
56 48 if ( false === $term ) {
57 49 // query language and translations at the same time
@@ -57,9 +49,8 @@
57 49 // query language and translations at the same time
58 50 $taxonomies = array( $this->tax_language, $this->tax_translations );
59 51
60 52 // query terms
61 - $terms = array();
62 53 foreach ( wp_get_object_terms( $object_id, $taxonomies, array( 'update_term_meta_cache' => false ) ) as $t ) {
63 54 $terms[ $t->taxonomy ] = $t;
64 55 if ( $t->taxonomy == $taxonomy ) {
65 56 $term = $t;
@@ -162,16 +153,15 @@
162 153 $term = $this->get_object_term( $id, $this->tax_translations );
163 154
164 155 if ( ! empty( $term ) ) {
165 156 $d = maybe_unserialize( $term->description );
166 - if ( is_array( $d ) ) {
167 - $slug = array_search( $id, $this->get_translations( $id ) ); // In case some plugin stores the same value with different key.
168 - unset( $d[ $slug ] );
169 - }
157 + $slug = array_search( $id, $this->get_translations( $id ) ); // in case some plugin stores the same value with different key
158 + unset( $d[ $slug ] );
170 159
171 160 if ( empty( $d ) ) {
172 161 wp_delete_term( (int) $term->term_id, $this->tax_translations );
173 - } else {
162 + }
163 + else {
174 164 wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $d ) ) );
175 165 }
176 166 }
177 167 }
@@ -248,8 +238,9 @@
248 238 * @param object|array|string $lang a PLL_Language object or a comma separated list of language slug or an array of language slugs
249 239 * @return string where clause
250 240 */
251 241 public function where_clause( $lang ) {
242 + global $wpdb;
252 243 $tt_id = $this->tax_tt;
253 244
254 245 // $lang is an object
255 246 // generally the case if the query is coming from Polylang
@@ -258,10 +249,9 @@
258 249 }
259 250
260 251 // $lang is a comma separated list of slugs ( or an array of slugs )
261 252 // generally the case is the query is coming from outside with 'lang' parameter
262 - $slugs = is_array( $lang ) ? $lang : explode( ',', $lang );
263 - $languages = array();
253 + $slugs = is_array( $lang ) ? $lang : explode( ',', $lang );
264 254 foreach ( $slugs as $slug ) {
265 255 $languages[] = absint( $this->model->get_language( $slug )->$tt_id );
266 256 }
267 257
@@ -279,25 +269,9 @@
279 269 */
280 270 public function get_objects_in_language( $lang ) {
281 271 global $wpdb;
282 272 $tt_id = $this->tax_tt;
283 -
284 - $last_changed = wp_cache_get_last_changed( 'terms' );
285 - $cache_key = "polylang:get_objects_in_language:{$lang->$tt_id}:{$last_changed}";
286 - $cache = wp_cache_get( $cache_key, 'terms' );
287 -
288 - if ( false === $cache ) {
289 - $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $lang->$tt_id ) );
290 - wp_cache_set( $cache_key, $object_ids, 'terms' );
291 - } else {
292 - $object_ids = (array) $cache;
293 - }
294 -
295 - if ( ! $object_ids ) {
296 - return array();
297 - }
298 -
299 - return $object_ids;
273 + return $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $lang->$tt_id ) );
300 274 }
301 275
302 276 /**
303 277 * Check if a user can synchronize translations