PluginProbe
Polylang / 2.7.3
Polylang v2.7.3
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 +21 -59 3.02.7.3 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 *
@@ -8,36 +5,11 @@
8 5 *
9 6 * @since 2.4
10 7 */
11 8 class PLL_Sync {
12 - /**
13 - * @var PLL_Sync_Tax
14 - */
15 - public $taxonomies;
9 + public $taxonomies, $post_metas, $term_meta;
16 10
17 11 /**
18 - * @var PLL_Sync_Post_Metas
19 - */
20 - public $post_metas;
21 -
22 - /**
23 - * @var PLL_Sync_Term_Metas
24 - */
25 - public $term_metas;
26 -
27 - /**
28 - * Stores the plugin options.
29 - *
30 - * @var array
31 - */
32 - protected $options;
33 -
34 - /**
35 - * @var PLL_Model
36 - */
37 - protected $model;
38 -
39 - /**
40 12 * Constructor
41 13 *
42 14 * @since 1.2
43 15 *
@@ -69,13 +41,13 @@
69 41 add_filter( 'pre_update_option_sticky_posts', array( $this, 'sync_sticky_posts' ), 10, 2 );
70 42 }
71 43
72 44 /**
73 - * Get post fields to synchronize.
45 + * Get post fields to synchornize
74 46 *
75 47 * @since 2.4
76 48 *
77 - * @param WP_Post $post Post object.
49 + * @param object $post Post object
78 50 * @return array
79 51 */
80 52 protected function get_fields_to_sync( $post ) {
81 53 $postarr = array();
@@ -143,16 +115,15 @@
143 115 return $data;
144 116 }
145 117
146 118 /**
147 - * Synchronizes post fields in translations.
119 + * Synchronizes post fields in translations
148 120 *
149 121 * @since 2.4
150 122 *
151 - * @param int $post_id Post id.
152 - * @param WP_Post $post Post object.
153 - * @param int[] $translations Post translations.
154 - * @return void
123 + * @param int $post_id post id
124 + * @param object $post post object
125 + * @param array $translations post translations
155 126 */
156 127 public function pll_save_post( $post_id, $post, $translations ) {
157 128 global $wpdb;
158 129
@@ -195,9 +166,8 @@
195 166 *
196 167 * @param int $term_id Term id.
197 168 * @param int $tt_id Term taxonomy id, not used.
198 169 * @param string $taxonomy Taxonomy name.
199 - * @return void
200 170 */
201 171 public function sync_term_parent( $term_id, $tt_id, $taxonomy ) {
202 172 global $wpdb;
203 173
@@ -202,27 +172,20 @@
202 172 global $wpdb;
203 173
204 174 if ( is_taxonomy_hierarchical( $taxonomy ) && $this->model->is_translated_taxonomy( $taxonomy ) ) {
205 175 $term = get_term( $term_id );
176 + $translations = $this->model->term->get_translations( $term_id );
206 177
207 - if ( $term instanceof WP_Term ) {
208 - $translations = $this->model->term->get_translations( $term_id );
178 + foreach ( $translations as $lang => $tr_id ) {
179 + if ( ! empty( $tr_id ) && $tr_id !== $term_id ) {
180 + $tr_parent = $this->model->term->get_translation( $term->parent, $lang );
181 + $wpdb->update(
182 + $wpdb->term_taxonomy,
183 + array( 'parent' => isset( $tr_parent ) ? $tr_parent : 0 ),
184 + array( 'term_taxonomy_id' => get_term( (int) $tr_id, $taxonomy )->term_taxonomy_id )
185 + );
209 186
210 - foreach ( $translations as $lang => $tr_id ) {
211 - if ( ! empty( $tr_id ) && $tr_id !== $term_id ) {
212 - $tr_parent = $this->model->term->get_translation( $term->parent, $lang );
213 - $tr_term = get_term( (int) $tr_id, $taxonomy );
214 -
215 - if ( $tr_term instanceof WP_Term ) {
216 - $wpdb->update(
217 - $wpdb->term_taxonomy,
218 - array( 'parent' => $tr_parent ? $tr_parent : 0 ),
219 - array( 'term_taxonomy_id' => $tr_term->term_taxonomy_id )
220 - );
221 -
222 - clean_term_cache( $tr_id, $taxonomy ); // OK since WP 3.9.
223 - }
224 - }
187 + clean_term_cache( $tr_id, $taxonomy ); // OK since WP 3.9
225 188 }
226 189 }
227 190 }
228 191 }
@@ -232,9 +195,8 @@
232 195 *
233 196 * @since 1.8
234 197 *
235 198 * @param int $post_id post id
236 - * @return void
237 199 */
238 200 public function edit_attachment( $post_id ) {
239 201 $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) );
240 202 }
@@ -239,15 +201,15 @@
239 201 $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) );
240 202 }
241 203
242 204 /**
243 - * Synchronize sticky posts.
205 + * Synchronize sticky posts
244 206 *
245 207 * @since 2.3
246 208 *
247 - * @param int[] $value New option value.
248 - * @param int[] $old_value Old option value.
249 - * @return int[]
209 + * @param array $value New option value
210 + * @param array $old_value Old option value
211 + * @return array
250 212 */
251 213 public function sync_sticky_posts( $value, $old_value ) {
252 214 if ( in_array( 'sticky_posts', $this->options['sync'] ) ) {
253 215 // Stick post