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