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-tax.php +27 -47 3.02.8 View file →
@@ -10,20 +10,8 @@
10 10 */
11 11 class PLL_Sync_Tax {
12 12
13 13 /**
14 - * Stores the plugin options.
15 - *
16 - * @var array
17 - */
18 - protected $options;
19 -
20 - /**
21 - * @var PLL_Model
22 - */
23 - protected $model;
24 -
25 - /**
26 14 * Constructor
27 15 *
28 16 * @since 2.3
29 17 *
@@ -29,9 +17,9 @@
29 17 *
30 18 * @param object $polylang
31 19 */
32 20 public function __construct( &$polylang ) {
33 - $this->model = &$polylang->model;
21 + $this->model = &$polylang->model;
34 22 $this->options = &$polylang->options;
35 23
36 24 add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 );
37 25 add_action( 'pll_save_term', array( $this, 'create_term' ), 10, 3 );
@@ -39,18 +27,18 @@
39 27 add_action( 'delete_term', array( $this, 'delete_term' ) );
40 28 }
41 29
42 30 /**
43 - * Get the list of taxonomies to copy or to synchronize.
31 + * Get the list of taxonomies to copy or to synchronize
44 32 *
45 33 * @since 1.7
46 34 * @since 2.1 The `$from`, `$to`, `$lang` parameters were added.
47 35 *
48 - * @param bool $sync True if it is synchronization, false if it is a copy.
49 - * @param int $from Id of the post from which we copy informations, optional, defaults to null.
50 - * @param int $to Id of the post to which we paste informations, optional, defaults to null.
51 - * @param string $lang Language slug, optional, defaults to null.
52 - * @return string[] List of taxonomy names.
36 + * @param bool $sync True if it is synchronization, false if it is a copy
37 + * @param int $from Id of the post from which we copy informations, optional, defaults to null
38 + * @param int $to Id of the post to which we paste informations, optional, defaults to null
39 + * @param string $lang Language slug, optional, defaults to null
40 + * @return array List of taxonomy names
53 41 */
54 42 protected function get_taxonomies_to_copy( $sync, $from = null, $to = null, $lang = null ) {
55 43 $taxonomies = ! $sync || in_array( 'taxonomies', $this->options['sync'] ) ? $this->model->get_translated_taxonomies() : array();
56 44 if ( ! $sync || in_array( 'post_format', $this->options['sync'] ) ) {
@@ -57,18 +45,18 @@
57 45 $taxonomies[] = 'post_format';
58 46 }
59 47
60 48 /**
61 - * Filters the taxonomies to copy or synchronize.
49 + * Filter the taxonomies to copy or synchronize
62 50 *
63 51 * @since 1.7
64 52 * @since 2.1 The `$from`, `$to`, `$lang` parameters were added.
65 53 *
66 - * @param string[] $taxonomies List of taxonomy names.
67 - * @param bool $sync True if it is synchronization, false if it is a copy.
68 - * @param int $from Id of the post from which we copy informations.
69 - * @param int $to Id of the post to which we paste informations.
70 - * @param string $lang Language slug.
54 + * @param array $taxonomies List of taxonomy names
55 + * @param bool $sync True if it is synchronization, false if it is a copy
56 + * @param int $from Id of the post from which we copy informations
57 + * @param int $to Id of the post to which we paste informations
58 + * @param string $lang Language slug
71 59 */
72 60 return array_unique( apply_filters( 'pll_copy_taxonomies', $taxonomies, $sync, $from, $to, $lang ) );
73 61 }
74 62
@@ -76,13 +64,13 @@
76 64 * When copying or synchronizing terms, translate terms in translatable taxonomies
77 65 *
78 66 * @since 2.3
79 67 *
80 - * @param int $object_id Object ID.
81 - * @param int[] $terms List of terms ids assigned to the source post.
82 - * @param string $taxonomy Taxonomy name.
83 - * @param string $lang Language slug.
84 - * @return int[] List of terms ids to assign to the target post.
68 + * @param array $object_id Object ID
69 + * @param array $terms List of terms ids assigned to the source post
70 + * @param string $taxonomy Taxonomy name
71 + * @param string $lang Language slug
72 + * @return array List of terms ids to assign to the target post
85 73 */
86 74 protected function maybe_translate_terms( $object_id, $terms, $taxonomy, $lang ) {
87 75 if ( is_array( $terms ) && $this->model->is_translated_taxonomy( $taxonomy ) ) {
88 76 $newterms = array();
@@ -115,9 +103,9 @@
115 103 return $terms; // Empty $terms or untranslated taxonomy
116 104 }
117 105
118 106 /**
119 - * Maybe copy taxonomy terms from one post to the other.
107 + * Maybe copy taxonomy terms from one post to the other
120 108 *
121 109 * @since 2.6
122 110 *
123 111 * @param int $object_id Source object ID.
@@ -125,9 +113,8 @@
125 113 * @param string $lang Target language.
126 114 * @param array $terms An array of object terms.
127 115 * @param string $taxonomy Taxonomy slug.
128 116 * @param bool $append Whether to append new terms to the old terms.
129 - * @return void
130 117 */
131 118 protected function copy_object_terms( $object_id, $tr_id, $lang, $terms, $taxonomy, $append ) {
132 119 $to_copy = $this->get_taxonomies_to_copy( true, $object_id, $tr_id, $lang );
133 120
@@ -151,18 +138,17 @@
151 138
152 139 }
153 140
154 141 /**
155 - * When assigning terms to a post, assign translated terms to the translated posts (synchronisation).
142 + * When assigning terms to a post, assign translated terms to the translated posts (synchronisation)
156 143 *
157 144 * @since 2.3
158 145 *
159 146 * @param int $object_id Object ID.
160 147 * @param array $terms An array of object terms.
161 - * @param int[] $tt_ids An array of term taxonomy IDs.
148 + * @param array $tt_ids An array of term taxonomy IDs.
162 149 * @param string $taxonomy Taxonomy slug.
163 150 * @param bool $append Whether to append new terms to the old terms.
164 - * @return void
165 151 */
166 152 public function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append ) {
167 153 static $avoid_recursion = false;
168 154 $taxonomy_object = get_taxonomy( $taxonomy );
@@ -167,9 +153,9 @@
167 153 static $avoid_recursion = false;
168 154 $taxonomy_object = get_taxonomy( $taxonomy );
169 155
170 156 // Make sure that the taxonomy is registered for a post type
171 - if ( ! $avoid_recursion && ! empty( $taxonomy_object ) && array_filter( $taxonomy_object->object_type, 'post_type_exists' ) ) {
157 + if ( ! $avoid_recursion && array_filter( $taxonomy_object->object_type, 'post_type_exists' ) ) {
172 158 $avoid_recursion = true;
173 159
174 160 $tr_ids = $this->model->post->get_translations( $object_id );
175 161
@@ -206,9 +192,8 @@
206 192 *
207 193 * @param int $from Id of the source post
208 194 * @param int $to Id of the target post
209 195 * @param string $lang Language slug
210 - * @return void
211 196 */
212 197 public function copy( $from, $to, $lang ) {
213 198 remove_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 6 );
214 199
@@ -215,9 +200,9 @@
215 200 // Get taxonomies to sync for this post type
216 201 $taxonomies = array_intersect( get_post_taxonomies( $from ), $this->get_taxonomies_to_copy( false, $from, $to, $lang ) );
217 202
218 203 // Update the term cache to reduce the number of queries in the loop
219 - update_object_term_cache( array( $from ), get_post_type( $from ) );
204 + update_object_term_cache( $from, get_post_type( $from ) );
220 205
221 206 // Copy
222 207 foreach ( $taxonomies as $tax ) {
223 208 if ( $terms = get_the_terms( $from, $tax ) ) {
@@ -233,16 +218,15 @@
233 218 add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 6 );
234 219 }
235 220
236 221 /**
237 - * When creating a new term, associate it to posts having translations associated to the translated terms.
222 + * When creating a new term, associate it to posts having translations associated to the translated terms
238 223 *
239 224 * @since 2.3
240 225 *
241 - * @param int $term_id Id of the created term.
242 - * @param string $taxonomy Taxonomy.
243 - * @param int[] $translations Ids of the translations of the created term.
244 - * @return void
226 + * @param int $term_id Id of the created term
227 + * @param string $taxonomy Taxonomy
228 + * @param array $translations Ids of the translations of the created term
245 229 */
246 230 public function create_term( $term_id, $taxonomy, $translations ) {
247 231 if ( doing_action( 'create_term' ) && in_array( $taxonomy, $this->get_taxonomies_to_copy( true ) ) ) {
248 232 // Get all posts associated to the translated terms
@@ -289,10 +273,8 @@
289 273 * Deactivate the synchronization of terms before deleting a term
290 274 * to avoid translated terms to be removed from translated posts
291 275 *
292 276 * @since 2.3.2
293 - *
294 - * @return void
295 277 */
296 278 public function pre_delete_term() {
297 279 remove_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 );
298 280 }
@@ -300,10 +282,8 @@
300 282 /**
301 283 * Re-activate the synchronization of terms after a term is deleted
302 284 *
303 285 * @since 2.3.2
304 - *
305 - * @return void
306 286 */
307 287 public function delete_term() {
308 288 add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 );
309 289 }