PluginProbe
Polylang / 2.5
Polylang v2.5
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 | modules/sync/sync-tax.php +16 -54 2.92.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class to manage the sychronization of taxonomy terms across posts translations
8 5 *
@@ -103,43 +100,8 @@
103 100 return $terms; // Empty $terms or untranslated taxonomy
104 101 }
105 102
106 103 /**
107 - * Maybe copy taxonomy terms from one post to the other
108 - *
109 - * @since 2.6
110 - *
111 - * @param int $object_id Source object ID.
112 - * @param int $tr_id Target object ID.
113 - * @param string $lang Target language.
114 - * @param array $terms An array of object terms.
115 - * @param string $taxonomy Taxonomy slug.
116 - * @param bool $append Whether to append new terms to the old terms.
117 - */
118 - protected function copy_object_terms( $object_id, $tr_id, $lang, $terms, $taxonomy, $append ) {
119 - $to_copy = $this->get_taxonomies_to_copy( true, $object_id, $tr_id, $lang );
120 -
121 - if ( in_array( $taxonomy, $to_copy ) ) {
122 - $newterms = $this->maybe_translate_terms( $object_id, $terms, $taxonomy, $lang );
123 -
124 - // For some reasons, the user may have untranslated terms in the translation. Don't forget them.
125 - if ( $this->model->is_translated_taxonomy( $taxonomy ) ) {
126 - $tr_terms = get_the_terms( $tr_id, $taxonomy );
127 - if ( is_array( $tr_terms ) ) {
128 - foreach ( $tr_terms as $term ) {
129 - if ( ! $this->model->term->get_translation( $term->term_id, $this->model->post->get_language( $object_id ) ) ) {
130 - $newterms[] = (int) $term->term_id;
131 - }
132 - }
133 - }
134 - }
135 -
136 - wp_set_object_terms( $tr_id, $newterms, $taxonomy, $append );
137 - }
138 -
139 - }
140 -
141 - /**
142 104 * When assigning terms to a post, assign translated terms to the translated posts (synchronisation)
143 105 *
144 106 * @since 2.3
145 107 *
@@ -160,24 +122,26 @@
160 122 $tr_ids = $this->model->post->get_translations( $object_id );
161 123
162 124 foreach ( $tr_ids as $lang => $tr_id ) {
163 125 if ( $tr_id !== $object_id ) {
164 - if ( $this->model->post->current_user_can_synchronize( $object_id ) ) {
165 - $this->copy_object_terms( $object_id, $tr_id, $lang, $terms, $taxonomy, $append );
166 - } else {
167 - // No permission to synchronize, so let's synchronize in reverse order
168 - $orig_lang = array_search( $object_id, $tr_ids );
169 - $tr_terms = get_the_terms( $tr_id, $taxonomy );
126 + $to_copy = $this->get_taxonomies_to_copy( true, $object_id, $tr_id, $lang );
170 127
171 - if ( false === $tr_terms ) {
172 - $tr_terms = array();
128 + if ( in_array( $taxonomy, $to_copy ) ) {
129 + $newterms = $this->maybe_translate_terms( $object_id, $terms, $taxonomy, $lang );
130 +
131 + // For some reasons, the user may have untranslated terms in the translation. Don't forget them.
132 + if ( $this->model->is_translated_taxonomy( $taxonomy ) ) {
133 + $tr_terms = get_the_terms( $tr_id, $taxonomy );
134 + if ( is_array( $tr_terms ) ) {
135 + foreach ( $tr_terms as $term ) {
136 + if ( ! $this->model->term->get_translation( $term->term_id, $this->model->post->get_language( $object_id ) ) ) {
137 + $newterms[] = (int) $term->term_id;
138 + }
139 + }
140 + }
173 141 }
174 142
175 - if ( is_array( $tr_terms ) ) {
176 - $tr_terms = wp_list_pluck( $tr_terms, 'term_id' );
177 - $this->copy_object_terms( $tr_id, $object_id, $orig_lang, $tr_terms, $taxonomy, $append );
178 - }
179 - break;
143 + wp_set_object_terms( $tr_id, $newterms, $taxonomy, $append );
180 144 }
181 145 }
182 146 }
183 147
@@ -261,11 +225,9 @@
261 225
262 226 $posts = array_unique( $posts );
263 227
264 228 foreach ( $posts as $post_id ) {
265 - if ( current_user_can( 'assign_term', $term_id ) ) {
266 - wp_set_object_terms( $post_id, $term_id, $taxonomy, true );
267 - }
229 + wp_set_object_terms( $post_id, $term_id, $taxonomy, true );
268 230 }
269 231 }
270 232 }
271 233