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