PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.0
GiveWP – Donation Plugin and Fundraising Platform v2.2.0
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / payments / backward-compatibility.php
give / includes / payments Last commit date
actions.php 8 years ago backward-compatibility.php 8 years ago class-give-payment.php 7 years ago class-give-sequential-donation-number.php 8 years ago class-payment-stats.php 7 years ago class-payments-query.php 8 years ago functions.php 7 years ago
backward-compatibility.php
707 lines
1 <?php
2 /**
3 * Split _give_payment_meta to new Give core meta_keys.
4 *
5 * @since 2.0
6 *
7 * @param $object_id
8 * @param array $meta_value
9 *
10 * @return void
11 */
12 function _give_20_bc_split_and_save_give_payment_meta( $object_id, $meta_value ) {
13 // Bailout
14 if ( empty( $meta_value ) ) {
15 return;
16 } elseif ( ! is_array( $meta_value ) ) {
17 $meta_value = array();
18 }
19
20 remove_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10 );
21
22 // Date payment meta.
23 if ( ! empty( $meta_value['date'] ) ) {
24 give_update_meta( $object_id, '_give_payment_date', $meta_value['date'] );
25 }
26
27 // Currency payment meta.
28 if ( ! empty( $meta_value['currency'] ) ) {
29 give_update_meta( $object_id, '_give_payment_currency', $meta_value['currency'] );
30 }
31
32 // User information.
33 if ( ! empty( $meta_value['user_info'] ) ) {
34 // Donor first name.
35 if ( ! empty( $meta_value['user_info']['first_name'] ) ) {
36 give_update_meta( $object_id, '_give_donor_billing_first_name', $meta_value['user_info']['first_name'] );
37 }
38
39 // Donor last name.
40 if ( ! empty( $meta_value['user_info']['last_name'] ) ) {
41 give_update_meta( $object_id, '_give_donor_billing_last_name', $meta_value['user_info']['last_name'] );
42 }
43
44 // Donor address payment meta.
45 if ( ! empty( $meta_value['user_info']['address'] ) ) {
46
47 // Address1.
48 if ( ! empty( $meta_value['user_info']['address']['line1'] ) ) {
49 give_update_meta( $object_id, '_give_donor_billing_address1', $meta_value['user_info']['address']['line1'] );
50 }
51
52 // Address2.
53 if ( ! empty( $meta_value['user_info']['address']['line2'] ) ) {
54 give_update_meta( $object_id, '_give_donor_billing_address2', $meta_value['user_info']['address']['line2'] );
55 }
56
57 // City.
58 if ( ! empty( $meta_value['user_info']['address']['city'] ) ) {
59 give_update_meta( $object_id, '_give_donor_billing_city', $meta_value['user_info']['address']['city'] );
60 }
61
62 // Zip.
63 if ( ! empty( $meta_value['user_info']['address']['zip'] ) ) {
64 give_update_meta( $object_id, '_give_donor_billing_zip', $meta_value['user_info']['address']['zip'] );
65 }
66
67 // State.
68 if ( ! empty( $meta_value['user_info']['address']['state'] ) ) {
69 give_update_meta( $object_id, '_give_donor_billing_state', $meta_value['user_info']['address']['state'] );
70 }
71
72 // Country.
73 if ( ! empty( $meta_value['user_info']['address']['country'] ) ) {
74 give_update_meta( $object_id, '_give_donor_billing_country', $meta_value['user_info']['address']['country'] );
75 }
76 }
77 }// End if().
78
79 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
80 }
81
82 /**
83 * Add backward compatibility to get meta value of _give_payment_meta meta key.
84 *
85 * @since 2.0
86 *
87 * @param $object_id
88 * @param array $meta_value
89 *
90 * @return array
91 */
92 function _give_20_bc_give_payment_meta_value( $object_id, $meta_value ) {
93 $cache_key = "_give_payment_meta_{$object_id}";
94 $cache = Give_Cache::get_db_query( $cache_key );
95
96 if ( ! is_null( $cache ) ) {
97 return $cache;
98 }
99
100 // Set default value to array.
101 if ( ! is_array( $meta_value ) ) {
102 $meta_value = array();
103 }
104
105 // Donation key.
106 $meta_value['key'] = give_get_meta( $object_id, '_give_payment_purchase_key', true );
107
108 // Donation form.
109 $meta_value['form_title'] = give_get_meta( $object_id, '_give_payment_form_title', true );
110
111 // Donor email.
112 $meta_value['email'] = give_get_meta( $object_id, '_give_payment_donor_email', true );
113 $meta_value['email'] = ! empty( $meta_value['email'] ) ?
114 $meta_value['email'] :
115 Give()->donors->get_column( 'email', give_get_payment_donor_id( $object_id ) );
116
117 // Form id.
118 $meta_value['form_id'] = give_get_meta( $object_id, '_give_payment_form_id', true );
119
120 // Price id.
121 $meta_value['price_id'] = give_get_meta( $object_id, '_give_payment_price_id', true );
122
123 // Date.
124 $meta_value['date'] = give_get_meta( $object_id, '_give_payment_date', true );
125 $meta_value['date'] = ! empty( $meta_value['date'] ) ?
126 $meta_value['date'] :
127 get_post_field( 'post_date', $object_id );
128
129 // Currency.
130 $meta_value['currency'] = give_get_meta( $object_id, '_give_payment_currency', true );
131
132 // Decode donor data.
133 $donor_names = give_get_donor_name_by( give_get_meta( $object_id, '_give_payment_donor_id', true ), 'donor' );
134 $donor_names = explode( ' ', $donor_names, 2 );
135
136 // Donor first name.
137 $donor_data['first_name'] = give_get_meta( $object_id, '_give_donor_billing_first_name', true );
138 $donor_data['first_name'] = ! empty( $donor_data['first_name'] ) ?
139 $donor_data['first_name'] :
140 $donor_names[0];
141
142 // Donor last name.
143 $donor_data['last_name'] = give_get_meta( $object_id, '_give_donor_billing_last_name', true );
144 $donor_data['last_name'] = ! empty( $donor_data['last_name'] ) ?
145 $donor_data['last_name'] :
146 ( isset( $donor_names[1] ) ? $donor_names[1] : '' );
147
148 // Donor email.
149 $donor_data['email'] = $meta_value['email'];
150
151 // User ID.
152 $donor_data['id'] = give_get_payment_user_id( $object_id );
153
154 $donor_data['address'] = false;
155
156 // Address1.
157 if ( $address1 = give_get_meta( $object_id, '_give_donor_billing_address1', true ) ) {
158 $donor_data['address']['line1'] = $address1;
159 }
160
161 // Address2.
162 if ( $address2 = give_get_meta( $object_id, '_give_donor_billing_address2', true ) ) {
163 $donor_data['address']['line2'] = $address2;
164 }
165
166 // City.
167 if ( $city = give_get_meta( $object_id, '_give_donor_billing_city', true ) ) {
168 $donor_data['address']['city'] = $city;
169 }
170
171 // Zip.
172 if ( $zip = give_get_meta( $object_id, '_give_donor_billing_zip', true ) ) {
173 $donor_data['address']['zip'] = $zip;
174 }
175
176 // State.
177 if ( $state = give_get_meta( $object_id, '_give_donor_billing_state', true ) ) {
178 $donor_data['address']['state'] = $state;
179 }
180
181 // Country.
182 if ( $country = give_get_meta( $object_id, '_give_donor_billing_country', true ) ) {
183 $donor_data['address']['country'] = $country;
184 }
185
186 $meta_value['user_info'] = maybe_unserialize( $donor_data );
187
188 Give_Cache::set_db_query( $cache_key, $meta_value );
189
190 return $meta_value;
191 }
192
193 /**
194 * Add backward compatibility old meta while saving.
195 * 1. _give_payment_meta (split into multiple single meta keys)
196 * 2. _give_payment_user_email (renamed to _give_payment_donor_email)
197 * 3. _give_payment_customer_id (renamed to _give_payment_donor_id)
198 * 4. give_payment_user_ip (renamed to give_payment_donor_ip)
199 *
200 * @since 2.0
201 *
202 * @param null|bool $check Whether to allow updating metadata for the given type.
203 * @param int $object_id Object ID.
204 * @param string $meta_key Meta key.
205 * @param mixed $meta_value Meta value. Must be serializable if non-scalar.
206 * @param mixed $prev_value Optional. If specified, only update existing
207 * metadata entries with the specified value.
208 * Otherwise, update all entries.
209 *
210 * @return mixed
211 */
212 function _give_20_bc_saving_old_payment_meta( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
213 // Bailout.
214 if (
215 'give_payment' !== get_post_type( $object_id ) ||
216 ! in_array( $meta_key, array(
217 '_give_payment_meta',
218 '_give_payment_user_email',
219 '_give_payment_customer_id',
220 'give_payment_user_ip',
221 ) )
222 ) {
223 return $check;
224 }
225
226 if ( '_give_payment_meta' === $meta_key ) {
227 _give_20_bc_split_and_save_give_payment_meta( $object_id, $meta_value );
228 } elseif ( '_give_payment_user_email' === $meta_key ) {
229 give_update_meta( $object_id, '_give_payment_donor_email', $meta_value );
230 $check = true;
231 } elseif ( '_give_payment_customer_id' === $meta_key ) {
232 give_update_meta( $object_id, '_give_payment_donor_id', $meta_value );
233 $check = true;
234 } elseif ( 'give_payment_user_ip' === $meta_key ) {
235 give_update_meta( $object_id, '_give_payment_donor_ip', $meta_value );
236 $check = true;
237 }
238
239 return $check;
240 }
241
242 add_filter( 'update_post_metadata', '_give_20_bc_saving_old_payment_meta', 10, 5 );
243
244
245 /**
246 * Add backward compatibility to get old payment meta.
247 *
248 * @since 2.0
249 *
250 * @param $check
251 * @param $object_id
252 * @param $meta_key
253 * @param $single
254 *
255 * @return mixed
256 */
257 function _give_20_bc_get_old_payment_meta( $check, $object_id, $meta_key, $single ) {
258 global $wpdb;
259
260 // Deprecated meta keys.
261 $old_meta_keys = array(
262 '_give_payment_customer_id',
263 '_give_payment_user_email',
264 '_give_payment_user_ip',
265 );
266
267 // Add _give_payment_meta to backward compatibility
268 if ( ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
269 $old_meta_keys[] = '_give_payment_meta';
270 }
271
272 // Bailout.
273 if (
274 'give_payment' !== get_post_type( $object_id ) ||
275 ! in_array( $meta_key, $old_meta_keys )
276 ) {
277 return $check;
278 }
279
280 $cache_key = "{$meta_key}_{$object_id}";
281 $check = Give_Cache::get_db_query( $cache_key );
282
283 if ( is_null( $check ) ) {
284 switch ( $meta_key ) {
285
286 // Handle old meta keys.
287 case '_give_payment_meta':
288 remove_filter( 'get_post_metadata', '_give_20_bc_get_old_payment_meta' );
289
290 // if ( $meta_value = give_get_meta( $object_id, '_give_payment_meta' ) ) {
291 $meta_value = ! empty( $meta_value ) ?
292 current( $meta_value ) :
293 (array) maybe_unserialize(
294 $wpdb->get_var(
295 $wpdb->prepare(
296 "
297 SELECT meta_value
298 FROM $wpdb->postmeta
299 WHERE post_id=%d
300 AND meta_key=%s
301 ",
302 $object_id,
303 '_give_payment_meta'
304 )
305 )
306 );
307 $check = _give_20_bc_give_payment_meta_value( $object_id, $meta_value );
308 // }
309
310 add_filter( 'get_post_metadata', '_give_20_bc_get_old_payment_meta', 10, 5 );
311
312 break;
313
314 case '_give_payment_customer_id':
315 if ( $donor_id = give_get_meta( $object_id, '_give_payment_donor_id', $single ) ) {
316 $check = $donor_id;
317 }
318 break;
319
320 case '_give_payment_user_email':
321 if ( $donor_email = give_get_meta( $object_id, '_give_payment_donor_email', $single ) ) {
322 $check = $donor_email;
323 }
324 break;
325
326 case '_give_payment_user_ip':
327 if ( $donor_ip = give_get_meta( $object_id, '_give_payment_donor_ip', $single ) ) {
328 $check = $donor_ip;
329 }
330 break;
331 }// End switch().
332
333 Give_Cache::set_db_query( $cache_key, $check );
334 }
335
336 // Put result in an array on zero index.
337 if ( ! is_null( $check ) ) {
338 $check = array( $check );
339 }
340
341 return $check;
342 }
343
344 add_filter( 'get_post_metadata', '_give_20_bc_get_old_payment_meta', 10, 5 );
345
346
347 /**
348 * Add backward compatibility to get new payment meta.
349 *
350 * @since 2.0
351 *
352 * @param $check
353 * @param $object_id
354 * @param $meta_key
355 * @param $single
356 *
357 * @return mixed
358 */
359 function _give_20_bc_get_new_payment_meta( $check, $object_id, $meta_key, $single ) {
360 // Bailout: do not apply backward compatibility if upgrade done.
361 if ( give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
362 return $check;
363 }
364
365 global $wpdb;
366 $new_meta_keys = array(
367 '_give_payment_donor_id',
368 '_give_payment_donor_email',
369 '_give_payment_donor_ip',
370 '_give_donor_billing_first_name',
371 '_give_donor_billing_last_name',
372 '_give_donor_billing_address1',
373 '_give_donor_billing_address2',
374 '_give_donor_billing_city',
375 '_give_donor_billing_zip',
376 '_give_donor_billing_state',
377 '_give_donor_billing_country',
378 '_give_payment_date',
379 '_give_payment_currency',
380 );
381
382 // metadata_exists fx will cause of firing get_post_metadata filter again so remove it to prevent infinite loop.
383 remove_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta' );
384
385 // Bailout.
386 if (
387 'give_payment' !== get_post_type( $object_id ) ||
388 ! in_array( $meta_key, $new_meta_keys ) ||
389 metadata_exists( 'post', $object_id, $meta_key )
390 ) {
391 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
392
393 return $check;
394 }
395
396 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
397
398 $cache_key = "{$meta_key}_{$object_id}";
399 $check = Give_Cache::get_db_query( $cache_key );
400
401 if ( is_null( $check ) ) {
402 switch ( $meta_key ) {
403
404 // Handle new meta keys.
405 case '_give_payment_donor_id':
406 $check = $wpdb->get_var(
407 $wpdb->prepare(
408 "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s",
409 $object_id,
410 '_give_payment_customer_id'
411 )
412 );
413 break;
414
415 case '_give_payment_donor_email':
416 $check = $wpdb->get_var(
417 $wpdb->prepare(
418 "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s",
419 $object_id,
420 '_give_payment_user_email'
421 )
422 );
423 break;
424
425 case '_give_payment_donor_ip':
426 $check = $wpdb->get_var(
427 $wpdb->prepare(
428 "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%s AND meta_key=%s",
429 $object_id,
430 '_give_payment_user_ip'
431 )
432 );
433 break;
434
435 case '_give_donor_billing_first_name':
436 case '_give_donor_billing_last_name':
437 case '_give_donor_billing_address1':
438 case '_give_donor_billing_address2':
439 case '_give_donor_billing_city':
440 case '_give_donor_billing_zip':
441 case '_give_donor_billing_state':
442 case '_give_donor_billing_country':
443 case '_give_payment_date':
444 case '_give_payment_currency':
445 $donation_meta = Give_Cache::get_db_query( "_give_payment_meta_{$object_id}" );
446
447 if ( is_null( $donation_meta ) ) {
448 $donation_meta = $wpdb->get_var(
449 $wpdb->prepare(
450 "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s",
451 $object_id,
452 '_give_payment_meta'
453 )
454 );
455 $donation_meta = maybe_unserialize( $donation_meta );
456 $donation_meta = ! is_array( $donation_meta ) ? array() : $donation_meta;
457 Give_Cache::set_db_query( "_give_payment_meta_{$object_id}", $donation_meta );
458 }
459
460 // Get results.
461 if ( empty( $donation_meta ) ) {
462 $check = '';
463 } elseif ( in_array( $meta_key, array( '_give_payment_date', '_give_payment_currency' ) ) ) {
464 $payment_meta_key = str_replace( '_give_payment_', '', $meta_key );
465
466 if ( isset( $donation_meta[ $payment_meta_key ] ) ) {
467 $check = $donation_meta[ $payment_meta_key ];
468 }
469 } else {
470 $payment_meta_key = str_replace( '_give_donor_billing_', '', $meta_key );
471
472 switch ( $payment_meta_key ) {
473 case 'address1':
474 if ( isset( $donation_meta['user_info']['address']['line1'] ) ) {
475 $check = $donation_meta['user_info']['address']['line1'];
476 }
477 break;
478
479 case 'address2':
480 if ( isset( $donation_meta['user_info']['address']['line2'] ) ) {
481 $check = $donation_meta['user_info']['address']['line2'];
482 }
483 break;
484
485 case 'first_name':
486 if ( isset( $donation_meta['user_info']['first_name'] ) ) {
487 $check = $donation_meta['user_info']['first_name'];
488 }
489 break;
490
491 case 'last_name':
492 if ( isset( $donation_meta['user_info']['last_name'] ) ) {
493 $check = $donation_meta['user_info']['last_name'];
494 }
495 break;
496
497 default:
498 if ( isset( $donation_meta['user_info']['address'][ $payment_meta_key ] ) ) {
499 $check = $donation_meta['user_info']['address'][ $payment_meta_key ];
500 }
501 }
502 }
503
504 break;
505 }// End switch().
506
507 // Set cache.
508 Give_Cache::set_db_query( $cache_key, $check );
509 }
510
511 // Put result in an array on zero index.
512 if ( ! $single ) {
513 $check = array( $check );
514 }
515
516
517 return $check;
518 }
519
520 add_filter( 'get_post_metadata', '_give_20_bc_get_new_payment_meta', 10, 5 );
521
522
523 /**
524 * Add support for old payment meta keys.
525 *
526 * @since 2.0
527 *
528 * @param WP_Query $query
529 *
530 * @return void
531 */
532 function _give_20_bc_support_deprecated_meta_key_query( $query ) {
533 // Bailout.
534 if ( give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
535 return;
536 }
537
538 $new_meta_keys = array(
539 '_give_payment_customer_id' => '_give_payment_donor_id',
540 '_give_payment_user_email' => '_give_payment_donor_email',
541 // '_give_payment_user_ip' => '_give_payment_donor_ip',
542 );
543
544 $deprecated_meta_keys = array_flip( $new_meta_keys );
545
546 // Set meta keys.
547 $meta_keys = array();
548
549
550 // Bailout.
551 if ( ! empty( $query->query_vars['meta_key'] ) ) {
552 if ( in_array( $query->query_vars['meta_key'], $new_meta_keys ) ) {
553 $meta_keys = $deprecated_meta_keys;
554 } elseif ( in_array( $query->query_vars['meta_key'], $deprecated_meta_keys ) ) {
555 $meta_keys = $new_meta_keys;
556 }
557
558 if ( ! empty( $meta_keys ) ) {
559 // Set meta_query
560 $query->set(
561 'meta_query',
562 array(
563 'relation' => 'OR',
564 array(
565 'key' => $query->query_vars['meta_key'],
566 'value' => $query->query_vars['meta_value'],
567 ),
568 array(
569 'key' => $meta_keys[ $query->query_vars['meta_key'] ],
570 'value' => $query->query_vars['meta_value'],
571 ),
572 )
573 );
574
575 // Unset single meta query.
576 unset( $query->query_vars['meta_key'] );
577 unset( $query->query_vars['meta_value'] );
578 }
579 } elseif (
580 ! empty( $query->query_vars['meta_query'] ) &&
581 ( 1 === count( $query->query_vars['meta_query'] ) )
582 ) {
583 $meta_query = current( $query->query_vars['meta_query'] );
584
585 if ( empty( $meta_query[0]['key'] ) ) {
586 return;
587 }
588
589 if ( in_array( $meta_query[0]['key'], $new_meta_keys ) ) {
590 $meta_keys = $deprecated_meta_keys;
591 } elseif ( in_array( $meta_query[0]['key'], $deprecated_meta_keys ) ) {
592 $meta_keys = $new_meta_keys;
593 } else {
594 return;
595 }
596
597 if ( ! empty( $meta_keys ) ) {
598 // Set meta_query
599 $query->set(
600 'meta_query',
601 array(
602 'relation' => 'OR',
603 array(
604 'key' => $query->query_vars['meta_query'][0]['key'],
605 'value' => $query->query_vars['meta_query'][0]['value'],
606 ),
607 array(
608 'key' => $meta_keys[ $query->query_vars['meta_query'][0]['key'] ],
609 'value' => $query->query_vars['meta_query'][0]['value'],
610 ),
611 )
612 );
613 }
614 }
615 }
616
617 add_action( 'pre_get_posts', '_give_20_bc_support_deprecated_meta_key_query' );
618
619
620 /**
621 * Save payment backward compatibility.
622 * Note: some addon still can use user_info in set payment meta
623 * we will use this info to set first name, last name and address of donor
624 *
625 * @since 2.0
626 *
627 * @param Give_Payment $payment
628 * @param string $key
629 */
630 function _give_20_bc_payment_save( $payment, $key ) {
631 // Bailout.
632 if ( ! give_has_upgrade_completed( 'v20_upgrades_payment_metadata' ) ) {
633 return;
634 }
635
636 switch ( $key ) {
637 case 'user_info':
638 if ( empty( $payment->user_info ) ) {
639 // Bailout.
640 break;
641 } elseif ( is_string( $payment->user_info ) ) {
642 // Check if value serialize.
643 $payment->user_info = maybe_unserialize( $payment->user_info );
644 }
645
646
647 // Save first name.
648 if ( isset( $payment->user_info['first_name'] ) ) {
649 $payment->update_meta( '_give_donor_billing_first_name', $payment->user_info['first_name'] );
650 }
651
652
653 // Save last name.
654 if ( isset( $payment->user_info['last_name'] ) ) {
655 $payment->update_meta( '_give_donor_billing_last_name', $payment->user_info['last_name'] );
656 }
657
658
659 // Save address.
660 if ( ! empty( $payment->user_info['address'] ) ) {
661 foreach ( $payment->user_info['address'] as $address_name => $address ) {
662 switch ( $address_name ) {
663 case 'line1':
664 $payment->update_meta( '_give_donor_billing_address1', $address );
665 break;
666
667 case 'line2':
668 $payment->update_meta( '_give_donor_billing_address2', $address );
669 break;
670
671 default:
672 $payment->update_meta( "_give_donor_billing_{$address_name}", $address );
673 }
674 }
675 }
676
677 break;
678 }
679 }
680
681 add_action( 'give_payment_save', '_give_20_bc_payment_save', 10, 2 );
682
683
684 /**
685 * Delete pre upgrade cache for donations.
686 *
687 * @since 2.0
688 *
689 * @param $check
690 * @param $object_id
691 *
692 * @return mixed
693 */
694 function __give_20_bc_flush_cache( $check, $object_id ) {
695 if (
696 ! give_has_upgrade_completed( 'v20_move_metadata_into_new_table' ) &&
697 'give_payment' === get_post_type( $object_id )
698 ) {
699 Give_Cache::delete_group( $object_id, 'give-donations' );
700 }
701
702 return $check;
703 }
704
705 add_action( 'update_post_metadata', '__give_20_bc_flush_cache', 9999, 2 );
706 add_action( 'add_post_metadata', '__give_20_bc_flush_cache', 9999, 2 );
707