PluginProbe
Polylang / trunk
Polylang vtrunk
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 | src/translated-object.php +14 -16 3.8.8 → trunk View file →
@@ -90,9 +90,9 @@
90 90 if ( ! parent::set_language( $id, $lang ) ) {
91 91 return false;
92 92 }
93 93
94 - $id = $this->sanitize_int_id( $id );
94 + $id = pll_sanitize_id( $id );
95 95
96 96 $translations = $this->get_translations( $id );
97 97
98 98 // Don't create translation groups with only 1 value.
@@ -115,9 +115,9 @@
115 115 *
116 116 * @phpstan-return array<non-empty-string, positive-int>
117 117 */
118 118 public function get_translations_from_term_id( $term_id ) {
119 - $term_id = $this->sanitize_int_id( $term_id );
119 + $term_id = pll_sanitize_id( $term_id );
120 120
121 121 if ( empty( $term_id ) ) {
122 122 return array();
123 123 }
@@ -146,9 +146,9 @@
146 146 *
147 147 * @phpstan-return array<non-empty-string, positive-int>
148 148 */
149 149 public function save_translations( $id, array $translations = array() ) {
150 - $id = $this->sanitize_int_id( $id );
150 + $id = pll_sanitize_id( $id );
151 151
152 152 if ( empty( $id ) ) {
153 153 return array();
154 154 }
@@ -181,9 +181,9 @@
181 181
182 182 if ( empty( $term ) ) {
183 183 // Create a new term if necessary.
184 184 $group = uniqid( 'pll_' );
185 - wp_insert_term( $group, $this->tax_translations, array( 'description' => maybe_serialize( $translations ) ) );
185 + wp_insert_term( $group, $this->tax_translations, array( 'description' => (string) maybe_serialize( $translations ) ) );
186 186 } else {
187 187 // Take care not to overwrite extra data stored in the description field, if any.
188 188 $group = (int) $term->term_id;
189 189 $descr = maybe_unserialize( $term->description );
@@ -188,9 +188,9 @@
188 188 $group = (int) $term->term_id;
189 189 $descr = maybe_unserialize( $term->description );
190 190 $descr = is_array( $descr ) ? array_diff_key( $descr, $old_translations ) : array(); // Remove old translations.
191 191 $descr = array_merge( $descr, $translations ); // Add new one.
192 - wp_update_term( $group, $this->tax_translations, array( 'description' => maybe_serialize( $descr ) ) );
192 + wp_update_term( $group, $this->tax_translations, array( 'description' => (string) maybe_serialize( $descr ) ) );
193 193 }
194 194
195 195 // Link all translations to the new term.
196 196 foreach ( $translations as $p ) {
@@ -219,9 +219,9 @@
219 219 * @param int $id Object ID.
220 220 * @return void
221 221 */
222 222 public function delete_translation( $id ) {
223 - $id = $this->sanitize_int_id( $id );
223 + $id = pll_sanitize_id( $id );
224 224
225 225 if ( empty( $id ) ) {
226 226 return;
227 227 }
@@ -244,9 +244,9 @@
244 244
245 245 if ( empty( $descr ) || ! is_array( $descr ) ) {
246 246 wp_delete_term( (int) $term->term_id, $this->tax_translations );
247 247 } else {
248 - wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $descr ) ) );
248 + wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => (string) maybe_serialize( $descr ) ) );
249 249 }
250 250 }
251 251
252 252 /**
@@ -259,9 +259,9 @@
259 259 *
260 260 * @phpstan-return array<non-empty-string, positive-int>
261 261 */
262 262 public function get_translations( $id ) {
263 - $id = $this->sanitize_int_id( $id );
263 + $id = pll_sanitize_id( $id );
264 264
265 265 if ( empty( $id ) ) {
266 266 return array();
267 267 }
@@ -280,9 +280,9 @@
280 280 *
281 281 * @phpstan-return array<non-empty-string, positive-int>
282 282 */
283 283 public function get_raw_translations( $id ) {
284 - $id = $this->sanitize_int_id( $id );
284 + $id = pll_sanitize_id( $id );
285 285
286 286 if ( empty( $id ) ) {
287 287 return array();
288 288 }
@@ -325,9 +325,9 @@
325 325 *
326 326 * @phpstan-return int<0, max>
327 327 */
328 328 public function get( $id, $lang ) {
329 - $id = $this->sanitize_int_id( $id );
329 + $id = pll_sanitize_id( $id );
330 330
331 331 if ( empty( $id ) ) {
332 332 return 0;
333 333 }
@@ -355,9 +355,9 @@
355 355 * @param int $id Object ID.
356 356 * @return bool
357 357 */
358 358 public function current_user_can_synchronize( $id ) {
359 - $id = $this->sanitize_int_id( $id );
359 + $id = pll_sanitize_id( $id );
360 360
361 361 if ( empty( $id ) ) {
362 362 return false;
363 363 }
@@ -404,11 +404,9 @@
404 404 *
405 405 * @phpstan-param array<non-empty-string, positive-int> $translations
406 406 */
407 407 protected function should_update_translation_group( $id, $translations ) {
408 - // Don't do anything if no translations have been added to the group.
409 - $old_translations = $this->get_translations( $id ); // Includes at least $id itself.
410 - return ! empty( array_diff_assoc( $translations, $old_translations ) );
408 + return count( $translations ) > 1;
411 409 }
412 410
413 411 /**
414 412 * Returns an array of valid translations for multiple objects.
@@ -498,9 +496,9 @@
498 496 );
499 497
500 498 // Make sure values are clean before working with them.
501 499 /** @phpstan-var array<non-empty-string, positive-int> $translations */
502 - $translations = $this->sanitize_int_ids_list( $translations );
500 + $translations = pll_sanitize_ids( $translations );
503 501
504 502 if ( 'save' === $context ) {
505 503 /**
506 504 * Check that the translated objects are in the right language.
@@ -519,9 +517,9 @@
519 517
520 518 $translations = $valid_translations;
521 519 }
522 520
523 - $id = $this->sanitize_int_id( $id );
521 + $id = pll_sanitize_id( $id );
524 522
525 523 if ( empty( $id ) ) {
526 524 return $translations;
527 525 }