PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / trunk
Advanced Custom Fields: Extended vtrunk
0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / modules / performance / module-performance-connector.php
acf-extended / includes / modules / performance Last commit date
module-performance-connector.php 1 month ago module-performance-functions.php 1 month ago module-performance-ui.php 3 years ago module-performance-ultra-fields.php 2 years ago module-performance-ultra-revisions.php 1 month ago module-performance-ultra.php 1 month ago module-performance-upgrades.php 2 years ago module-performance.php 1 month ago
module-performance-connector.php
378 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_performance_connector')):
8
9 class acfe_performance_connector{
10
11 var $bypass = false;
12
13 /**
14 * construct
15 */
16 function __construct(){
17
18 // hooks
19 add_filter('acf/pre_load_meta', array($this, 'pre_load_meta'), 1000, 2);
20 add_filter('acf/pre_load_metadata', array($this, 'pre_load_metadata'), 1000, 4);
21 add_filter('acfe/delete_orphan_meta', array($this, 'delete_orphan_meta'), 10, 3);
22
23 }
24
25
26 /**
27 * pre_load_meta
28 *
29 * Preload get_fields() from other engines if meta of current engine are missing
30 *
31 * @param $return
32 * @param $post_id
33 *
34 * @hook acf/pre_load_meta:1000
35 *
36 * @function acf_get_meta() + get_fields()
37 *
38 * @return array|mixed|null
39 */
40 function pre_load_meta($return, $post_id){
41
42 // value already found
43 if($return !== null){
44 return $return;
45 }
46
47 // disabled module
48 if(!$this->is_enabled($post_id)){
49 return $return;
50 }
51
52 // get engines
53 $engines = acfe_get_object_performance_other_engines($post_id);
54
55 // loop
56 foreach($engines as $engine){
57
58 // 'acf' meta found on object
59 if($engine->get_meta($post_id)){
60
61 $preload = $engine->do_pre_load_meta($return, $post_id);
62
63 if($preload !== null){
64 return $preload;
65 }
66
67 }
68
69 }
70
71 return $return;
72
73 }
74
75
76 /**
77 * pre_load_metadata
78 *
79 * Preload metadata from other engines if meta value from current engine is missing
80 *
81 * @param $return
82 * @param $post_id
83 * @param $name
84 * @param $hidden
85 *
86 * @hook acf/pre_load_metadata:1000
87 *
88 * @function acf_get_metadata() + acf_get_value()
89 *
90 * @return mixed
91 */
92 function pre_load_metadata($return, $post_id, $name, $hidden){
93
94 // value already found
95 if($return !== null){
96 return $return;
97 }
98
99 // disabled module
100 if(!$this->is_enabled($post_id) || $this->bypass){
101 return $return;
102 }
103
104 // vars
105 $this->bypass = true;
106 $engines = acfe_get_object_performance_other_engines($post_id);
107
108 // loop
109 foreach($engines as $engine){
110
111 // 'acf' meta found on object
112 if($engine->get_meta($post_id)){
113
114 $preload = $engine->do_pre_load_metadata($return, $post_id, $name, $hidden);
115
116 if($preload !== null){
117 $return = $preload;
118 break;
119 }
120
121 }
122
123 }
124
125 $this->bypass = false;
126
127 // return
128 return $return;
129
130 }
131
132
133 /**
134 * delete_orphan_meta
135 *
136 * @param $return
137 * @param $post_id
138 * @param $confirm
139 *
140 * @return array[]
141 */
142 function delete_orphan_meta($return, $post_id, $confirm){
143
144 // engine name
145 $engine_name = acfe_get_object_performance_engine_name($post_id);
146
147 // performance enabled
148 if(acfe_is_object_performance_enabled($post_id)){
149
150 // engine
151 $performance_mode = acfe_get_object_performance_mode($post_id);
152 $engine = acfe_get_performance_engine($engine_name);
153
154 // performance deleted
155 $performance_deleted = $return['normal'];
156 $performance_key = $engine->get_meta_key($post_id);
157
158 // reset return
159 $return = array(
160 'normal' => array(),
161 );
162
163 // if engine = hybrid
164 // previous 'clean meta' cleaned reference + meta in the whole '$performance_deleted'
165 // we must fix that by moving non prefixed meta into normal return
166 if($engine_name === 'hybrid'){
167
168 foreach(array_keys($performance_deleted) as $key){
169
170 $value = $performance_deleted[ $key ];
171
172 // prefixed meta
173 if(strpos($key, '_') !== 0){
174
175 $return['normal'][ $key ] = $value;
176 unset($performance_deleted[ $key ]);
177
178 }
179
180 }
181
182 }
183
184 if(!empty($performance_deleted)){
185 $return[ $performance_key ] = $performance_deleted;
186 }
187
188 // clean normal orphan
189 // this will clean orphan from normal meta
190 $normal_deleted = acfe_do_performance_bypass(function($post_id, $confirm){
191
192 // get orphan
193 $meta = acfe_get_orphan_meta($post_id);
194 $deleted = array();
195
196 // loop
197 foreach($meta as $row){
198
199 // vars
200 $key = $row['key'];
201 $name = $row['name'];
202 $value = $row['value'];
203
204 // delete
205 if($confirm){
206
207 acf_delete_metadata($post_id, $name, true); // prefix
208 acf_delete_metadata($post_id, $name); // normal
209
210 }
211
212 // store
213 $deleted[ "_{$name}" ] = $key;
214 $deleted[ $name ] = $value;
215
216 }
217
218 return $deleted;
219
220 }, array($post_id, $confirm));
221
222 // return
223 $return['normal'] = array_merge($return['normal'], $normal_deleted);
224
225 // clean normal meta
226 // this will clean normal meta which should be removed in mode=production
227 if($performance_mode === 'production'){
228
229 $normal_deleted = acfe_do_performance_bypass(function($post_id, $confirm){
230
231 // meta (acf / _acf)
232 $acf = acfe_get_object_performance_meta($post_id);
233
234 $engine_name = acfe_get_object_performance_engine_name($post_id);
235
236 // performance meta doesn't exist
237 // mode=rollback was probably used
238 if($acf === null){
239 return array();
240 }
241
242 // get orphan
243 $meta = acfe_get_meta($post_id);
244 $deleted = array();
245
246 // loop
247 foreach($meta as $row){
248
249 // vars
250 $field = $row['field'];
251 $key = $row['key'];
252 $name = $row['name'];
253 $value = $row['value'];
254
255 switch($engine_name){
256
257 case 'ultra': {
258
259 // check if field has 'save as individual meta' and already in 'acf' meta
260 if(!acfe_get($field, 'acfe_save_meta') || !isset($acf[ $name ])){
261
262 // delete
263 if($confirm){
264
265 acf_delete_metadata($post_id, $name, true); // prefix
266 acf_delete_metadata($post_id, $name); // normal
267
268 }
269
270 // store
271 $deleted[ "_{$name}" ] = $key;
272 $deleted[ $name ] = $value;
273
274 }
275
276 break;
277 }
278
279 case 'hybrid': {
280
281 // delete
282 if($confirm){
283 acf_delete_metadata($post_id, $name, true); // prefix
284 }
285
286 // store
287 $deleted[ "_{$name}" ] = $key;
288
289 break;
290 }
291
292 }
293
294 }
295
296 return $deleted;
297
298 }, array($post_id, $confirm));
299
300 // return
301 $return['normal'] = array_merge($return['normal'], $normal_deleted);
302
303 }
304
305 }
306
307 // this is done on
308 // performance enabled +
309 // performance disabled
310
311 // not ultra
312 if($engine_name !== 'ultra'){
313
314 // ultra engine
315 $ultra = acfe_get_performance_engine('ultra');
316
317 if($ultra){
318
319 // meta key
320 $meta_key = $ultra->get_meta_key($post_id);
321
322 // clean ultra residue (acf)
323 $meta = $ultra->get_meta($post_id);
324
325 if($meta !== null){
326 $ultra->delete_meta($post_id);
327 $return['normal'][ $meta_key ] = $meta;
328 }
329
330 }
331
332 }
333
334 // not hybrid
335 if($engine_name !== 'hybrid'){
336
337 // hybrid engine
338 $hybrid = acfe_get_performance_engine('hybrid');
339
340 if($hybrid){
341
342 // meta key
343 $meta_key = $hybrid->get_meta_key($post_id);
344
345 // clean hybrid residue (_acf)
346 $meta = $hybrid->get_meta($post_id);
347
348 if($meta !== null){
349 $hybrid->delete_meta($post_id);
350 $return['normal'][ $meta_key ] = $meta;
351 }
352
353 }
354
355 }
356
357 // return
358 return $return;
359
360 }
361
362
363 /**
364 * is_enabled
365 *
366 * @param $post_id
367 *
368 * @return bool
369 */
370 function is_enabled($post_id = 0){
371 return acfe_is_object_performance_enabled($post_id);
372 }
373
374 }
375
376 acf_new_instance('acfe_performance_connector');
377
378 endif;