PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 +58 -23 2.9.13.6.7 View file →
@@ -8,16 +8,41 @@
8 8 *
9 9 * @since 2.4
10 10 */
11 11 class PLL_Sync {
12 - public $taxonomies, $post_metas, $term_meta;
12 + /**
13 + * @var PLL_Sync_Tax
14 + */
15 + public $taxonomies;
13 16
14 17 /**
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 + /**
15 40 * Constructor
16 41 *
17 42 * @since 1.2
18 43 *
19 - * @param object $polylang
44 + * @param object $polylang The Polylang object.
20 45 */
21 46 public function __construct( &$polylang ) {
22 47 $this->model = &$polylang->model;
23 48 $this->options = &$polylang->options;
@@ -44,13 +69,13 @@
44 69 add_filter( 'pre_update_option_sticky_posts', array( $this, 'sync_sticky_posts' ), 10, 2 );
45 70 }
46 71
47 72 /**
48 - * Get post fields to synchornize
73 + * Get post fields to synchronize.
49 74 *
50 75 * @since 2.4
51 76 *
52 - * @param object $post Post object
77 + * @param WP_Post $post Post object.
53 78 * @return array
54 79 */
55 80 protected function get_fields_to_sync( $post ) {
56 81 $postarr = array();
@@ -118,15 +143,16 @@
118 143 return $data;
119 144 }
120 145
121 146 /**
122 - * Synchronizes post fields in translations
147 + * Synchronizes post fields in translations.
123 148 *
124 149 * @since 2.4
125 150 *
126 - * @param int $post_id post id
127 - * @param object $post post object
128 - * @param array $translations post translations
151 + * @param int $post_id Post id.
152 + * @param WP_Post $post Post object.
153 + * @param int[] $translations Post translations.
154 + * @return void
129 155 */
130 156 public function pll_save_post( $post_id, $post, $translations ) {
131 157 global $wpdb;
132 158
@@ -141,9 +167,9 @@
141 167
142 168 $tr_arr = $postarr;
143 169 unset( $tr_arr['post_parent'] );
144 170
145 - // Do not udpate the translation parent if the user set a parent with no translation.
171 + // Do not update the translation parent if the user set a parent with no translation.
146 172 if ( isset( $postarr['post_parent'] ) ) {
147 173 $post_parent = $postarr['post_parent'] ? $this->model->post->get_translation( $postarr['post_parent'], $lang ) : 0;
148 174 if ( ! ( $postarr['post_parent'] && ! $post_parent ) ) {
149 175 $tr_arr['post_parent'] = $post_parent;
@@ -169,8 +195,9 @@
169 195 *
170 196 * @param int $term_id Term id.
171 197 * @param int $tt_id Term taxonomy id, not used.
172 198 * @param string $taxonomy Taxonomy name.
199 + * @return void
173 200 */
174 201 public function sync_term_parent( $term_id, $tt_id, $taxonomy ) {
175 202 global $wpdb;
176 203
@@ -175,20 +202,27 @@
175 202 global $wpdb;
176 203
177 204 if ( is_taxonomy_hierarchical( $taxonomy ) && $this->model->is_translated_taxonomy( $taxonomy ) ) {
178 205 $term = get_term( $term_id );
179 - $translations = $this->model->term->get_translations( $term_id );
180 206
181 - 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 );
184 - $wpdb->update(
185 - $wpdb->term_taxonomy,
186 - array( 'parent' => isset( $tr_parent ) ? $tr_parent : 0 ),
187 - array( 'term_taxonomy_id' => get_term( (int) $tr_id, $taxonomy )->term_taxonomy_id )
188 - );
207 + if ( $term instanceof WP_Term ) {
208 + $translations = $this->model->term->get_translations( $term_id );
189 209
190 - clean_term_cache( $tr_id, $taxonomy ); // OK since WP 3.9
210 + foreach ( $translations as $lang => $tr_id ) {
211 + if ( $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 && ! ( $term->parent && empty( $tr_parent ) ) ) {
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 + }
191 225 }
192 226 }
193 227 }
194 228 }
@@ -198,8 +232,9 @@
198 232 *
199 233 * @since 1.8
200 234 *
201 235 * @param int $post_id post id
236 + * @return void
202 237 */
203 238 public function edit_attachment( $post_id ) {
204 239 $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) );
205 240 }
@@ -204,15 +239,15 @@
204 239 $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) );
205 240 }
206 241
207 242 /**
208 - * Synchronize sticky posts
243 + * Synchronize sticky posts.
209 244 *
210 245 * @since 2.3
211 246 *
212 - * @param array $value New option value
213 - * @param array $old_value Old option value
214 - * @return array
247 + * @param int[] $value New option value.
248 + * @param int[] $old_value Old option value.
249 + * @return int[]
215 250 */
216 251 public function sync_sticky_posts( $value, $old_value ) {
217 252 if ( in_array( 'sticky_posts', $this->options['sync'] ) ) {
218 253 // Stick post