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