| @@ -18,12 +18,8 @@ | ||
| 18 | 18 | */ |
| 19 | 19 | public function __construct( &$polylang ) { |
| 20 | 20 | $this->model = &$polylang->model; |
| 21 | 21 | |
| 22 | - add_filter( "add_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); | |
| 23 | - add_filter( "update_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); | |
| 24 | - add_filter( "delete_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); | |
| 25 | - | |
| 26 | 22 | $this->add_all_meta_actions(); |
| 27 | 23 | |
| 28 | 24 | add_action( "pll_save_{$this->meta_type}", array( $this, 'save_object' ), 10, 3 ); |
| 29 | 25 | } |
| @@ -130,34 +126,8 @@ | ||
| 130 | 126 | return array_unique( apply_filters( "pll_copy_{$this->meta_type}_metas", array(), $sync, $from, $to, $lang ) ); |
| 131 | 127 | } |
| 132 | 128 | |
| 133 | 129 | /** |
| 134 | - * Disallow modifying synchronized meta if the current user can not modify translations | |
| 135 | - * | |
| 136 | - * @since 2.6 | |
| 137 | - * | |
| 138 | - * @param null|bool $check Whether to allow adding/updating/deleting metadata. | |
| 139 | - * @param int $id Object ID. | |
| 140 | - * @param string $meta_key Meta key. | |
| 141 | - * @return null|bool | |
| 142 | - */ | |
| 143 | - public function can_synchronize_metadata( $check, $id, $meta_key ) { | |
| 144 | - if ( ! $this->model->{$this->meta_type}->current_user_can_synchronize( $id ) ) { | |
| 145 | - $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); | |
| 146 | - | |
| 147 | - foreach ( $tr_ids as $lang => $tr_id ) { | |
| 148 | - if ( $tr_id != $id ) { | |
| 149 | - $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); | |
| 150 | - if ( in_array( $meta_key, $to_copy ) ) { | |
| 151 | - return false; | |
| 152 | - } | |
| 153 | - } | |
| 154 | - } | |
| 155 | - } | |
| 156 | - return $check; | |
| 157 | - } | |
| 158 | - | |
| 159 | - /** | |
| 160 | 130 | * Synchronize added metas across translations |
| 161 | 131 | * |
| 162 | 132 | * @since 2.3 |
| 163 | 133 | * |
| @@ -177,9 +147,9 @@ | ||
| 177 | 147 | if ( $tr_id != $id ) { |
| 178 | 148 | $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); |
| 179 | 149 | if ( in_array( $meta_key, $to_copy ) ) { |
| 180 | 150 | $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); |
| 181 | - add_metadata( $this->meta_type, $tr_id, $meta_key, is_string( $meta_value ) ? wp_slash( $meta_value ) : $meta_value ); | |
| 151 | + add_metadata( $this->meta_type, $tr_id, $meta_key, $meta_value ); | |
| 182 | 152 | } |
| 183 | 153 | } |
| 184 | 154 | } |
| 185 | 155 | |
| @@ -223,24 +193,24 @@ | ||
| 223 | 193 | if ( ! $avoid_recursion ) { |
| 224 | 194 | $avoid_recursion = true; |
| 225 | 195 | $hash = md5( "$id|$meta_key|" . maybe_serialize( $meta_value ) ); |
| 226 | 196 | |
| 227 | - $prev_meta = get_metadata_by_mid( $this->meta_type, $mid ); | |
| 197 | + $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); | |
| 228 | 198 | |
| 229 | - if ( $prev_meta ) { | |
| 230 | - $this->remove_add_meta_action(); // We don't want to sync back the new metas | |
| 231 | - $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); | |
| 232 | - | |
| 233 | - foreach ( $tr_ids as $lang => $tr_id ) { | |
| 234 | - if ( $tr_id != $id && in_array( $meta_key, $this->get_metas_to_copy( $id, $tr_id, $lang, true ) ) ) { | |
| 199 | + foreach ( $tr_ids as $lang => $tr_id ) { | |
| 200 | + if ( $tr_id != $id ) { | |
| 201 | + $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); | |
| 202 | + if ( in_array( $meta_key, $to_copy ) ) { | |
| 203 | + $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); | |
| 204 | + $prev_meta = get_metadata_by_mid( $this->meta_type, $mid ); | |
| 235 | 205 | if ( empty( $this->prev_value[ $hash ] ) || $this->prev_value[ $hash ] === $prev_meta->meta_value ) { |
| 236 | 206 | $prev_value = $this->maybe_translate_value( $prev_meta->meta_value, $meta_key, $id, $tr_id, $lang ); |
| 237 | - $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); | |
| 238 | - update_metadata( $this->meta_type, $tr_id, $meta_key, is_string( $meta_value ) ? wp_slash( $meta_value ) : $meta_value, $prev_value ); | |
| 207 | + $this->remove_add_meta_action(); // We don't want to sync back the new metas | |
| 208 | + update_metadata( $this->meta_type, $tr_id, $meta_key, $meta_value, $prev_value ); | |
| 209 | + $this->restore_add_meta_action(); | |
| 239 | 210 | } |
| 240 | 211 | } |
| 241 | 212 | } |
| 242 | - $this->restore_add_meta_action(); | |
| 243 | 213 | } |
| 244 | 214 | |
| 245 | 215 | unset( $this->prev_value[ $hash ] ); |
| 246 | 216 | $avoid_recursion = false; |
| @@ -286,9 +256,9 @@ | ||
| 286 | 256 | if ( in_array( $key, $this->to_copy[ $id ][ $tr_id ] ) ) { |
| 287 | 257 | if ( '' !== $value && null !== $value && false !== $value ) { // Same test as WP |
| 288 | 258 | $value = $this->maybe_translate_value( $value, $key, $id, $tr_id, $lang ); |
| 289 | 259 | } |
| 290 | - delete_metadata( $this->meta_type, $tr_id, $key, is_string( $value ) ? wp_slash( $value ) : $value ); | |
| 260 | + delete_metadata( $this->meta_type, $tr_id, $key, $value ); | |
| 291 | 261 | } |
| 292 | 262 | } |
| 293 | 263 | } |
| 294 | 264 | } |
| @@ -327,9 +297,9 @@ | ||
| 327 | 297 | // One custom field to update |
| 328 | 298 | $value = reset( $metas[ $key ] ); |
| 329 | 299 | $value = maybe_unserialize( $value ); |
| 330 | 300 | $to_value = $this->maybe_translate_value( $value, $key, $from, $to, $lang ); |
| 331 | - update_metadata( $this->meta_type, $to, $key, is_string( $to_value ) ? wp_slash( $to_value ) : $to_value ); | |
| 301 | + update_metadata( $this->meta_type, $to, $key, $to_value ); | |
| 332 | 302 | } else { |
| 333 | 303 | // Multiple custom fields, either in the source or the target |
| 334 | 304 | if ( ! empty( $tr_metas[ $key ] ) ) { |
| 335 | 305 | // The synchronization of multiple values custom fields is easier if we delete all metas first |
| @@ -338,9 +308,9 @@ | ||
| 338 | 308 | |
| 339 | 309 | foreach ( $metas[ $key ] as $value ) { |
| 340 | 310 | $value = maybe_unserialize( $value ); |
| 341 | 311 | $to_value = $this->maybe_translate_value( $value, $key, $from, $to, $lang ); |
| 342 | - add_metadata( $this->meta_type, $to, $key, is_string( $to_value ) ? wp_slash( $to_value ) : $to_value ); | |
| 312 | + add_metadata( $this->meta_type, $to, $key, $to_value ); | |
| 343 | 313 | } |
| 344 | 314 | } |
| 345 | 315 | } |
| 346 | 316 | } |
| @@ -358,8 +328,10 @@ | ||
| 358 | 328 | * @param object $obj Not used |
| 359 | 329 | * @param array $translations The list of translations object ids |
| 360 | 330 | */ |
| 361 | 331 | public function save_object( $object_id, $obj, $translations ) { |
| 332 | + $src_lang = array_search( $object_id, $translations ); | |
| 333 | + | |
| 362 | 334 | foreach ( $translations as $tr_lang => $tr_id ) { |
| 363 | 335 | if ( $tr_id != $object_id ) { |
| 364 | 336 | $this->copy( $object_id, $tr_id, $tr_lang, true ); |
| 365 | 337 | } |