PluginProbe
Polylang / 2.5.2
Polylang v2.5.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 +9 -56 2.82.5.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 *
@@ -9,9 +6,9 @@
9 6 * @since 1.8
10 7 */
11 8 abstract class PLL_Translated_Object {
12 9 public $model;
13 - protected $object_type, $type, $tax_language, $tax_translations, $tax_tt;
10 + protected $object_type, $tax_language, $tax_translations, $tax_tt;
14 11
15 12 /**
16 13 * Constructor
17 14 *
@@ -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;
@@ -123,16 +114,16 @@
123 114 $term = reset( $terms );
124 115
125 116 // create a new term if necessary
126 117 if ( empty( $term ) ) {
127 - wp_insert_term( $group = uniqid( 'pll_' ), $this->tax_translations, array( 'description' => maybe_serialize( $translations ) ) );
118 + wp_insert_term( $group = uniqid( 'pll_' ), $this->tax_translations, array( 'description' => serialize( $translations ) ) );
128 119 }
129 120 else {
130 121 // take care not to overwrite extra data stored in description field, if any
131 - $d = maybe_unserialize( $term->description );
122 + $d = unserialize( $term->description );
132 123 $d = is_array( $d ) ? array_diff_key( $d, $old_translations ) : array(); // remove old translations
133 124 $d = array_merge( $d, $translations ); // add new one
134 - wp_update_term( $group = (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $d ) ) );
125 + wp_update_term( $group = (int) $term->term_id, $this->tax_translations, array( 'description' => serialize( $d ) ) );
135 126 }
136 127
137 128 // link all translations to the new term
138 129 foreach ( $translations as $p ) {
@@ -161,9 +152,9 @@
161 152 $id = (int) $id;
162 153 $term = $this->get_object_term( $id, $this->tax_translations );
163 154
164 155 if ( ! empty( $term ) ) {
165 - $d = maybe_unserialize( $term->description );
156 + $d = unserialize( $term->description );
166 157 $slug = array_search( $id, $this->get_translations( $id ) ); // in case some plugin stores the same value with different key
167 158 unset( $d[ $slug ] );
168 159
169 160 if ( empty( $d ) ) {
@@ -169,9 +160,9 @@
169 160 if ( empty( $d ) ) {
170 161 wp_delete_term( (int) $term->term_id, $this->tax_translations );
171 162 }
172 163 else {
173 - wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $d ) ) );
164 + wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => serialize( $d ) ) );
174 165 }
175 166 }
176 167 }
177 168
@@ -184,9 +175,9 @@
184 175 * @return array an associative array of translations with language code as key and translation id as value
185 176 */
186 177 public function get_translations( $id ) {
187 178 $term = $this->get_object_term( $id, $this->tax_translations );
188 - $translations = empty( $term ) ? array() : maybe_unserialize( $term->description );
179 + $translations = empty( $term ) ? array() : unserialize( $term->description );
189 180
190 181 // make sure we return only translations ( thus we allow plugins to store other information in the array )
191 182 if ( is_array( $translations ) ) {
192 183 $translations = array_intersect_key( $translations, array_flip( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) );
@@ -247,8 +238,9 @@
247 238 * @param object|array|string $lang a PLL_Language object or a comma separated list of language slug or an array of language slugs
248 239 * @return string where clause
249 240 */
250 241 public function where_clause( $lang ) {
242 + global $wpdb;
251 243 $tt_id = $this->tax_tt;
252 244
253 245 // $lang is an object
254 246 // generally the case if the query is coming from Polylang
@@ -257,10 +249,9 @@
257 249 }
258 250
259 251 // $lang is a comma separated list of slugs ( or an array of slugs )
260 252 // generally the case is the query is coming from outside with 'lang' parameter
261 - $slugs = is_array( $lang ) ? $lang : explode( ',', $lang );
262 - $languages = array();
253 + $slugs = is_array( $lang ) ? $lang : explode( ',', $lang );
263 254 foreach ( $slugs as $slug ) {
264 255 $languages[] = absint( $this->model->get_language( $slug )->$tt_id );
265 256 }
266 257
@@ -279,44 +270,6 @@
279 270 public function get_objects_in_language( $lang ) {
280 271 global $wpdb;
281 272 $tt_id = $this->tax_tt;
282 273 return $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $lang->$tt_id ) );
283 - }
284 -
285 - /**
286 - * Check if a user can synchronize translations
287 - *
288 - * @since 2.6
289 - *
290 - * @param int $id Object id
291 - * @return bool
292 - */
293 - public function current_user_can_synchronize( $id ) {
294 - /**
295 - * Filters whether a synchronization capability check should take place
296 - *
297 - * @since 2.6
298 - *
299 - * @param $check null to enable the capability check,
300 - * true to always allow the synchronization,
301 - * false to always disallow the synchronization.
302 - * Defaults to true.
303 - * @param $id The synchronization source object id
304 - */
305 - $check = apply_filters( "pll_pre_current_user_can_synchronize_{$this->type}", true, $id );
306 - if ( null !== $check ) {
307 - return $check;
308 - }
309 -
310 - if ( ! current_user_can( "edit_{$this->type}", $id ) ) {
311 - return false;
312 - }
313 -
314 - foreach ( $this->get_translations( $id ) as $tr_id ) {
315 - if ( $tr_id !== $id && ! current_user_can( "edit_{$this->type}", $tr_id ) ) {
316 - return false;
317 - }
318 - }
319 -
320 - return true;
321 274 }
322 275 }