PluginProbe
Polylang / 3.1
Polylang v3.1
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-metas.php +57 -20 2.93.1 View file →
@@ -8,12 +8,35 @@
8 8 *
9 9 * @since 2.3
10 10 */
11 11 abstract class PLL_Sync_Metas {
12 + /**
13 + * @var PLL_Model
14 + */
12 15 public $model;
13 - protected $meta_type, $prev_value, $to_copy;
14 16
15 17 /**
18 + * Meta type. Typically 'post' or 'term'.
19 + *
20 + * @var string
21 + */
22 + protected $meta_type;
23 +
24 + /**
25 + * Stores the previous values when updating a meta.
26 + *
27 + * @var array
28 + */
29 + protected $prev_value;
30 +
31 + /**
32 + * Stores the metas to synchronize before deleting them.
33 + *
34 + * @var array
35 + */
36 + protected $to_copy;
37 +
38 + /**
16 39 * Constructor
17 40 *
18 41 * @since 2.3
19 42 *
@@ -34,8 +57,10 @@
34 57 /**
35 58 * Removes "added_{$this->meta_type}_meta" action
36 59 *
37 60 * @since 2.3
61 + *
62 + * @return void
38 63 */
39 64 protected function remove_add_meta_action() {
40 65 remove_action( "added_{$this->meta_type}_meta", array( $this, 'add_meta' ), 10, 4 );
41 66 }
@@ -43,8 +68,10 @@
43 68 /**
44 69 * Removes all meta synchronization actions and filters
45 70 *
46 71 * @since 2.3
72 + *
73 + * @return void
47 74 */
48 75 protected function remove_all_meta_actions() {
49 76 $this->remove_add_meta_action();
50 77
@@ -58,8 +85,10 @@
58 85 /**
59 86 * Adds "added_{$this->meta_type}_meta" action
60 87 *
61 88 * @since 2.3
89 + *
90 + * @return void
62 91 */
63 92 protected function restore_add_meta_action() {
64 93 add_action( "added_{$this->meta_type}_meta", array( $this, 'add_meta' ), 10, 4 );
65 94 }
@@ -67,8 +96,10 @@
67 96 /**
68 97 * Adds meta synchronization actions and filters
69 98 *
70 99 * @since 2.3
100 + *
101 + * @return void
71 102 */
72 103 protected function add_all_meta_actions() {
73 104 $this->restore_add_meta_action();
74 105
@@ -106,30 +137,30 @@
106 137 return apply_filters( "pll_translate_{$this->meta_type}_meta", maybe_unserialize( $value ), $key, $lang, $from, $to );
107 138 }
108 139
109 140 /**
110 - * Get the custom fields to copy or synchronize
141 + * Get the custom fields to copy or synchronize.
111 142 *
112 143 * @since 2.3
113 144 *
114 - * @param int $from Id of the post from which we copy informations
115 - * @param int $to Id of the post to which we paste informations
116 - * @param string $lang Language slug
117 - * @param bool $sync True if it is synchronization, false if it is a copy
118 - * @return array List of meta keys
145 + * @param int $from Id of the post from which we copy informations.
146 + * @param int $to Id of the post to which we paste informations.
147 + * @param string $lang Language slug.
148 + * @param bool $sync True if it is synchronization, false if it is a copy.
149 + * @return string[] List of meta keys.
119 150 */
120 151 protected function get_metas_to_copy( $from, $to, $lang, $sync = false ) {
121 152 /**
122 - * Filter the custom fields to copy or synchronize
153 + * Filters the custom fields to copy or synchronize.
123 154 *
124 155 * @since 0.6
125 156 * @since 1.9.2 The `$from`, `$to`, `$lang` parameters were added.
126 157 *
127 - * @param array $keys List of custom fields names
128 - * @param bool $sync True if it is synchronization, false if it is a copy
129 - * @param int $from Id of the post from which we copy informations
130 - * @param int $to Id of the post to which we paste informations
131 - * @param string $lang Language slug
158 + * @param string[] $keys List of custom fields names.
159 + * @param bool $sync True if it is synchronization, false if it is a copy.
160 + * @param int $from Id of the post from which we copy informations.
161 + * @param int $to Id of the post to which we paste informations.
162 + * @param string $lang Language slug.
132 163 */
133 164 return array_unique( apply_filters( "pll_copy_{$this->meta_type}_metas", array(), $sync, $from, $to, $lang ) );
134 165 }
135 166
@@ -167,8 +198,9 @@
167 198 * @param int $mid Meta id.
168 199 * @param int $id Object ID.
169 200 * @param string $meta_key Meta key.
170 201 * @param mixed $meta_value Meta value. Must be serializable if non-scalar.
202 + * @return void
171 203 */
172 204 public function add_meta( $mid, $id, $meta_key, $meta_value ) {
173 205 static $avoid_recursion = false;
174 206
@@ -218,8 +250,9 @@
218 250 * @param int $mid Meta id.
219 251 * @param int $id Object ID.
220 252 * @param string $meta_key Meta key.
221 253 * @param mixed $meta_value Meta value. Must be serializable if non-scalar.
254 + * @return void
222 255 */
223 256 public function update_meta( $mid, $id, $meta_key, $meta_value ) {
224 257 static $avoid_recursion = false;
225 258
@@ -250,14 +283,15 @@
250 283 }
251 284 }
252 285
253 286 /**
254 - * Store metas to synchronize before deleting them
287 + * Store metas to synchronize before deleting them.
255 288 *
256 289 * @since 2.3
257 290 *
258 - * @param array $mids Not used
291 + * @param int[] $mids Not used.
259 292 * @param int $id Object ID.
293 + * @return void
260 294 */
261 295 public function store_metas_to_sync( $mids, $id ) {
262 296 $tr_ids = $this->model->{$this->meta_type}->get_translations( $id );
263 297
@@ -266,16 +300,17 @@
266 300 }
267 301 }
268 302
269 303 /**
270 - * Synchronize deleted meta across translations
304 + * Synchronizes deleted meta across translations.
271 305 *
272 306 * @since 2.3
273 307 *
274 - * @param array $mids Not used
308 + * @param int[] $mids Not used.
275 309 * @param int $id Object ID.
276 310 * @param string $key Meta key.
277 311 * @param mixed $value Meta value.
312 + * @return void
278 313 */
279 314 public function delete_meta( $mids, $id, $key, $value ) {
280 315 static $avoid_recursion = false;
281 316
@@ -307,8 +342,9 @@
307 342 * @param int $from Id of the source object
308 343 * @param int $to Id of the target object
309 344 * @param string $lang Language code of the target object
310 345 * @param bool $sync Optional, defaults to true. True if it is synchronization, false if it is a copy
346 + * @return void
311 347 */
312 348 public function copy( $from, $to, $lang, $sync = false ) {
313 349 $this->remove_all_meta_actions();
314 350
@@ -356,11 +392,12 @@
356 392 * that saving a post (or term) will synchronize them.
357 393 *
358 394 * @since 2.3
359 395 *
360 - * @param int $object_id Id of the object being asaved
361 - * @param object $obj Not used
362 - * @param array $translations The list of translations object ids
396 + * @param int $object_id Id of the object being saved.
397 + * @param object $obj Not used.
398 + * @param int[] $translations The list of translations object ids.
399 + * @return void
363 400 */
364 401 public function save_object( $object_id, $obj, $translations ) {
365 402 foreach ( $translations as $tr_lang => $tr_id ) {
366 403 if ( $tr_id != $object_id ) {