PluginProbe
Polylang / 2.6.2
Polylang v2.6.2
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.php +7 -12 2.9.22.6.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Manages copy and synchronization of terms and post metas on front
8 5 *
@@ -85,8 +82,9 @@
85 82 */
86 83 public function can_sync_post_parent( $post_parent, $post_id, $postarr ) {
87 84 if ( ! empty( $postarr['ID'] ) && ! $this->model->post->current_user_can_synchronize( $postarr['ID'] ) ) {
88 85 $tr_ids = $this->model->post->get_translations( $postarr['ID'] );
86 + $orig_lang = array_search( $postarr['ID'], $tr_ids );
89 87 foreach ( $tr_ids as $tr_id ) {
90 88 if ( $tr_id !== $postarr['ID'] && $post = get_post( $tr_id ) ) {
91 89 $post_parent = $post->post_parent;
92 90 break;
@@ -141,9 +139,9 @@
141 139
142 140 $tr_arr = $postarr;
143 141 unset( $tr_arr['post_parent'] );
144 142
145 - // Do not udpate the translation parent if the user set a parent with no translation.
143 + // Do not udpate the translation parent if the user set a parent with no translation
146 144 if ( isset( $postarr['post_parent'] ) ) {
147 145 $post_parent = $postarr['post_parent'] ? $this->model->post->get_translation( $postarr['post_parent'], $lang ) : 0;
148 146 if ( ! ( $postarr['post_parent'] && ! $post_parent ) ) {
149 147 $tr_arr['post_parent'] = $post_parent;
@@ -149,14 +147,12 @@
149 147 $tr_arr['post_parent'] = $post_parent;
150 148 }
151 149 }
152 150
153 - // Update all the rows at once.
154 - if ( ! empty( $tr_arr ) ) {
155 - // Don't use wp_update_post to avoid infinite loop.
156 - $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) );
157 - clean_post_cache( $tr_id );
158 - }
151 + // Update all the row at once
152 + // Don't use wp_update_post to avoid infinite loop
153 + $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) );
154 + clean_post_cache( $tr_id );
159 155 }
160 156 }
161 157 }
162 158 }
@@ -178,10 +174,9 @@
178 174 $term = get_term( $term_id );
179 175 $translations = $this->model->term->get_translations( $term_id );
180 176
181 177 foreach ( $translations as $lang => $tr_id ) {
182 - if ( ! empty( $tr_id ) && $tr_id !== $term_id ) {
183 - $tr_parent = $this->model->term->get_translation( $term->parent, $lang );
178 + if ( ! empty( $tr_id ) && $tr_id !== $term_id && $tr_parent = $this->model->term->get_translation( $term->parent, $lang ) ) {
184 179 $wpdb->update(
185 180 $wpdb->term_taxonomy,
186 181 array( 'parent' => isset( $tr_parent ) ? $tr_parent : 0 ),
187 182 array( 'term_taxonomy_id' => get_term( (int) $tr_id, $taxonomy )->term_taxonomy_id )