@@ -11,7 +11,7 @@ class BEA_CSF_Addon_ACF {
11
11
* BEA_CSF_Addon_ACF constructor.
12
12
*/
13
13
public function __construct () {
14
- if ( ! class_exists ('acf ' ) ) {
14
+ if ( ! class_exists ( 'acf ' ) ) {
15
15
return false ;
16
16
}
17
17
@@ -47,7 +47,7 @@ public static function bea_csf_client_posttype_merge( $data, $sync_fields, $new_
47
47
$ fields = array ();
48
48
foreach ( $ groups as $ group ) {
49
49
$ _fields = (array ) acf_get_fields ( $ group );
50
- foreach ($ _fields as $ _field ) {
50
+ foreach ( $ _fields as $ _field ) {
51
51
$ fields [] = $ _field ;
52
52
}
53
53
}
@@ -62,7 +62,7 @@ public static function bea_csf_client_posttype_merge( $data, $sync_fields, $new_
62
62
63
63
// Translate
64
64
$ meta_data_to_update = self ::translate_dynamic_acf_fields ( $ data ['meta_data ' ], $ data , $ sync_fields );
65
- if ( is_array ($ meta_data_to_update ) && !empty ($ meta_data_to_update ) ) {
65
+ if ( is_array ( $ meta_data_to_update ) && ! empty ( $ meta_data_to_update ) ) {
66
66
foreach ( $ meta_data_to_update as $ meta_data_to_update_key => $ meta_data_to_update_value ) {
67
67
update_post_meta ( $ new_post ->ID , $ meta_data_to_update_key , $ meta_data_to_update_value );
68
68
}
@@ -95,7 +95,7 @@ public static function bea_csf_client_taxonomy_merge( $data, $sync_fields, $new_
95
95
$ fields = array ();
96
96
foreach ( $ groups as $ group ) {
97
97
$ _fields = (array ) acf_get_fields ( $ group );
98
- foreach ($ _fields as $ _field ) {
98
+ foreach ( $ _fields as $ _field ) {
99
99
$ fields [] = $ _field ;
100
100
}
101
101
}
@@ -110,7 +110,7 @@ public static function bea_csf_client_taxonomy_merge( $data, $sync_fields, $new_
110
110
111
111
// Translate
112
112
$ meta_data_to_update = self ::translate_dynamic_acf_fields ( $ data ['meta_data ' ], $ data , $ sync_fields );
113
- if ( is_array ($ meta_data_to_update ) && !empty ($ meta_data_to_update ) ) {
113
+ if ( is_array ( $ meta_data_to_update ) && ! empty ( $ meta_data_to_update ) ) {
114
114
foreach ( $ meta_data_to_update as $ meta_data_to_update_key => $ meta_data_to_update_value ) {
115
115
update_term_meta ( $ new_term ->term_id , $ meta_data_to_update_key , $ meta_data_to_update_value );
116
116
}
@@ -139,57 +139,57 @@ public static function translate_dynamic_acf_fields( $meta_data, $data, $sync_fi
139
139
}
140
140
141
141
// Keep only metadata with ID database reference
142
- if ( !isset (self ::$ acf_fields [$ values [0 ]] ) ) {
142
+ if ( ! isset ( self ::$ acf_fields [ $ values [0 ] ] ) ) {
143
143
continue ;
144
144
}
145
145
146
146
// Get ACF field data
147
- $ acf_field = self ::$ acf_fields [$ values [0 ]];
147
+ $ acf_field = self ::$ acf_fields [ $ values [0 ] ];
148
148
149
149
// Build meta_key to metadata to translate
150
- $ meta_key_to_translate = substr ($ key , 1 ) ;
150
+ $ meta_key_to_translate = substr ( $ key , 1 ) ;
151
151
152
152
// Get data to translate
153
- $ meta_value_to_translate = maybe_unserialize ($ meta_data [$ meta_key_to_translate ][0 ]);
153
+ $ meta_value_to_translate = maybe_unserialize ( $ meta_data [ $ meta_key_to_translate ][0 ] );
154
154
155
155
$ types = false ;
156
- if ( in_array ($ acf_field ['type ' ], array ('image ' , 'post_object ' , 'file ' , 'page_link ' , 'gallery ' , 'relationship ' ) ) ) {
157
- $ types = array ('attachment ' , 'posttype ' );
158
- } elseif ( in_array ($ acf_field ['type ' ], array ('taxonomy ' ) ) ) {
159
- $ types = array ('taxonomy ' );
156
+ if ( in_array ( $ acf_field ['type ' ], array ( 'image ' , 'post_object ' , 'file ' , 'page_link ' , 'gallery ' , 'relationship ' ) ) ) {
157
+ $ types = array ( 'attachment ' , 'posttype ' );
158
+ } elseif ( in_array ( $ acf_field ['type ' ], array ( 'taxonomy ' ) ) ) {
159
+ $ types = array ( 'taxonomy ' );
160
160
}
161
161
162
162
// Array or singular value ?
163
- if ( is_array ($ meta_value_to_translate ) ) {
164
- foreach ( $ meta_value_to_translate as $ _key => $ _value ) {
163
+ if ( is_array ( $ meta_value_to_translate ) ) {
164
+ foreach ( $ meta_value_to_translate as $ _key => $ _value ) {
165
165
$ object_id = BEA_CSF_Relations::get_object_for_any ( $ types , $ data ['blogid ' ], $ sync_fields ['_current_receiver_blog_id ' ], $ _value , $ _value );
166
166
// If relation not exist, try to check if the parent relation is an synchronized content for get an indirect relation
167
167
if ( empty ( $ object_id ) || (int ) $ object_id == 0 ) {
168
- $ parent_relation = BEA_CSF_Relations::current_object_is_synchronized ($ types , $ data ['blogid ' ], $ meta_value_to_translate );
168
+ $ parent_relation = BEA_CSF_Relations::current_object_is_synchronized ( $ types , $ data ['blogid ' ], $ meta_value_to_translate );
169
169
if ( $ parent_relation != false ) {
170
170
$ object_id = BEA_CSF_Relations::get_object_for_any ( $ types , $ parent_relation ->emitter_blog_id , $ sync_fields ['_current_receiver_blog_id ' ], $ parent_relation ->emitter_id , $ parent_relation ->emitter_id );
171
171
}
172
172
}
173
173
174
174
if ( ! empty ( $ object_id ) && (int ) $ object_id > 0 ) {
175
- $ meta_value_to_translate [$ _key ] = $ object_id ;
175
+ $ meta_value_to_translate [ $ _key ] = $ object_id ;
176
176
}
177
177
}
178
178
179
- $ meta_data_to_update [$ meta_key_to_translate ] = $ meta_value_to_translate ;
179
+ $ meta_data_to_update [ $ meta_key_to_translate ] = $ meta_value_to_translate ;
180
180
} else {
181
181
$ object_id = BEA_CSF_Relations::get_object_for_any ( $ types , $ data ['blogid ' ], $ sync_fields ['_current_receiver_blog_id ' ], $ meta_value_to_translate , $ meta_value_to_translate );
182
182
// If relation not exist, try to check if the parent relation is an synchronized content for get an indirect relation
183
183
if ( empty ( $ object_id ) || (int ) $ object_id == 0 ) {
184
- $ parent_relation = BEA_CSF_Relations::current_object_is_synchronized ($ types , $ data ['blogid ' ], $ meta_value_to_translate );
184
+ $ parent_relation = BEA_CSF_Relations::current_object_is_synchronized ( $ types , $ data ['blogid ' ], $ meta_value_to_translate );
185
185
if ( $ parent_relation != false ) {
186
186
$ object_id = BEA_CSF_Relations::get_object_for_any ( $ types , $ parent_relation ->emitter_blog_id , $ sync_fields ['_current_receiver_blog_id ' ], $ parent_relation ->emitter_id , $ parent_relation ->emitter_id );
187
187
188
188
}
189
189
}
190
190
191
191
if ( ! empty ( $ object_id ) && (int ) $ object_id > 0 ) {
192
- $ meta_data_to_update [$ meta_key_to_translate ] = $ object_id ;
192
+ $ meta_data_to_update [ $ meta_key_to_translate ] = $ object_id ;
193
193
}
194
194
}
195
195
}
@@ -204,13 +204,13 @@ public static function translate_dynamic_acf_fields( $meta_data, $data, $sync_fi
204
204
*/
205
205
public static function prepare_acf_fields ( $ fields ) {
206
206
foreach ( (array ) $ fields as $ field ) {
207
- if (in_array ($ field ['type ' ], array ('flexible_content ' ) ) ) { // Flexible is recursive structure with layouts
208
- foreach ( $ field ['layouts ' ] as $ layout_field ) {
207
+ if ( in_array ( $ field ['type ' ], array ( 'flexible_content ' ) ) ) { // Flexible is recursive structure with layouts
208
+ foreach ( $ field ['layouts ' ] as $ layout_field ) {
209
209
self ::prepare_acf_fields ( $ layout_field ['sub_fields ' ] );
210
210
}
211
- } elseif (in_array ($ field ['type ' ], array ('repeater ' , 'group ' ) ) ) { // Repeater is recursive structure
211
+ } elseif ( in_array ( $ field ['type ' ], array ( 'repeater ' , 'group ' ) ) ) { // Repeater is recursive structure
212
212
self ::prepare_acf_fields ( $ field ['sub_fields ' ] );
213
- } elseif ( in_array ($ field ['type ' ], array ('image ' , 'gallery ' , 'post_object ' , 'relationship ' , 'file ' , 'page_link ' , 'taxonomy ' ) ) ) {
213
+ } elseif ( in_array ( $ field ['type ' ], array ( 'image ' , 'gallery ' , 'post_object ' , 'relationship ' , 'file ' , 'page_link ' , 'taxonomy ' ) ) ) {
214
214
self ::$ acf_fields [ $ field ['key ' ] ] = $ field ;
215
215
}
216
216
}
0 commit comments