1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Upgrade Functions |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Admin/Upgrades |
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
9
|
|
|
* @since 1.0 |
10
|
|
|
* |
11
|
|
|
* NOTICE: When adding new upgrade notices, please be sure to put the action into the upgrades array during install: |
12
|
|
|
* /includes/install.php @ Appox Line 156 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
// Exit if accessed directly. |
16
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
17
|
|
|
exit; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Perform automatic database upgrades when necessary. |
22
|
|
|
* |
23
|
|
|
* @since 1.6 |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
function give_do_automatic_upgrades() { |
27
|
|
|
$did_upgrade = false; |
28
|
|
|
$give_version = preg_replace( '/[^0-9.].*/', '', get_option( 'give_version' ) ); |
29
|
|
|
|
30
|
|
|
if ( ! $give_version ) { |
31
|
|
|
// 1.0 is the first version to use this option so we must add it. |
32
|
|
|
$give_version = '1.0'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
switch ( true ) { |
36
|
|
|
|
37
|
|
|
case version_compare( $give_version, '1.6', '<' ) : |
38
|
|
|
give_v16_upgrades(); |
39
|
|
|
$did_upgrade = true; |
|
|
|
|
40
|
|
|
|
41
|
|
|
case version_compare( $give_version, '1.7', '<' ) : |
42
|
|
|
give_v17_upgrades(); |
43
|
|
|
$did_upgrade = true; |
|
|
|
|
44
|
|
|
|
45
|
|
|
case version_compare( $give_version, '1.8', '<' ) : |
46
|
|
|
give_v18_upgrades(); |
47
|
|
|
$did_upgrade = true; |
|
|
|
|
48
|
|
|
|
49
|
|
|
case version_compare( $give_version, '1.8.7', '<' ) : |
50
|
|
|
give_v187_upgrades(); |
51
|
|
|
$did_upgrade = true; |
|
|
|
|
52
|
|
|
|
53
|
|
|
case version_compare( $give_version, '1.8.8', '<' ) : |
54
|
|
|
give_v188_upgrades(); |
55
|
|
|
$did_upgrade = true; |
|
|
|
|
56
|
|
|
|
57
|
|
|
case version_compare( $give_version, '1.8.9', '<' ) : |
58
|
|
|
give_v189_upgrades(); |
59
|
|
|
$did_upgrade = true; |
|
|
|
|
60
|
|
|
|
61
|
|
|
case version_compare( $give_version, '1.8.12', '<' ) : |
62
|
|
|
give_v1812_upgrades(); |
63
|
|
|
$did_upgrade = true; |
|
|
|
|
64
|
|
|
|
65
|
|
|
case version_compare( $give_version, '1.8.13', '<' ) : |
66
|
|
|
give_v1813_upgrades(); |
67
|
|
|
$did_upgrade = true; |
|
|
|
|
68
|
|
|
|
69
|
|
|
case version_compare( $give_version, '1.8.17', '<' ) : |
70
|
|
|
give_v1817_upgrades(); |
71
|
|
|
$did_upgrade = true; |
|
|
|
|
72
|
|
|
|
73
|
|
|
case version_compare( $give_version, '1.8.18', '<' ) : |
74
|
|
|
give_v1818_upgrades(); |
75
|
|
|
$did_upgrade = true; |
|
|
|
|
76
|
|
|
|
77
|
|
|
case version_compare( $give_version, '2.0', '<' ) : |
78
|
|
|
give_v20_upgrades(); |
79
|
|
|
$did_upgrade = true; |
|
|
|
|
80
|
|
|
|
81
|
|
|
case version_compare( $give_version, '2.0.1', '<' ) : |
82
|
|
|
// Do nothing on fresh install. |
83
|
|
|
if( ! doing_action( 'give_upgrades' ) ) { |
|
|
|
|
84
|
|
|
give_v201_create_tables(); |
85
|
|
|
Give_Updates::get_instance()->__health_background_update( Give_Updates::get_instance() ); |
86
|
|
|
Give_Updates::$background_updater->dispatch(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$did_upgrade = true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ( $did_upgrade ) { |
93
|
|
|
update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
add_action( 'admin_init', 'give_do_automatic_upgrades' ); |
98
|
|
|
add_action( 'give_upgrades', 'give_do_automatic_upgrades' ); |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Display Upgrade Notices. |
102
|
|
|
* |
103
|
|
|
* IMPORTANT: ALSO UPDATE INSTALL.PHP WITH THE ID OF THE UPGRADE ROUTINE SO IT DOES NOT AFFECT NEW INSTALLS. |
104
|
|
|
* |
105
|
|
|
* @since 1.0 |
106
|
|
|
* @since 1.8.12 Update new update process code. |
107
|
|
|
* |
108
|
|
|
* @param Give_Updates $give_updates |
109
|
|
|
* |
110
|
|
|
* @return void |
111
|
|
|
*/ |
112
|
|
|
function give_show_upgrade_notices( $give_updates ) { |
113
|
|
|
// v1.3.2 Upgrades |
114
|
|
|
$give_updates->register( |
115
|
|
|
array( |
116
|
|
|
'id' => 'upgrade_give_payment_customer_id', |
117
|
1 |
|
'version' => '1.3.2', |
118
|
|
|
'callback' => 'give_v132_upgrade_give_payment_customer_id', |
119
|
|
|
) |
120
|
|
|
); |
121
|
1 |
|
|
122
|
|
|
// v1.3.4 Upgrades ensure the user has gone through 1.3.4. |
123
|
1 |
|
$give_updates->register( |
124
|
|
|
array( |
125
|
|
|
'id' => 'upgrade_give_offline_status', |
126
|
|
|
'depend' => 'upgrade_give_payment_customer_id', |
127
|
|
|
'version' => '1.3.4', |
128
|
|
|
'callback' => 'give_v134_upgrade_give_offline_status', |
129
|
|
|
) |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
// v1.8 form metadata upgrades. |
133
|
|
|
$give_updates->register( |
134
|
|
|
array( |
135
|
|
|
'id' => 'v18_upgrades_form_metadata', |
136
|
|
|
'version' => '1.8', |
137
|
|
|
'callback' => 'give_v18_upgrades_form_metadata', |
138
|
1 |
|
) |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
// v1.8.9 Upgrades |
142
|
1 |
|
$give_updates->register( |
143
|
1 |
|
array( |
144
|
|
|
'id' => 'v189_upgrades_levels_post_meta', |
145
|
|
|
'version' => '1.8.9', |
146
|
1 |
|
'callback' => 'give_v189_upgrades_levels_post_meta_callback', |
147
|
|
|
) |
148
|
1 |
|
); |
149
|
|
|
|
150
|
|
|
// v1.8.12 Upgrades |
151
|
|
|
$give_updates->register( |
152
|
|
|
array( |
153
|
|
|
'id' => 'v1812_update_amount_values', |
154
|
|
|
'version' => '1.8.12', |
155
|
|
|
'callback' => 'give_v1812_update_amount_values_callback', |
156
|
|
|
) |
157
|
|
|
); |
158
|
|
|
|
159
|
1 |
|
// v1.8.12 Upgrades |
160
|
|
|
$give_updates->register( |
161
|
1 |
|
array( |
162
|
|
|
'id' => 'v1812_update_donor_purchase_values', |
163
|
|
|
'version' => '1.8.12', |
164
|
|
|
'callback' => 'give_v1812_update_donor_purchase_value_callback', |
165
|
1 |
|
) |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
// v1.8.13 Upgrades for donor |
169
|
|
|
$give_updates->register( |
170
|
|
|
array( |
171
|
|
|
'id' => 'v1813_update_donor_user_roles', |
172
|
|
|
'version' => '1.8.13', |
173
|
|
|
'callback' => 'give_v1813_update_donor_user_roles_callback', |
174
|
|
|
) |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
// v1.8.17 Upgrades for donations. |
178
|
|
|
$give_updates->register( array( |
179
|
|
|
'id' => 'v1817_update_donation_iranian_currency_code', |
180
|
|
|
'version' => '1.8.17', |
181
|
|
|
'callback' => 'give_v1817_update_donation_iranian_currency_code', |
182
|
|
|
) ); |
183
|
|
|
|
184
|
|
|
// v1.8.17 Upgrades for cleanup of user roles. |
185
|
|
|
$give_updates->register( array( |
186
|
|
|
'id' => 'v1817_cleanup_user_roles', |
187
|
|
|
'version' => '1.8.17', |
188
|
|
|
'callback' => 'give_v1817_cleanup_user_roles', |
189
|
|
|
) ); |
190
|
|
|
|
191
|
|
|
// v1.8.18 Upgrades for assigning custom amount to existing set donations. |
192
|
|
|
$give_updates->register( array( |
193
|
|
|
'id' => 'v1818_assign_custom_amount_set_donation', |
194
|
|
|
'version' => '1.8.18', |
195
|
|
|
'callback' => 'give_v1818_assign_custom_amount_set_donation', |
196
|
|
|
) ); |
197
|
|
|
|
198
|
|
|
// v1.8.18 Cleanup the Give Worker Role Caps. |
199
|
|
|
$give_updates->register( array( |
200
|
|
|
'id' => 'v1818_give_worker_role_cleanup', |
201
|
|
|
'version' => '1.8.18', |
202
|
|
|
'callback' => 'give_v1818_give_worker_role_cleanup', |
203
|
|
|
) ); |
204
|
|
|
|
205
|
|
|
// v2.0.0 Upgrades |
206
|
|
|
$give_updates->register( |
207
|
|
|
array( |
208
|
|
|
'id' => 'v20_upgrades_form_metadata', |
209
|
|
|
'version' => '2.0.0', |
210
|
|
|
'callback' => 'give_v20_upgrades_form_metadata_callback', |
211
|
|
|
) |
212
|
|
|
); |
213
|
|
|
|
214
|
|
|
// v2.0.0 User Address Upgrades |
215
|
|
|
$give_updates->register( |
216
|
|
|
array( |
217
|
|
|
'id' => 'v20_upgrades_user_address', |
218
|
|
|
'version' => '2.0.0', |
219
|
|
|
'callback' => 'give_v20_upgrades_user_address', |
220
|
|
|
) |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
// v2.0.0 Upgrades |
224
|
|
|
$give_updates->register( |
225
|
|
|
array( |
226
|
|
|
'id' => 'v20_upgrades_payment_metadata', |
227
|
|
|
'version' => '2.0.0', |
228
|
|
|
'callback' => 'give_v20_upgrades_payment_metadata_callback', |
229
|
|
|
) |
230
|
|
|
); |
231
|
|
|
|
232
|
|
|
// v2.0.0 Upgrades |
233
|
|
|
$give_updates->register( |
234
|
|
|
array( |
235
|
|
|
'id' => 'v20_logs_upgrades', |
236
|
|
|
'version' => '2.0.0', |
237
|
|
|
'callback' => 'give_v20_logs_upgrades_callback', |
238
|
|
|
|
239
|
|
|
) |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
// v2.0.0 Donor Name Upgrades |
243
|
|
|
$give_updates->register( |
244
|
|
|
array( |
245
|
|
|
'id' => 'v20_upgrades_donor_name', |
246
|
|
|
'version' => '2.0.0', |
247
|
|
|
'callback' => 'give_v20_upgrades_donor_name', |
248
|
|
|
) |
249
|
|
|
); |
250
|
|
|
|
251
|
|
|
// v2.0.0 Upgrades |
252
|
|
|
$give_updates->register( |
253
|
|
|
array( |
254
|
|
|
'id' => 'v20_move_metadata_into_new_table', |
255
|
|
|
'version' => '2.0.0', |
256
|
|
|
'callback' => 'give_v20_move_metadata_into_new_table_callback', |
257
|
|
|
'depend' => array( 'v20_upgrades_payment_metadata', 'v20_upgrades_form_metadata' ), |
258
|
|
|
) |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
// v2.0.0 Upgrades |
262
|
|
|
$give_updates->register( |
263
|
|
|
array( |
264
|
|
|
'id' => 'v20_rename_donor_tables', |
265
|
|
|
'version' => '2.0.0', |
266
|
|
|
'callback' => 'give_v20_rename_donor_tables_callback', |
267
|
|
|
'depend' => array( |
268
|
|
|
'v20_move_metadata_into_new_table', |
269
|
|
|
'v20_logs_upgrades', |
270
|
|
|
'v20_upgrades_form_metadata', |
271
|
|
|
'v20_upgrades_payment_metadata', |
272
|
|
|
'v20_upgrades_user_address', |
273
|
|
|
'v20_upgrades_donor_name' |
|
|
|
|
274
|
|
|
), |
275
|
|
|
) |
276
|
|
|
); |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
279
|
|
|
// v2.0.1 Upgrades |
280
|
|
|
$give_updates->register( |
281
|
|
|
array( |
282
|
|
|
'id' => 'v201_upgrades_payment_metadata', |
283
|
|
|
'version' => '2.0.1', |
284
|
|
|
'callback' => 'give_v201_upgrades_payment_metadata_callback', |
285
|
|
|
) |
286
|
|
|
); |
287
|
|
|
|
288
|
|
|
// v2.0.1 Upgrades |
289
|
|
|
$give_updates->register( |
290
|
|
|
array( |
291
|
|
|
'id' => 'v201_add_missing_donors', |
292
|
|
|
'version' => '2.0.1', |
293
|
|
|
'callback' => 'give_v201_add_missing_donors_callback', |
294
|
|
|
) |
295
|
|
|
); |
296
|
|
|
|
297
|
|
|
// Run v2.0.0 Upgrades again in 2.0.1 |
298
|
|
|
$give_updates->register( |
299
|
|
|
array( |
300
|
|
|
'id' => 'v201_move_metadata_into_new_table', |
301
|
|
|
'version' => '2.0.1', |
302
|
|
|
'callback' => 'give_v201_move_metadata_into_new_table_callback', |
303
|
|
|
'depend' => array( 'v201_upgrades_payment_metadata', 'v201_add_missing_donors' ), |
304
|
|
|
) |
305
|
|
|
); |
306
|
|
|
|
307
|
|
|
// Run v2.0.0 Upgrades again in 2.0.1 |
308
|
|
|
$give_updates->register( |
309
|
|
|
array( |
310
|
|
|
'id' => 'v201_logs_upgrades', |
311
|
|
|
'version' => '2.0.1', |
312
|
|
|
'callback' => 'give_v201_logs_upgrades_callback', |
313
|
|
|
|
314
|
|
|
) |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
add_action( 'give_register_updates', 'give_show_upgrade_notices' ); |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Triggers all upgrade functions |
322
|
|
|
* |
323
|
|
|
* This function is usually triggered via AJAX |
324
|
|
|
* |
325
|
|
|
* @since 1.0 |
326
|
|
|
* @return void |
327
|
|
|
*/ |
328
|
|
|
function give_trigger_upgrades() { |
329
|
|
|
|
330
|
|
View Code Duplication |
if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
|
|
|
331
|
|
|
wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
332
|
|
|
'response' => 403, |
333
|
|
|
) ); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
$give_version = get_option( 'give_version' ); |
337
|
|
|
|
338
|
|
|
if ( ! $give_version ) { |
339
|
|
|
// 1.0 is the first version to use this option so we must add it. |
340
|
|
|
$give_version = '1.0'; |
341
|
|
|
add_option( 'give_version', $give_version ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
update_option( 'give_version', GIVE_VERSION ); |
345
|
|
|
delete_option( 'give_doing_upgrade' ); |
346
|
|
|
|
347
|
|
|
if ( DOING_AJAX ) { |
348
|
|
|
die( 'complete' ); |
349
|
|
|
} // End if(). |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' ); |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Upgrades the |
357
|
|
|
* |
358
|
|
|
* Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id` |
359
|
|
|
* |
360
|
|
|
* @since 1.3.2 |
361
|
|
|
*/ |
362
|
|
|
function give_v132_upgrade_give_payment_customer_id() { |
363
|
|
|
global $wpdb; |
364
|
|
|
|
365
|
|
|
/* @var Give_Updates $give_updates */ |
366
|
|
|
$give_updates = Give_Updates::get_instance(); |
367
|
|
|
|
368
|
|
View Code Duplication |
if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
|
|
|
369
|
|
|
wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
370
|
|
|
'response' => 403, |
371
|
|
|
) ); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
give_ignore_user_abort(); |
375
|
|
|
|
376
|
|
|
// UPDATE DB METAKEYS. |
377
|
|
|
$sql = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'"; |
378
|
|
|
$query = $wpdb->query( $sql ); |
|
|
|
|
379
|
|
|
|
380
|
|
|
$give_updates->percentage = 100; |
|
|
|
|
381
|
|
|
give_set_upgrade_complete( 'upgrade_give_payment_customer_id' ); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Upgrades the Offline Status |
387
|
|
|
* |
388
|
|
|
* Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned |
389
|
|
|
* |
390
|
|
|
* @since 1.3.4 |
391
|
|
|
*/ |
392
|
|
|
function give_v134_upgrade_give_offline_status() { |
393
|
|
|
global $wpdb; |
394
|
|
|
|
395
|
|
|
/* @var Give_Updates $give_updates */ |
396
|
|
|
$give_updates = Give_Updates::get_instance(); |
397
|
|
|
|
398
|
|
|
// Get abandoned offline payments. |
399
|
|
|
$select = "SELECT ID FROM $wpdb->posts p "; |
400
|
|
|
$join = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id "; |
401
|
|
|
$where = "WHERE p.post_type = 'give_payment' "; |
402
|
|
|
$where .= "AND ( p.post_status = 'abandoned' )"; |
403
|
|
|
$where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; |
404
|
|
|
|
405
|
|
|
$sql = $select . $join . $where; |
406
|
|
|
$found_payments = $wpdb->get_col( $sql ); |
|
|
|
|
407
|
|
|
|
408
|
|
|
foreach ( $found_payments as $payment ) { |
409
|
|
|
|
410
|
|
|
// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves. |
411
|
|
|
$modified_time = get_post_modified_time( 'U', false, $payment ); |
412
|
|
|
|
413
|
|
|
// 1450124863 = 12/10/2015 20:42:25. |
414
|
|
|
if ( $modified_time >= 1450124863 ) { |
415
|
|
|
|
416
|
|
|
give_update_payment_status( $payment, 'pending' ); |
417
|
|
|
|
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
$give_updates->percentage = 100; |
|
|
|
|
422
|
|
|
give_set_upgrade_complete( 'upgrade_give_offline_status' ); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Cleanup User Roles |
428
|
|
|
* |
429
|
|
|
* This upgrade routine removes unused roles and roles with typos |
430
|
|
|
* |
431
|
|
|
* @since 1.5.2 |
432
|
|
|
*/ |
433
|
|
|
function give_v152_cleanup_users() { |
434
|
|
|
|
435
|
|
|
$give_version = get_option( 'give_version' ); |
436
|
|
|
|
437
|
|
|
if ( ! $give_version ) { |
438
|
|
|
// 1.0 is the first version to use this option so we must add it. |
439
|
|
|
$give_version = '1.0'; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
$give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
443
|
|
|
|
444
|
|
|
// v1.5.2 Upgrades |
445
|
|
|
if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) { |
446
|
|
|
|
447
|
|
|
// Delete all caps with "ss". |
448
|
|
|
// Also delete all unused "campaign" roles. |
449
|
|
|
$delete_caps = array( |
450
|
|
|
'delete_give_formss', |
451
|
|
|
'delete_others_give_formss', |
452
|
|
|
'delete_private_give_formss', |
453
|
|
|
'delete_published_give_formss', |
454
|
|
|
'read_private_forms', |
455
|
|
|
'edit_give_formss', |
456
|
|
|
'edit_others_give_formss', |
457
|
|
|
'edit_private_give_formss', |
458
|
|
|
'edit_published_give_formss', |
459
|
|
|
'publish_give_formss', |
460
|
|
|
'read_private_give_formss', |
461
|
|
|
'assign_give_campaigns_terms', |
462
|
|
|
'delete_give_campaigns', |
463
|
|
|
'delete_give_campaigns_terms', |
464
|
|
|
'delete_give_campaignss', |
465
|
|
|
'delete_others_give_campaignss', |
466
|
|
|
'delete_private_give_campaignss', |
467
|
|
|
'delete_published_give_campaignss', |
468
|
|
|
'edit_give_campaigns', |
469
|
|
|
'edit_give_campaigns_terms', |
470
|
|
|
'edit_give_campaignss', |
471
|
|
|
'edit_others_give_campaignss', |
472
|
|
|
'edit_private_give_campaignss', |
473
|
|
|
'edit_published_give_campaignss', |
474
|
|
|
'manage_give_campaigns_terms', |
475
|
|
|
'publish_give_campaignss', |
476
|
|
|
'read_give_campaigns', |
477
|
|
|
'read_private_give_campaignss', |
478
|
|
|
'view_give_campaigns_stats', |
479
|
|
|
'delete_give_paymentss', |
480
|
|
|
'delete_others_give_paymentss', |
481
|
|
|
'delete_private_give_paymentss', |
482
|
|
|
'delete_published_give_paymentss', |
483
|
|
|
'edit_give_paymentss', |
484
|
|
|
'edit_others_give_paymentss', |
485
|
|
|
'edit_private_give_paymentss', |
486
|
|
|
'edit_published_give_paymentss', |
487
|
|
|
'publish_give_paymentss', |
488
|
|
|
'read_private_give_paymentss', |
489
|
|
|
); |
490
|
|
|
|
491
|
|
|
global $wp_roles; |
492
|
|
|
foreach ( $delete_caps as $cap ) { |
493
|
|
|
foreach ( array_keys( $wp_roles->roles ) as $role ) { |
494
|
|
|
$wp_roles->remove_cap( $role, $cap ); |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
// Create Give plugin roles. |
499
|
|
|
$roles = new Give_Roles(); |
500
|
|
|
$roles->add_roles(); |
501
|
|
|
$roles->add_caps(); |
502
|
|
|
|
503
|
|
|
// The Update Ran. |
504
|
|
|
update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
505
|
|
|
give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' ); |
506
|
|
|
delete_option( 'give_doing_upgrade' ); |
507
|
|
|
|
508
|
|
|
}// End if(). |
509
|
|
|
|
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
add_action( 'admin_init', 'give_v152_cleanup_users' ); |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* 1.6 Upgrade routine to create the customer meta table. |
516
|
|
|
* |
517
|
|
|
* @since 1.6 |
518
|
|
|
* @return void |
519
|
|
|
*/ |
520
|
|
|
function give_v16_upgrades() { |
521
|
|
|
// Create the donor databases. |
522
|
|
|
$donors_db = new Give_DB_Donors(); |
523
|
|
|
$donors_db->create_table(); |
524
|
|
|
$donor_meta = new Give_DB_Donor_Meta(); |
525
|
|
|
$donor_meta->create_table(); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* 1.7 Upgrades. |
530
|
|
|
* |
531
|
|
|
* a. Update license api data for plugin addons. |
532
|
|
|
* b. Cleanup user roles. |
533
|
|
|
* |
534
|
|
|
* @since 1.7 |
535
|
|
|
* @return void |
536
|
|
|
*/ |
537
|
|
|
function give_v17_upgrades() { |
538
|
|
|
// Upgrade license data. |
539
|
|
|
give_v17_upgrade_addon_license_data(); |
540
|
|
|
give_v17_cleanup_roles(); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Upgrade license data |
545
|
|
|
* |
546
|
|
|
* @since 1.7 |
547
|
|
|
*/ |
548
|
|
|
function give_v17_upgrade_addon_license_data() { |
549
|
|
|
$give_options = give_get_settings(); |
550
|
|
|
|
551
|
|
|
$api_url = 'https://givewp.com/give-sl-api/'; |
552
|
|
|
|
553
|
|
|
// Get addons license key. |
554
|
|
|
$addons = array(); |
555
|
|
|
foreach ( $give_options as $key => $value ) { |
556
|
|
|
if ( false !== strpos( $key, '_license_key' ) ) { |
557
|
|
|
$addons[ $key ] = $value; |
558
|
|
|
} |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
// Bailout: We do not have any addon license data to upgrade. |
562
|
|
|
if ( empty( $addons ) ) { |
563
|
|
|
return false; |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
foreach ( $addons as $key => $addon_license ) { |
567
|
|
|
|
568
|
|
|
// Get addon shortname. |
569
|
|
|
$shortname = str_replace( '_license_key', '', $key ); |
570
|
|
|
|
571
|
|
|
// Addon license option name. |
572
|
|
|
$addon_license_option_name = $shortname . '_license_active'; |
573
|
|
|
|
574
|
|
|
// bailout if license is empty. |
575
|
|
|
if ( empty( $addon_license ) ) { |
576
|
|
|
delete_option( $addon_license_option_name ); |
577
|
|
|
continue; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
// Get addon name. |
581
|
|
|
$addon_name = array(); |
582
|
|
|
$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) ); |
583
|
|
|
foreach ( $addon_name_parts as $name_part ) { |
584
|
|
|
|
585
|
|
|
// Fix addon name |
586
|
|
|
switch ( $name_part ) { |
587
|
|
|
case 'authorizenet' : |
588
|
|
|
$name_part = 'authorize.net'; |
589
|
|
|
break; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
$addon_name[] = ucfirst( $name_part ); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
$addon_name = implode( ' ', $addon_name ); |
596
|
|
|
|
597
|
|
|
// Data to send to the API. |
598
|
|
|
$api_params = array( |
599
|
|
|
'edd_action' => 'activate_license', // never change from "edd_" to "give_"! |
600
|
|
|
'license' => $addon_license, |
601
|
|
|
'item_name' => urlencode( $addon_name ), |
602
|
|
|
'url' => home_url(), |
603
|
|
|
); |
604
|
|
|
|
605
|
|
|
// Call the API. |
606
|
|
|
$response = wp_remote_post( |
607
|
|
|
$api_url, |
608
|
|
|
array( |
609
|
|
|
'timeout' => 15, |
610
|
|
|
'sslverify' => false, |
611
|
|
|
'body' => $api_params, |
612
|
|
|
) |
613
|
|
|
); |
614
|
|
|
|
615
|
|
|
// Make sure there are no errors. |
616
|
|
|
if ( is_wp_error( $response ) ) { |
617
|
|
|
delete_option( $addon_license_option_name ); |
618
|
|
|
continue; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
// Tell WordPress to look for updates. |
622
|
|
|
set_site_transient( 'update_plugins', null ); |
623
|
|
|
|
624
|
|
|
// Decode license data. |
625
|
|
|
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
626
|
|
|
update_option( $addon_license_option_name, $license_data ); |
627
|
|
|
}// End foreach(). |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
|
631
|
|
|
/** |
632
|
|
|
* Cleanup User Roles. |
633
|
|
|
* |
634
|
|
|
* This upgrade routine removes unused roles and roles with typos. |
635
|
|
|
* |
636
|
|
|
* @since 1.7 |
637
|
|
|
*/ |
638
|
|
|
function give_v17_cleanup_roles() { |
639
|
|
|
|
640
|
|
|
// Delete all caps with "_give_forms_" and "_give_payments_". |
641
|
|
|
// These roles have no usage; the proper is singular. |
642
|
|
|
$delete_caps = array( |
643
|
|
|
'view_give_forms_stats', |
644
|
|
|
'delete_give_forms_terms', |
645
|
|
|
'assign_give_forms_terms', |
646
|
|
|
'edit_give_forms_terms', |
647
|
|
|
'manage_give_forms_terms', |
648
|
|
|
'view_give_payments_stats', |
649
|
|
|
'manage_give_payments_terms', |
650
|
|
|
'edit_give_payments_terms', |
651
|
|
|
'assign_give_payments_terms', |
652
|
|
|
'delete_give_payments_terms', |
653
|
|
|
); |
654
|
|
|
|
655
|
|
|
global $wp_roles; |
656
|
|
|
foreach ( $delete_caps as $cap ) { |
657
|
|
|
foreach ( array_keys( $wp_roles->roles ) as $role ) { |
658
|
|
|
$wp_roles->remove_cap( $role, $cap ); |
659
|
|
|
} |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
// Set roles again. |
663
|
|
|
$roles = new Give_Roles(); |
664
|
|
|
$roles->add_roles(); |
665
|
|
|
$roles->add_caps(); |
666
|
|
|
|
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* 1.8 Upgrades. |
671
|
|
|
* |
672
|
|
|
* a. Upgrade checkbox settings to radio button settings. |
673
|
|
|
* a. Update form meta for new metabox settings. |
674
|
|
|
* |
675
|
|
|
* @since 1.8 |
676
|
|
|
* @return void |
677
|
|
|
*/ |
678
|
|
|
function give_v18_upgrades() { |
679
|
|
|
// Upgrade checkbox settings to radio button settings. |
680
|
|
|
give_v18_upgrades_core_setting(); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Upgrade core settings. |
685
|
|
|
* |
686
|
|
|
* @since 1.8 |
687
|
|
|
* @return void |
688
|
|
|
*/ |
689
|
|
|
function give_v18_upgrades_core_setting() { |
690
|
|
|
// Core settings which changes from checkbox to radio. |
691
|
|
|
$core_setting_names = array_merge( |
692
|
|
|
array_keys( give_v18_renamed_core_settings() ), |
693
|
|
|
array( |
694
|
|
|
'uninstall_on_delete', |
695
|
|
|
'scripts_footer', |
696
|
|
|
'test_mode', |
697
|
|
|
'email_access', |
698
|
|
|
'terms', |
699
|
|
|
'give_offline_donation_enable_billing_fields', |
700
|
|
|
) |
701
|
|
|
); |
702
|
|
|
|
703
|
|
|
// Bailout: If not any setting define. |
704
|
|
|
if ( $give_settings = get_option( 'give_settings' ) ) { |
705
|
|
|
|
706
|
|
|
$setting_changed = false; |
707
|
|
|
|
708
|
|
|
// Loop: check each setting field. |
709
|
|
|
foreach ( $core_setting_names as $setting_name ) { |
710
|
|
|
// New setting name. |
711
|
|
|
$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name ); |
712
|
|
|
|
713
|
|
|
// Continue: If setting already set. |
714
|
|
|
if ( |
715
|
|
|
array_key_exists( $new_setting_name, $give_settings ) |
716
|
|
|
&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) ) |
717
|
|
|
) { |
718
|
|
|
continue; |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
// Set checkbox value to radio value. |
722
|
|
|
$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' ); |
723
|
|
|
|
724
|
|
|
// @see https://github.com/WordImpress/Give/issues/1063. |
725
|
|
|
if ( false !== strpos( $setting_name, 'disable_' ) ) { |
726
|
|
|
|
727
|
|
|
$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' ); |
728
|
|
|
} elseif ( false !== strpos( $setting_name, 'enable_' ) ) { |
729
|
|
|
|
730
|
|
|
$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' ); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
// Tell bot to update core setting to db. |
734
|
|
|
if ( ! $setting_changed ) { |
735
|
|
|
$setting_changed = true; |
736
|
|
|
} |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
// Update setting only if they changed. |
740
|
|
|
if ( $setting_changed ) { |
741
|
|
|
update_option( 'give_settings', $give_settings ); |
742
|
|
|
} |
743
|
|
|
}// End if(). |
744
|
|
|
|
745
|
|
|
give_set_upgrade_complete( 'v18_upgrades_core_setting' ); |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
/** |
749
|
|
|
* Upgrade form metadata for new metabox settings. |
750
|
|
|
* |
751
|
|
|
* @since 1.8 |
752
|
|
|
* @return void |
753
|
|
|
*/ |
754
|
|
|
function give_v18_upgrades_form_metadata() { |
755
|
|
|
/* @var Give_Updates $give_updates */ |
756
|
|
|
$give_updates = Give_Updates::get_instance(); |
757
|
|
|
|
758
|
|
|
// form query |
759
|
|
|
$forms = new WP_Query( array( |
760
|
|
|
'paged' => $give_updates->step, |
761
|
|
|
'status' => 'any', |
762
|
|
|
'order' => 'ASC', |
763
|
|
|
'post_type' => 'give_forms', |
764
|
|
|
'posts_per_page' => 20, |
765
|
|
|
) |
766
|
|
|
); |
767
|
|
|
|
768
|
|
|
if ( $forms->have_posts() ) { |
769
|
|
|
$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) ); |
770
|
|
|
|
771
|
|
|
while ( $forms->have_posts() ) { |
772
|
|
|
$forms->the_post(); |
773
|
|
|
|
774
|
|
|
// Form content. |
775
|
|
|
// Note in version 1.8 display content setting split into display content and content placement setting. |
776
|
|
|
// You can delete _give_content_option in future. |
777
|
|
|
$show_content = give_get_meta( get_the_ID(), '_give_content_option', true ); |
778
|
|
|
if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) { |
779
|
|
|
$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' ); |
780
|
|
|
give_update_meta( get_the_ID(), '_give_display_content', $field_value ); |
781
|
|
|
|
782
|
|
|
$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' ); |
783
|
|
|
give_update_meta( get_the_ID(), '_give_content_placement', $field_value ); |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
// "Disable" Guest Donation. Checkbox. |
787
|
|
|
// See: https://github.com/WordImpress/Give/issues/1470. |
788
|
|
|
$guest_donation = give_get_meta( get_the_ID(), '_give_logged_in_only', true ); |
789
|
|
|
$guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' ); |
790
|
|
|
give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval ); |
791
|
|
|
|
792
|
|
|
// Offline Donations. |
793
|
|
|
// See: https://github.com/WordImpress/Give/issues/1579. |
794
|
|
|
$offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
795
|
|
|
if ( 'no' === $offline_donation ) { |
796
|
|
|
$offline_donation_newval = 'global'; |
797
|
|
|
} elseif ( 'yes' === $offline_donation ) { |
798
|
|
|
$offline_donation_newval = 'enabled'; |
799
|
|
|
} else { |
800
|
|
|
$offline_donation_newval = 'disabled'; |
801
|
|
|
} |
802
|
|
|
give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval ); |
803
|
|
|
|
804
|
|
|
// Convert yes/no setting field to enabled/disabled. |
805
|
|
|
$form_radio_settings = array( |
806
|
|
|
// Custom Amount. |
807
|
|
|
'_give_custom_amount', |
808
|
|
|
|
809
|
|
|
// Donation Gaol. |
810
|
|
|
'_give_goal_option', |
811
|
|
|
|
812
|
|
|
// Close Form. |
813
|
|
|
'_give_close_form_when_goal_achieved', |
814
|
|
|
|
815
|
|
|
// Term & conditions. |
816
|
|
|
'_give_terms_option', |
817
|
|
|
|
818
|
|
|
// Billing fields. |
819
|
|
|
'_give_offline_donation_enable_billing_fields_single', |
820
|
|
|
); |
821
|
|
|
|
822
|
|
|
foreach ( $form_radio_settings as $meta_key ) { |
823
|
|
|
// Get value. |
824
|
|
|
$field_value = give_get_meta( get_the_ID(), $meta_key, true ); |
825
|
|
|
|
826
|
|
|
// Convert meta value only if it is in yes/no/none. |
827
|
|
|
if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) { |
828
|
|
|
|
829
|
|
|
$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' ); |
830
|
|
|
give_update_meta( get_the_ID(), $meta_key, $field_value ); |
831
|
|
|
} |
832
|
|
|
} |
833
|
|
|
}// End while(). |
834
|
|
|
|
835
|
|
|
wp_reset_postdata(); |
836
|
|
|
|
837
|
|
|
} else { |
838
|
|
|
// No more forms found, finish up. |
839
|
|
|
give_set_upgrade_complete( 'v18_upgrades_form_metadata' ); |
840
|
|
|
} |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* Get list of core setting renamed in version 1.8. |
846
|
|
|
* |
847
|
|
|
* @since 1.8 |
848
|
|
|
* @return array |
849
|
|
|
*/ |
850
|
|
|
function give_v18_renamed_core_settings() { |
851
|
|
|
return array( |
852
|
|
|
'disable_paypal_verification' => 'paypal_verification', |
853
|
|
|
'disable_css' => 'css', |
854
|
|
|
'disable_welcome' => 'welcome', |
855
|
|
|
'disable_forms_singular' => 'forms_singular', |
856
|
|
|
'disable_forms_archives' => 'forms_archives', |
857
|
|
|
'disable_forms_excerpt' => 'forms_excerpt', |
858
|
|
|
'disable_form_featured_img' => 'form_featured_img', |
859
|
|
|
'disable_form_sidebar' => 'form_sidebar', |
860
|
|
|
'disable_admin_notices' => 'admin_notices', |
861
|
|
|
'disable_the_content_filter' => 'the_content_filter', |
862
|
|
|
'enable_floatlabels' => 'floatlabels', |
863
|
|
|
'enable_categories' => 'categories', |
864
|
|
|
'enable_tags' => 'tags', |
865
|
|
|
); |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
|
869
|
|
|
/** |
870
|
|
|
* Upgrade core settings. |
871
|
|
|
* |
872
|
|
|
* @since 1.8.7 |
873
|
|
|
* @return void |
874
|
|
|
*/ |
875
|
|
|
function give_v187_upgrades() { |
876
|
|
|
global $wpdb; |
877
|
|
|
|
878
|
|
|
/** |
879
|
|
|
* Upgrade 1: Remove stat and cache transients. |
880
|
|
|
*/ |
881
|
|
|
$cached_options = $wpdb->get_col( |
|
|
|
|
882
|
|
|
$wpdb->prepare( |
883
|
|
|
" |
884
|
|
|
SELECT * |
885
|
|
|
FROM {$wpdb->options} |
886
|
|
|
WHERE ( |
887
|
|
|
option_name LIKE %s |
888
|
|
|
OR option_name LIKE %s |
889
|
|
|
OR option_name LIKE %s |
890
|
|
|
OR option_name LIKE %s |
891
|
|
|
OR option_name LIKE %s |
892
|
|
|
OR option_name LIKE %s |
893
|
|
|
OR option_name LIKE %s |
894
|
|
|
OR option_name LIKE %s |
895
|
|
|
OR option_name LIKE %s |
896
|
|
|
OR option_name LIKE %s |
897
|
|
|
OR option_name LIKE %s |
898
|
|
|
OR option_name LIKE %s |
899
|
|
|
OR option_name LIKE %s |
900
|
|
|
) |
901
|
|
|
", |
902
|
|
|
array( |
903
|
|
|
'%_transient_give_stats_%', |
904
|
|
|
'give_cache%', |
905
|
|
|
'%_transient_give_add_ons_feed%', |
906
|
|
|
'%_transient__give_ajax_works' . |
907
|
|
|
'%_transient_give_total_api_keys%', |
908
|
|
|
'%_transient_give_i18n_give_promo_hide%', |
909
|
|
|
'%_transient_give_contributors%', |
910
|
|
|
'%_transient_give_estimated_monthly_stats%', |
911
|
|
|
'%_transient_give_earnings_total%', |
912
|
|
|
'%_transient_give_i18n_give_%', |
913
|
|
|
'%_transient__give_installed%', |
914
|
|
|
'%_transient__give_activation_redirect%', |
915
|
|
|
'%_transient__give_hide_license_notices_shortly_%', |
916
|
|
|
'%give_income_total%', |
917
|
|
|
) |
918
|
|
|
), |
919
|
|
|
1 |
920
|
|
|
); |
921
|
|
|
|
922
|
|
|
// User related transients. |
923
|
|
|
$user_apikey_options = $wpdb->get_results( |
|
|
|
|
924
|
|
|
$wpdb->prepare( |
925
|
|
|
"SELECT user_id, meta_key |
926
|
|
|
FROM $wpdb->usermeta |
|
|
|
|
927
|
|
|
WHERE meta_value=%s", |
928
|
|
|
'give_user_public_key' |
929
|
|
|
), |
930
|
|
|
ARRAY_A |
931
|
|
|
); |
932
|
|
|
|
933
|
|
|
if ( ! empty( $user_apikey_options ) ) { |
934
|
|
|
foreach ( $user_apikey_options as $user ) { |
935
|
|
|
$cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] ); |
936
|
|
|
$cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] ); |
937
|
|
|
$cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] ); |
938
|
|
|
} |
939
|
|
|
} |
940
|
|
|
|
941
|
|
|
if ( ! empty( $cached_options ) ) { |
942
|
|
|
foreach ( $cached_options as $option ) { |
943
|
|
View Code Duplication |
switch ( true ) { |
|
|
|
|
944
|
|
|
case ( false !== strpos( $option, 'transient' ) ): |
945
|
|
|
$option = str_replace( '_transient_', '', $option ); |
946
|
|
|
delete_transient( $option ); |
947
|
|
|
break; |
948
|
|
|
|
949
|
|
|
default: |
950
|
|
|
delete_option( $option ); |
951
|
|
|
} |
952
|
|
|
} |
953
|
|
|
} |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
/** |
957
|
|
|
* Update Capabilities for Give_Worker User Role. |
958
|
|
|
* |
959
|
|
|
* This upgrade routine will update access rights for Give_Worker User Role. |
960
|
|
|
* |
961
|
|
|
* @since 1.8.8 |
962
|
|
|
*/ |
963
|
|
|
function give_v188_upgrades() { |
964
|
|
|
|
965
|
|
|
global $wp_roles; |
966
|
|
|
|
967
|
|
|
// Get the role object. |
968
|
|
|
$give_worker = get_role( 'give_worker' ); |
969
|
|
|
|
970
|
|
|
// A list of capabilities to add for give workers. |
971
|
|
|
$caps_to_add = array( |
972
|
|
|
'edit_posts', |
973
|
|
|
'edit_pages', |
974
|
|
|
); |
975
|
|
|
|
976
|
|
|
foreach ( $caps_to_add as $cap ) { |
977
|
|
|
// Add the capability. |
978
|
|
|
$give_worker->add_cap( $cap ); |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Update Post meta for minimum and maximum amount for multi level donation forms |
985
|
|
|
* |
986
|
|
|
* This upgrade routine adds post meta for give_forms CPT for multi level donation form. |
987
|
|
|
* |
988
|
|
|
* @since 1.8.9 |
989
|
|
|
*/ |
990
|
|
|
function give_v189_upgrades_levels_post_meta_callback() { |
991
|
|
|
/* @var Give_Updates $give_updates */ |
992
|
|
|
$give_updates = Give_Updates::get_instance(); |
993
|
|
|
|
994
|
|
|
// form query. |
995
|
|
|
$donation_forms = new WP_Query( array( |
996
|
|
|
'paged' => $give_updates->step, |
997
|
|
|
'status' => 'any', |
998
|
|
|
'order' => 'ASC', |
999
|
|
|
'post_type' => 'give_forms', |
1000
|
|
|
'posts_per_page' => 20, |
1001
|
|
|
) |
1002
|
|
|
); |
1003
|
|
|
|
1004
|
|
|
if ( $donation_forms->have_posts() ) { |
1005
|
|
|
$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
1006
|
|
|
|
1007
|
|
|
while ( $donation_forms->have_posts() ) { |
1008
|
|
|
$donation_forms->the_post(); |
1009
|
|
|
$form_id = get_the_ID(); |
1010
|
|
|
|
1011
|
|
|
// Remove formatting from _give_set_price. |
1012
|
|
|
update_post_meta( |
1013
|
|
|
$form_id, |
1014
|
|
|
'_give_set_price', |
1015
|
|
|
give_sanitize_amount( get_post_meta( $form_id, '_give_set_price', true ) ) |
1016
|
|
|
); |
1017
|
|
|
|
1018
|
|
|
// Remove formatting from _give_custom_amount_minimum. |
1019
|
|
|
update_post_meta( |
1020
|
|
|
$form_id, |
1021
|
|
|
'_give_custom_amount_minimum', |
1022
|
|
|
give_sanitize_amount( get_post_meta( $form_id, '_give_custom_amount_minimum', true ) ) |
1023
|
|
|
); |
1024
|
|
|
|
1025
|
|
|
// Bailout. |
1026
|
|
|
if ( 'set' === get_post_meta( $form_id, '_give_price_option', true ) ) { |
1027
|
|
|
continue; |
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
$donation_levels = get_post_meta( $form_id, '_give_donation_levels', true ); |
1031
|
|
|
|
1032
|
|
|
if ( ! empty( $donation_levels ) ) { |
1033
|
|
|
|
1034
|
|
|
foreach ( $donation_levels as $index => $donation_level ) { |
1035
|
|
|
if ( isset( $donation_level['_give_amount'] ) ) { |
1036
|
|
|
$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount( $donation_level['_give_amount'] ); |
1037
|
|
|
} |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
update_post_meta( $form_id, '_give_donation_levels', $donation_levels ); |
1041
|
|
|
|
1042
|
|
|
$donation_levels_amounts = wp_list_pluck( $donation_levels, '_give_amount' ); |
1043
|
|
|
|
1044
|
|
|
$min_amount = min( $donation_levels_amounts ); |
1045
|
|
|
$max_amount = max( $donation_levels_amounts ); |
1046
|
|
|
|
1047
|
|
|
// Set Minimum and Maximum amount for Multi Level Donation Forms |
1048
|
|
|
give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount( $min_amount ) : 0 ); |
1049
|
|
|
give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount( $max_amount ) : 0 ); |
1050
|
|
|
} |
|
|
|
|
1051
|
|
|
|
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
/* Restore original Post Data */ |
1055
|
|
|
wp_reset_postdata(); |
1056
|
|
|
} else { |
1057
|
|
|
// The Update Ran. |
1058
|
|
|
give_set_upgrade_complete( 'v189_upgrades_levels_post_meta' ); |
1059
|
|
|
} |
1060
|
|
|
|
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* Give version 1.8.9 upgrades |
1066
|
|
|
* |
1067
|
|
|
* @since 1.8.9 |
1068
|
|
|
*/ |
1069
|
|
|
function give_v189_upgrades() { |
1070
|
|
|
/** |
1071
|
|
|
* 1. Remove user license related notice show blocked ( Give_Notice will handle ) |
1072
|
|
|
*/ |
1073
|
|
|
global $wpdb; |
1074
|
|
|
|
1075
|
|
|
// Delete permanent notice blocker. |
1076
|
|
|
$wpdb->query( |
|
|
|
|
1077
|
|
|
$wpdb->prepare( |
1078
|
|
|
" |
1079
|
|
|
DELETE FROM $wpdb->usermeta |
|
|
|
|
1080
|
|
|
WHERE meta_key |
1081
|
|
|
LIKE '%%%s%%' |
1082
|
|
|
", |
1083
|
|
|
'_give_hide_license_notices_permanently' |
1084
|
|
|
) |
1085
|
|
|
); |
1086
|
|
|
|
1087
|
|
|
// Delete short notice blocker. |
1088
|
|
|
$wpdb->query( |
|
|
|
|
1089
|
|
|
$wpdb->prepare( |
1090
|
|
|
" |
1091
|
|
|
DELETE FROM $wpdb->options |
1092
|
|
|
WHERE option_name |
1093
|
|
|
LIKE '%%%s%%' |
1094
|
|
|
", |
1095
|
|
|
'__give_hide_license_notices_shortly_' |
1096
|
|
|
) |
1097
|
|
|
); |
1098
|
|
|
} |
1099
|
|
|
|
1100
|
|
|
/** |
1101
|
|
|
* 2.0 Upgrades. |
1102
|
|
|
* |
1103
|
|
|
* @since 2.0 |
1104
|
|
|
* @return void |
1105
|
|
|
*/ |
1106
|
|
|
function give_v20_upgrades() { |
1107
|
|
|
// Update cache setting. |
1108
|
|
|
give_update_option( 'cache', 'enabled' ); |
1109
|
|
|
|
1110
|
|
|
// Upgrade email settings. |
1111
|
|
|
give_v20_upgrades_email_setting(); |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
/** |
1115
|
|
|
* Move old email api settings to new email setting api for following emails: |
1116
|
|
|
* 1. new offline donation [This was hard coded] |
1117
|
|
|
* 2. offline donation instruction |
1118
|
|
|
* 3. new donation |
1119
|
|
|
* 4. donation receipt |
1120
|
|
|
* |
1121
|
|
|
* @since 2.0 |
1122
|
|
|
*/ |
1123
|
|
|
function give_v20_upgrades_email_setting() { |
1124
|
|
|
$all_setting = give_get_settings(); |
1125
|
|
|
|
1126
|
|
|
// Bailout on fresh install. |
1127
|
|
|
if ( empty( $all_setting ) ) { |
1128
|
|
|
return; |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
$settings = array( |
1132
|
|
|
'offline_donation_subject' => 'offline-donation-instruction_email_subject', |
1133
|
|
|
'global_offline_donation_email' => 'offline-donation-instruction_email_message', |
1134
|
|
|
'donation_subject' => 'donation-receipt_email_subject', |
1135
|
|
|
'donation_receipt' => 'donation-receipt_email_message', |
1136
|
|
|
'donation_notification_subject' => 'new-donation_email_subject', |
1137
|
|
|
'donation_notification' => 'new-donation_email_message', |
1138
|
|
|
'admin_notice_emails' => array( |
1139
|
|
|
'new-donation_recipient', |
1140
|
|
|
'new-offline-donation_recipient', |
1141
|
|
|
'new-donor-register_recipient', |
1142
|
|
|
), |
1143
|
|
|
'admin_notices' => 'new-donation_notification', |
1144
|
|
|
); |
1145
|
|
|
|
1146
|
|
|
foreach ( $settings as $old_setting => $new_setting ) { |
1147
|
|
|
// Do not update already modified |
1148
|
|
|
if ( ! is_array( $new_setting ) ) { |
1149
|
|
|
if ( array_key_exists( $new_setting, $all_setting ) || ! array_key_exists( $old_setting, $all_setting ) ) { |
1150
|
|
|
continue; |
1151
|
|
|
} |
1152
|
|
|
} |
1153
|
|
|
|
1154
|
|
|
switch ( $old_setting ) { |
1155
|
|
|
case 'admin_notices': |
1156
|
|
|
$notification_status = give_get_option( $old_setting, 'enabled' ); |
1157
|
|
|
|
1158
|
|
|
give_update_option( $new_setting, $notification_status ); |
|
|
|
|
1159
|
|
|
|
1160
|
|
|
// @todo: Delete this option later ( version > 2.0 ), We need this for per form email addon. |
1161
|
|
|
// give_delete_option( $old_setting ); |
1162
|
|
|
|
1163
|
|
|
break; |
1164
|
|
|
|
1165
|
|
|
// @todo: Delete this option later ( version > 2.0 ) because we need this for backward compatibility give_get_admin_notice_emails. |
1166
|
|
|
case 'admin_notice_emails': |
1167
|
|
|
$recipients = give_get_admin_notice_emails(); |
1168
|
|
|
|
1169
|
|
|
foreach ( $new_setting as $setting ) { |
|
|
|
|
1170
|
|
|
// bailout if setting already exist. |
1171
|
|
|
if ( array_key_exists( $setting, $all_setting ) ) { |
1172
|
|
|
continue; |
1173
|
|
|
} |
1174
|
|
|
|
1175
|
|
|
give_update_option( $setting, $recipients ); |
1176
|
|
|
} |
1177
|
|
|
break; |
1178
|
|
|
|
1179
|
|
|
default: |
1180
|
|
|
give_update_option( $new_setting, give_get_option( $old_setting ) ); |
|
|
|
|
1181
|
|
|
give_delete_option( $old_setting ); |
1182
|
|
|
} |
1183
|
|
|
} |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
/** |
1187
|
|
|
* Give version 1.8.9 upgrades |
1188
|
|
|
* |
1189
|
|
|
* @since 1.8.9 |
1190
|
|
|
*/ |
1191
|
|
|
function give_v1812_upgrades() { |
1192
|
|
|
/** |
1193
|
|
|
* Validate number format settings. |
1194
|
|
|
*/ |
1195
|
|
|
$give_settings = give_get_settings(); |
1196
|
|
|
$give_setting_updated = false; |
1197
|
|
|
|
1198
|
|
|
if ( $give_settings['thousands_separator'] === $give_settings['decimal_separator'] ) { |
1199
|
|
|
$give_settings['number_decimals'] = 0; |
1200
|
|
|
$give_settings['decimal_separator'] = ''; |
1201
|
|
|
$give_setting_updated = true; |
1202
|
|
|
|
1203
|
|
|
} elseif ( empty( $give_settings['decimal_separator'] ) ) { |
1204
|
|
|
$give_settings['number_decimals'] = 0; |
1205
|
|
|
$give_setting_updated = true; |
1206
|
|
|
|
1207
|
|
|
} elseif ( 6 < absint( $give_settings['number_decimals'] ) ) { |
1208
|
|
|
$give_settings['number_decimals'] = 5; |
1209
|
|
|
$give_setting_updated = true; |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
if ( $give_setting_updated ) { |
1213
|
|
|
update_option( 'give_settings', $give_settings ); |
1214
|
|
|
} |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
|
1218
|
|
|
/** |
1219
|
|
|
* Give version 1.8.12 update |
1220
|
|
|
* |
1221
|
|
|
* Standardized amount values to six decimal |
1222
|
|
|
* |
1223
|
|
|
* @see https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602 |
1224
|
|
|
* |
1225
|
|
|
* @since 1.8.12 |
1226
|
|
|
*/ |
1227
|
|
|
function give_v1812_update_amount_values_callback() { |
1228
|
|
|
/* @var Give_Updates $give_updates */ |
1229
|
|
|
$give_updates = Give_Updates::get_instance(); |
1230
|
|
|
|
1231
|
|
|
// form query. |
1232
|
|
|
$donation_forms = new WP_Query( array( |
1233
|
|
|
'paged' => $give_updates->step, |
1234
|
|
|
'status' => 'any', |
1235
|
|
|
'order' => 'ASC', |
1236
|
|
|
'post_type' => array( 'give_forms', 'give_payment' ), |
1237
|
|
|
'posts_per_page' => 20, |
1238
|
|
|
) |
1239
|
|
|
); |
1240
|
|
|
if ( $donation_forms->have_posts() ) { |
1241
|
|
|
$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
1242
|
|
|
|
1243
|
|
|
while ( $donation_forms->have_posts() ) { |
1244
|
|
|
$donation_forms->the_post(); |
1245
|
|
|
global $post; |
1246
|
|
|
|
1247
|
|
|
$meta = get_post_meta( $post->ID ); |
1248
|
|
|
|
1249
|
|
|
switch ( $post->post_type ) { |
1250
|
|
|
case 'give_forms': |
1251
|
|
|
// _give_set_price. |
1252
|
|
|
if ( ! empty( $meta['_give_set_price'][0] ) ) { |
1253
|
|
|
update_post_meta( $post->ID, '_give_set_price', give_sanitize_amount_for_db( $meta['_give_set_price'][0] ) ); |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
// _give_custom_amount_minimum. |
1257
|
|
|
if ( ! empty( $meta['_give_custom_amount_minimum'][0] ) ) { |
1258
|
|
|
update_post_meta( $post->ID, '_give_custom_amount_minimum', give_sanitize_amount_for_db( $meta['_give_custom_amount_minimum'][0] ) ); |
1259
|
|
|
} |
1260
|
|
|
|
1261
|
|
|
// _give_levels_minimum_amount. |
1262
|
|
|
if ( ! empty( $meta['_give_levels_minimum_amount'][0] ) ) { |
1263
|
|
|
update_post_meta( $post->ID, '_give_levels_minimum_amount', give_sanitize_amount_for_db( $meta['_give_levels_minimum_amount'][0] ) ); |
1264
|
|
|
} |
1265
|
|
|
|
1266
|
|
|
// _give_levels_maximum_amount. |
1267
|
|
|
if ( ! empty( $meta['_give_levels_maximum_amount'][0] ) ) { |
1268
|
|
|
update_post_meta( $post->ID, '_give_levels_maximum_amount', give_sanitize_amount_for_db( $meta['_give_levels_maximum_amount'][0] ) ); |
1269
|
|
|
} |
1270
|
|
|
|
1271
|
|
|
// _give_set_goal. |
1272
|
|
|
if ( ! empty( $meta['_give_set_goal'][0] ) ) { |
1273
|
|
|
update_post_meta( $post->ID, '_give_set_goal', give_sanitize_amount_for_db( $meta['_give_set_goal'][0] ) ); |
1274
|
|
|
} |
1275
|
|
|
|
1276
|
|
|
// _give_form_earnings. |
1277
|
|
|
if ( ! empty( $meta['_give_form_earnings'][0] ) ) { |
1278
|
|
|
update_post_meta( $post->ID, '_give_form_earnings', give_sanitize_amount_for_db( $meta['_give_form_earnings'][0] ) ); |
1279
|
|
|
} |
1280
|
|
|
|
1281
|
|
|
// _give_custom_amount_minimum. |
1282
|
|
|
if ( ! empty( $meta['_give_donation_levels'][0] ) ) { |
1283
|
|
|
$donation_levels = unserialize( $meta['_give_donation_levels'][0] ); |
1284
|
|
|
|
1285
|
|
|
foreach ( $donation_levels as $index => $level ) { |
1286
|
|
|
if ( empty( $level['_give_amount'] ) ) { |
1287
|
|
|
continue; |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount_for_db( $level['_give_amount'] ); |
1291
|
|
|
} |
1292
|
|
|
|
1293
|
|
|
$meta['_give_donation_levels'] = $donation_levels; |
1294
|
|
|
update_post_meta( $post->ID, '_give_donation_levels', $meta['_give_donation_levels'] ); |
1295
|
|
|
} |
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
1298
|
|
|
break; |
1299
|
|
|
|
1300
|
|
|
case 'give_payment': |
1301
|
|
|
// _give_payment_total. |
1302
|
|
|
if ( ! empty( $meta['_give_payment_total'][0] ) ) { |
1303
|
|
|
update_post_meta( $post->ID, '_give_payment_total', give_sanitize_amount_for_db( $meta['_give_payment_total'][0] ) ); |
1304
|
|
|
} |
1305
|
|
|
|
1306
|
|
|
break; |
1307
|
|
|
} |
1308
|
|
|
} |
1309
|
|
|
|
1310
|
|
|
/* Restore original Post Data */ |
1311
|
|
|
wp_reset_postdata(); |
1312
|
|
|
} else { |
1313
|
|
|
// The Update Ran. |
1314
|
|
|
give_set_upgrade_complete( 'v1812_update_amount_values' ); |
1315
|
|
|
} |
1316
|
|
|
} |
1317
|
|
|
|
1318
|
|
|
|
1319
|
|
|
/** |
1320
|
|
|
* Give version 1.8.12 update |
1321
|
|
|
* |
1322
|
|
|
* Standardized amount values to six decimal for donor |
1323
|
|
|
* |
1324
|
|
|
* @see https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602 |
1325
|
|
|
* |
1326
|
|
|
* @since 1.8.12 |
1327
|
|
|
*/ |
1328
|
|
|
function give_v1812_update_donor_purchase_value_callback() { |
1329
|
|
|
/* @var Give_Updates $give_updates */ |
1330
|
|
|
$give_updates = Give_Updates::get_instance(); |
1331
|
|
|
$offset = 1 === $give_updates->step ? 0 : $give_updates->step * 20; |
1332
|
|
|
|
1333
|
|
|
// form query. |
1334
|
|
|
$donors = Give()->donors->get_donors( array( |
1335
|
|
|
'number' => 20, |
1336
|
|
|
'offset' => $offset, |
1337
|
|
|
) |
1338
|
|
|
); |
1339
|
|
|
|
1340
|
|
|
if ( ! empty( $donors ) ) { |
1341
|
|
|
$give_updates->set_percentage( Give()->donors->count(), $offset ); |
1342
|
|
|
|
1343
|
|
|
/* @var Object $donor */ |
1344
|
|
|
foreach ( $donors as $donor ) { |
1345
|
|
|
Give()->donors->update( $donor->id, array( 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ) ); |
1346
|
|
|
} |
1347
|
|
|
} else { |
1348
|
|
|
// The Update Ran. |
1349
|
|
|
give_set_upgrade_complete( 'v1812_update_donor_purchase_values' ); |
1350
|
|
|
} |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
/** |
1354
|
|
|
* Upgrade routine for updating user roles for existing donors. |
1355
|
|
|
* |
1356
|
|
|
* @since 1.8.13 |
1357
|
|
|
*/ |
1358
|
|
|
function give_v1813_update_donor_user_roles_callback() { |
1359
|
|
|
/* @var Give_Updates $give_updates */ |
1360
|
|
|
$give_updates = Give_Updates::get_instance(); |
1361
|
|
|
$offset = 1 === $give_updates->step ? 0 : $give_updates->step * 20; |
1362
|
|
|
|
1363
|
|
|
// Fetch all the existing donors. |
1364
|
|
|
$donors = Give()->donors->get_donors( array( |
1365
|
|
|
'number' => 20, |
1366
|
|
|
'offset' => $offset, |
1367
|
|
|
) |
1368
|
|
|
); |
1369
|
|
|
|
1370
|
|
|
if ( ! empty( $donors ) ) { |
1371
|
|
|
$give_updates->set_percentage( Give()->donors->count(), ( $give_updates->step * 20 ) ); |
1372
|
|
|
|
1373
|
|
|
/* @var Object $donor */ |
1374
|
|
|
foreach ( $donors as $donor ) { |
1375
|
|
|
$user_id = $donor->user_id; |
1376
|
|
|
|
1377
|
|
|
// Proceed, if donor is attached with user. |
1378
|
|
|
if ( $user_id ) { |
1379
|
|
|
$user = get_userdata( $user_id ); |
1380
|
|
|
|
1381
|
|
|
// Update user role, if user has subscriber role. |
1382
|
|
|
if ( is_array( $user->roles ) && in_array( 'subscriber', $user->roles ) ) { |
1383
|
|
|
wp_update_user( |
1384
|
|
|
array( |
1385
|
|
|
'ID' => $user_id, |
1386
|
|
|
'role' => 'give_donor', |
1387
|
|
|
) |
1388
|
|
|
); |
1389
|
|
|
} |
1390
|
|
|
} |
1391
|
|
|
} |
1392
|
|
|
} else { |
1393
|
|
|
// The Update Ran. |
1394
|
|
|
give_set_upgrade_complete( 'v1813_update_donor_user_roles' ); |
1395
|
|
|
} |
1396
|
|
|
} |
1397
|
|
|
|
1398
|
|
|
|
1399
|
|
|
/** |
1400
|
|
|
* Version 1.8.13 automatic updates |
1401
|
|
|
* |
1402
|
|
|
* @since 1.8.13 |
1403
|
|
|
*/ |
1404
|
|
|
function give_v1813_upgrades() { |
1405
|
|
|
// Update admin setting. |
1406
|
|
|
give_update_option( 'donor_default_user_role', 'give_donor' ); |
1407
|
|
|
|
1408
|
|
|
// Update Give roles. |
1409
|
|
|
$roles = new Give_Roles(); |
1410
|
|
|
$roles->add_roles(); |
1411
|
|
|
$roles->add_caps(); |
1412
|
|
|
} |
1413
|
|
|
|
1414
|
|
|
/** |
1415
|
|
|
* Correct currency code for "Iranian Currency" for all of the payments. |
1416
|
|
|
* |
1417
|
|
|
* @since 1.8.17 |
1418
|
|
|
*/ |
1419
|
|
|
function give_v1817_update_donation_iranian_currency_code() { |
1420
|
|
|
/* @var Give_Updates $give_updates */ |
1421
|
|
|
$give_updates = Give_Updates::get_instance(); |
1422
|
|
|
|
1423
|
|
|
// form query. |
1424
|
|
|
$payments = new WP_Query( array( |
1425
|
|
|
'paged' => $give_updates->step, |
1426
|
|
|
'status' => 'any', |
1427
|
|
|
'order' => 'ASC', |
1428
|
|
|
'post_type' => array( 'give_payment' ), |
1429
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1430
|
|
|
) |
1431
|
|
|
); |
1432
|
|
|
|
1433
|
|
|
if ( $payments->have_posts() ) { |
1434
|
|
|
$give_updates->set_percentage( $payments->found_posts, ( $give_updates->step * 100 ) ); |
1435
|
|
|
|
1436
|
|
|
while ( $payments->have_posts() ) { |
1437
|
|
|
$payments->the_post(); |
1438
|
|
|
|
1439
|
|
|
$payment_meta = give_get_payment_meta( get_the_ID() ); |
1440
|
|
|
|
1441
|
|
|
if ( 'RIAL' === $payment_meta['currency'] ) { |
1442
|
|
|
$payment_meta['currency'] = 'IRR'; |
1443
|
|
|
give_update_meta( get_the_ID(), '_give_payment_meta', $payment_meta ); |
1444
|
|
|
} |
|
|
|
|
1445
|
|
|
|
1446
|
|
|
} |
|
|
|
|
1447
|
|
|
|
1448
|
|
|
} else { |
1449
|
|
|
// The Update Ran. |
1450
|
|
|
give_set_upgrade_complete( 'v1817_update_donation_iranian_currency_code' ); |
1451
|
|
|
} |
1452
|
|
|
} |
1453
|
|
|
|
1454
|
|
|
/** |
1455
|
|
|
* Correct currency code for "Iranian Currency" in Give setting. |
1456
|
|
|
* Version 1.8.17 automatic updates |
1457
|
|
|
* |
1458
|
|
|
* @since 1.8.17 |
1459
|
|
|
*/ |
1460
|
|
|
function give_v1817_upgrades() { |
1461
|
|
|
$give_settings = give_get_settings(); |
1462
|
|
|
|
1463
|
|
|
if ( 'RIAL' === $give_settings['currency'] ) { |
1464
|
|
|
$give_settings['currency'] = 'IRR'; |
1465
|
|
|
update_option( 'give_settings', $give_settings ); |
1466
|
|
|
} |
1467
|
|
|
} |
1468
|
|
|
|
1469
|
|
|
/** |
1470
|
|
|
* Process Clean up of User Roles for more flexibility. |
1471
|
|
|
* |
1472
|
|
|
* @since 1.8.17 |
1473
|
|
|
*/ |
1474
|
|
|
function give_v1817_process_cleanup_user_roles() { |
1475
|
|
|
|
1476
|
|
|
global $wp_roles; |
1477
|
|
|
|
1478
|
|
|
if( ! ( $wp_roles instanceof WP_Roles ) ) { |
|
|
|
|
1479
|
|
|
return; |
1480
|
|
|
} |
1481
|
|
|
|
1482
|
|
|
// Add Capabilities to user roles as required. |
1483
|
|
|
$add_caps = array( |
1484
|
|
|
'administrator' => array( |
1485
|
|
|
'view_give_payments', |
1486
|
|
|
), |
1487
|
|
|
); |
1488
|
|
|
|
1489
|
|
|
// Remove Capabilities to user roles as required. |
1490
|
|
|
$remove_caps = array( |
1491
|
|
|
'give_manager' => array( |
1492
|
|
|
'edit_others_pages', |
1493
|
|
|
'edit_others_posts', |
1494
|
|
|
'delete_others_pages', |
1495
|
|
|
'delete_others_posts', |
1496
|
|
|
'manage_categories', |
1497
|
|
|
'import', |
1498
|
|
|
'export', |
1499
|
|
|
), |
1500
|
|
|
); |
1501
|
|
|
|
1502
|
|
|
foreach ( $add_caps as $role => $caps ) { |
1503
|
|
|
foreach ( $caps as $cap ) { |
1504
|
|
|
$wp_roles->add_cap( $role, $cap ); |
1505
|
|
|
} |
1506
|
|
|
} |
1507
|
|
|
|
1508
|
|
|
foreach ( $remove_caps as $role => $caps ) { |
1509
|
|
|
foreach ( $caps as $cap ) { |
1510
|
|
|
$wp_roles->remove_cap( $role, $cap ); |
1511
|
|
|
} |
1512
|
|
|
} |
1513
|
|
|
|
1514
|
|
|
} |
1515
|
|
|
|
1516
|
|
|
/** |
1517
|
|
|
* Upgrade Routine - Clean up of User Roles for more flexibility. |
1518
|
|
|
* |
1519
|
|
|
* @since 1.8.17 |
1520
|
|
|
*/ |
1521
|
|
|
function give_v1817_cleanup_user_roles() { |
1522
|
|
|
/* @var Give_Updates $give_updates */ |
1523
|
|
|
$give_updates = Give_Updates::get_instance(); |
1524
|
|
|
|
1525
|
|
|
give_v1817_process_cleanup_user_roles(); |
1526
|
|
|
|
1527
|
|
|
$give_updates->percentage = 100; |
|
|
|
|
1528
|
|
|
|
1529
|
|
|
// Create Give plugin roles. |
1530
|
|
|
$roles = new Give_Roles(); |
1531
|
|
|
$roles->add_roles(); |
1532
|
|
|
$roles->add_caps(); |
1533
|
|
|
|
1534
|
|
|
give_set_upgrade_complete( 'v1817_cleanup_user_roles' ); |
1535
|
|
|
} |
1536
|
|
|
|
1537
|
|
|
/** |
1538
|
|
|
* Automatic Upgrade for release 1.8.18. |
1539
|
|
|
* |
1540
|
|
|
* @since 1.8.18 |
1541
|
|
|
*/ |
1542
|
|
|
function give_v1818_upgrades() { |
1543
|
|
|
|
1544
|
|
|
// Remove email_access_installed from give_settings. |
1545
|
|
|
give_delete_option( 'email_access_installed' ); |
1546
|
|
|
} |
1547
|
|
|
|
1548
|
|
|
/** |
1549
|
|
|
* Upgrade Routine - Assigns Custom Amount to existing donation of type set donation. |
1550
|
|
|
* |
1551
|
|
|
* @since 1.8.18 |
1552
|
|
|
*/ |
1553
|
|
|
function give_v1818_assign_custom_amount_set_donation() { |
1554
|
|
|
|
1555
|
|
|
/* @var Give_Updates $give_updates */ |
1556
|
|
|
$give_updates = Give_Updates::get_instance(); |
1557
|
|
|
|
1558
|
|
|
$donations = new WP_Query( array( |
1559
|
|
|
'paged' => $give_updates->step, |
1560
|
|
|
'status' => 'any', |
1561
|
|
|
'order' => 'ASC', |
1562
|
|
|
'post_type' => array( 'give_payment' ), |
1563
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1564
|
|
|
) |
1565
|
|
|
); |
1566
|
|
|
|
1567
|
|
|
if ( $donations->have_posts() ) { |
1568
|
|
|
$give_updates->set_percentage( $donations->found_posts, $give_updates->step * 100 ); |
1569
|
|
|
|
1570
|
|
|
while ( $donations->have_posts() ) { |
1571
|
|
|
$donations->the_post(); |
1572
|
|
|
|
1573
|
|
|
$form = new Give_Donate_Form( give_get_meta( get_the_ID(), '_give_payment_form_id', true ) ); |
1574
|
|
|
$donation_meta = give_get_payment_meta( get_the_ID() ); |
1575
|
|
|
|
1576
|
|
|
// Update Donation meta with price_id set as custom, only if it is: |
1577
|
|
|
// 1. Donation Type = Set Donation. |
1578
|
|
|
// 2. Donation Price Id is not set to custom. |
1579
|
|
|
// 3. Form has not enabled custom price and donation amount assures that it is custom amount. |
1580
|
|
|
if ( |
1581
|
|
|
$form->ID && |
1582
|
|
|
$form->is_set_type_donation_form() && |
1583
|
|
|
( 'custom' !== $donation_meta['price_id'] ) && |
1584
|
|
|
$form->is_custom_price( give_get_meta( get_the_ID(), '_give_payment_total', true ) ) |
1585
|
|
|
) { |
1586
|
|
|
$donation_meta['price_id'] = 'custom'; |
1587
|
|
|
give_update_meta( get_the_ID(), '_give_payment_meta', $donation_meta ); |
1588
|
|
|
give_update_meta( get_the_ID(), '_give_payment_price_id', 'custom' ); |
1589
|
|
|
} |
1590
|
|
|
} |
1591
|
|
|
|
1592
|
|
|
wp_reset_postdata(); |
1593
|
|
|
} else { |
1594
|
|
|
// Update Ran Successfully. |
1595
|
|
|
give_set_upgrade_complete( 'v1818_assign_custom_amount_set_donation' ); |
1596
|
|
|
} |
1597
|
|
|
} |
1598
|
|
|
|
1599
|
|
|
/** |
1600
|
|
|
* Upgrade Routine - Removed Give Worker caps. |
1601
|
|
|
* |
1602
|
|
|
* See: https://github.com/WordImpress/Give/issues/2476 |
1603
|
|
|
* |
1604
|
|
|
* @since 1.8.18 |
1605
|
|
|
*/ |
1606
|
|
|
function give_v1818_give_worker_role_cleanup(){ |
1607
|
|
|
|
1608
|
|
|
/* @var Give_Updates $give_updates */ |
1609
|
|
|
$give_updates = Give_Updates::get_instance(); |
1610
|
|
|
|
1611
|
|
|
global $wp_roles; |
1612
|
|
|
|
1613
|
|
|
if( ! ( $wp_roles instanceof WP_Roles ) ) { |
|
|
|
|
1614
|
|
|
return; |
1615
|
|
|
} |
1616
|
|
|
|
1617
|
|
|
// Remove Capabilities to user roles as required. |
1618
|
|
|
$remove_caps = array( |
1619
|
|
|
'give_worker' => array( |
1620
|
|
|
'delete_give_payments', |
1621
|
|
|
'delete_others_give_payments', |
1622
|
|
|
'delete_private_give_payments', |
1623
|
|
|
'delete_published_give_payments', |
1624
|
|
|
'edit_others_give_payments', |
1625
|
|
|
'edit_private_give_payments', |
1626
|
|
|
'edit_published_give_payments', |
1627
|
|
|
'read_private_give_payments', |
1628
|
|
|
), |
1629
|
|
|
); |
1630
|
|
|
|
1631
|
|
|
foreach ( $remove_caps as $role => $caps ) { |
1632
|
|
|
foreach( $caps as $cap ) { |
|
|
|
|
1633
|
|
|
$wp_roles->remove_cap( $role, $cap ); |
1634
|
|
|
} |
1635
|
|
|
} |
1636
|
|
|
|
1637
|
|
|
$give_updates->percentage = 100; |
|
|
|
|
1638
|
|
|
|
1639
|
|
|
// Create Give plugin roles. |
1640
|
|
|
$roles = new Give_Roles(); |
1641
|
|
|
$roles->add_roles(); |
1642
|
|
|
$roles->add_caps(); |
1643
|
|
|
|
1644
|
|
|
give_set_upgrade_complete( 'v1818_give_worker_role_cleanup' ); |
1645
|
|
|
} |
1646
|
|
|
|
1647
|
|
|
/** |
1648
|
|
|
* |
1649
|
|
|
* Upgrade form metadata for new metabox settings. |
1650
|
|
|
* |
1651
|
|
|
* @since 2.0 |
1652
|
|
|
* @return void |
1653
|
|
|
*/ |
1654
|
|
|
function give_v20_upgrades_form_metadata_callback() { |
1655
|
|
|
$give_updates = Give_Updates::get_instance(); |
1656
|
|
|
|
1657
|
|
|
// form query |
1658
|
|
|
$forms = new WP_Query( array( |
1659
|
|
|
'paged' => $give_updates->step, |
1660
|
|
|
'status' => 'any', |
1661
|
|
|
'order' => 'ASC', |
1662
|
|
|
'post_type' => 'give_forms', |
1663
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1664
|
|
|
) |
1665
|
|
|
); |
1666
|
|
|
|
1667
|
|
|
if ( $forms->have_posts() ) { |
1668
|
|
|
$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
1669
|
|
|
|
1670
|
|
|
while ( $forms->have_posts() ) { |
1671
|
|
|
$forms->the_post(); |
1672
|
|
|
global $post; |
1673
|
|
|
|
1674
|
|
|
// Update offline instruction email notification status. |
1675
|
|
|
$offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
1676
|
|
|
$offline_instruction_notification_status = give_is_setting_enabled( $offline_instruction_notification_status, array( |
|
|
|
|
1677
|
|
|
'enabled', |
1678
|
|
|
'global', |
1679
|
|
|
) ) |
1680
|
|
|
? $offline_instruction_notification_status |
1681
|
|
|
: 'global'; |
1682
|
|
|
update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status ); |
1683
|
|
|
|
1684
|
|
|
// Update offline instruction email message. |
1685
|
|
|
update_post_meta( |
1686
|
|
|
get_the_ID(), |
1687
|
|
|
'_give_offline-donation-instruction_email_message', |
1688
|
|
|
get_post_meta( |
1689
|
|
|
get_the_ID(), |
1690
|
|
|
// @todo: Delete this option later ( version > 2.0 ). |
1691
|
|
|
'_give_offline_donation_email', |
1692
|
|
|
true |
1693
|
|
|
) |
1694
|
|
|
); |
1695
|
|
|
|
1696
|
|
|
// Update offline instruction email subject. |
1697
|
|
|
update_post_meta( |
1698
|
|
|
get_the_ID(), |
1699
|
|
|
'_give_offline-donation-instruction_email_subject', |
1700
|
|
|
get_post_meta( |
1701
|
|
|
get_the_ID(), |
1702
|
|
|
// @todo: Delete this option later ( version > 2.0 ). |
1703
|
|
|
'_give_offline_donation_subject', |
1704
|
|
|
true |
1705
|
|
|
) |
1706
|
|
|
); |
1707
|
|
|
|
|
|
|
|
1708
|
|
|
|
1709
|
|
|
}// End while(). |
1710
|
|
|
|
1711
|
|
|
wp_reset_postdata(); |
1712
|
|
|
} else { |
1713
|
|
|
// No more forms found, finish up. |
1714
|
|
|
give_set_upgrade_complete( 'v20_upgrades_form_metadata' ); |
1715
|
|
|
} |
1716
|
|
|
} |
1717
|
|
|
|
1718
|
|
|
|
1719
|
|
|
/** |
1720
|
|
|
* Upgrade payment metadata for new metabox settings. |
1721
|
|
|
* |
1722
|
|
|
* @since 2.0 |
1723
|
|
|
* @global wpdb $wpdb |
1724
|
|
|
* @return void |
1725
|
|
|
*/ |
1726
|
|
|
function give_v20_upgrades_payment_metadata_callback() { |
1727
|
|
|
global $wpdb; |
1728
|
|
|
$give_updates = Give_Updates::get_instance(); |
1729
|
|
|
|
1730
|
|
|
// form query |
1731
|
|
|
$forms = new WP_Query( array( |
1732
|
|
|
'paged' => $give_updates->step, |
1733
|
|
|
'status' => 'any', |
1734
|
|
|
'order' => 'ASC', |
1735
|
|
|
'post_type' => 'give_payment', |
1736
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1737
|
|
|
) |
1738
|
|
|
); |
1739
|
|
|
|
1740
|
|
|
if ( $forms->have_posts() ) { |
1741
|
|
|
$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
1742
|
|
|
|
1743
|
|
|
while ( $forms->have_posts() ) { |
1744
|
|
|
$forms->the_post(); |
1745
|
|
|
global $post; |
1746
|
|
|
|
1747
|
|
|
// Split _give_payment_meta meta. |
1748
|
|
|
// @todo Remove _give_payment_meta after releases 2.0 |
1749
|
|
|
$payment_meta = give_get_meta( $post->ID, '_give_payment_meta', true ); |
1750
|
|
|
|
1751
|
|
|
if ( ! empty( $payment_meta ) ) { |
1752
|
|
|
_give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
1753
|
|
|
} |
1754
|
|
|
|
1755
|
|
|
$deprecated_meta_keys = array( |
1756
|
|
|
'_give_payment_customer_id' => '_give_payment_donor_id', |
1757
|
|
|
'_give_payment_user_email' => '_give_payment_donor_email', |
1758
|
|
|
'_give_payment_user_ip' => '_give_payment_donor_ip', |
1759
|
|
|
); |
1760
|
|
|
|
1761
|
|
View Code Duplication |
foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
|
|
|
|
1762
|
|
|
// Do not add new meta key if already exist. |
1763
|
|
|
if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, $new_meta_key ) ) ) { |
|
|
|
|
1764
|
|
|
continue; |
1765
|
|
|
} |
1766
|
|
|
|
1767
|
|
|
$wpdb->insert( |
|
|
|
|
1768
|
|
|
$wpdb->postmeta, |
1769
|
|
|
array( |
1770
|
|
|
'post_id' => $post->ID, |
1771
|
|
|
'meta_key' => $new_meta_key, |
|
|
|
|
1772
|
|
|
'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ) |
|
|
|
|
1773
|
|
|
) |
1774
|
|
|
); |
1775
|
|
|
} |
1776
|
|
|
|
1777
|
|
|
// Bailout |
1778
|
|
View Code Duplication |
if ( $donor_id = give_get_meta( $post->ID, '_give_payment_donor_id', true ) ) { |
|
|
|
|
1779
|
|
|
/* @var Give_Donor $donor */ |
1780
|
|
|
$donor = new Give_Donor( $donor_id ); |
1781
|
|
|
|
1782
|
|
|
$address['line1'] = give_get_meta( $post->ID, '_give_donor_billing_address1', true, '' ); |
|
|
|
|
1783
|
|
|
$address['line2'] = give_get_meta( $post->ID, '_give_donor_billing_address2', true, '' ); |
|
|
|
|
1784
|
|
|
$address['city'] = give_get_meta( $post->ID, '_give_donor_billing_city', true, '' ); |
|
|
|
|
1785
|
|
|
$address['state'] = give_get_meta( $post->ID, '_give_donor_billing_state', true, '' ); |
|
|
|
|
1786
|
|
|
$address['zip'] = give_get_meta( $post->ID, '_give_donor_billing_zip', true, '' ); |
|
|
|
|
1787
|
|
|
$address['country'] = give_get_meta( $post->ID, '_give_donor_billing_country', true, '' ); |
|
|
|
|
1788
|
|
|
|
1789
|
|
|
// Save address. |
1790
|
|
|
$donor->add_address( 'billing[]', $address ); |
1791
|
|
|
} |
|
|
|
|
1792
|
|
|
|
1793
|
|
|
}// End while(). |
1794
|
|
|
|
1795
|
|
|
wp_reset_postdata(); |
1796
|
|
|
} else { |
1797
|
|
|
// @todo Delete user id meta after releases 2.0 |
1798
|
|
|
// $wpdb->get_var( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_user_id' ) ); |
1799
|
|
|
|
1800
|
|
|
// No more forms found, finish up. |
1801
|
|
|
give_set_upgrade_complete( 'v20_upgrades_payment_metadata' ); |
1802
|
|
|
} |
1803
|
|
|
} |
1804
|
|
|
|
1805
|
|
|
|
1806
|
|
|
/** |
1807
|
|
|
* Upgrade logs data. |
1808
|
|
|
* |
1809
|
|
|
* @since 2.0 |
1810
|
|
|
* @return void |
1811
|
|
|
*/ |
1812
|
|
View Code Duplication |
function give_v20_logs_upgrades_callback() { |
|
|
|
|
1813
|
|
|
global $wpdb; |
1814
|
|
|
$give_updates = Give_Updates::get_instance(); |
1815
|
|
|
|
1816
|
|
|
// form query |
1817
|
|
|
$forms = new WP_Query( array( |
1818
|
|
|
'paged' => $give_updates->step, |
1819
|
|
|
'order' => 'DESC', |
1820
|
|
|
'post_type' => 'give_log', |
1821
|
|
|
'post_status' => 'any', |
1822
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1823
|
|
|
) |
1824
|
|
|
); |
1825
|
|
|
|
1826
|
|
|
if ( $forms->have_posts() ) { |
1827
|
|
|
$give_updates->set_percentage( $forms->found_posts, $give_updates->step * 100 ); |
1828
|
|
|
|
1829
|
|
|
while ( $forms->have_posts() ) { |
1830
|
|
|
$forms->the_post(); |
1831
|
|
|
global $post; |
1832
|
|
|
|
1833
|
|
|
if( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { |
|
|
|
|
1834
|
|
|
continue; |
1835
|
|
|
} |
1836
|
|
|
|
1837
|
|
|
$term = get_the_terms( $post->ID, 'give_log_type' ); |
1838
|
|
|
$term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); |
1839
|
|
|
$term_name = ! empty( $term ) ? $term->slug : ''; |
1840
|
|
|
|
1841
|
|
|
$log_data = array( |
1842
|
|
|
'ID' => $post->ID, |
1843
|
|
|
'log_title' => $post->post_title, |
1844
|
|
|
'log_content' => $post->post_content, |
1845
|
|
|
'log_parent' => 0, |
1846
|
|
|
'log_type' => $term_name, |
1847
|
|
|
'log_date' => $post->post_date, |
1848
|
|
|
'log_date_gmt' => $post->post_date_gmt, |
1849
|
|
|
); |
1850
|
|
|
$log_meta = array(); |
1851
|
|
|
|
1852
|
|
|
if ( $old_log_meta = get_post_meta( $post->ID ) ) { |
1853
|
|
|
foreach ( $old_log_meta as $meta_key => $meta_value ) { |
1854
|
|
|
switch ( $meta_key ) { |
1855
|
|
|
case '_give_log_payment_id': |
1856
|
|
|
$log_data['log_parent'] = current( $meta_value ); |
1857
|
|
|
$log_meta['_give_log_form_id'] = $post->post_parent; |
1858
|
|
|
break; |
1859
|
|
|
|
1860
|
|
|
default: |
1861
|
|
|
$log_meta[ $meta_key ] = current( $meta_value ); |
1862
|
|
|
} |
1863
|
|
|
} |
1864
|
|
|
} |
1865
|
|
|
|
1866
|
|
|
if ( 'api_request' === $term_name ) { |
1867
|
|
|
$log_meta['_give_log_api_query'] = $post->post_excerpt; |
1868
|
|
|
} |
1869
|
|
|
|
1870
|
|
|
$wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); |
|
|
|
|
1871
|
|
|
|
1872
|
|
|
if ( ! empty( $log_meta ) ) { |
1873
|
|
|
foreach ( $log_meta as $meta_key => $meta_value ) { |
1874
|
|
|
Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); |
1875
|
|
|
} |
1876
|
|
|
} |
1877
|
|
|
|
1878
|
|
|
$logIDs[] = $post->ID; |
1879
|
|
|
}// End while(). |
1880
|
|
|
|
1881
|
|
|
wp_reset_postdata(); |
1882
|
|
|
} else { |
1883
|
|
|
// @todo: Delete terms and taxonomy after releases 2.0. |
1884
|
|
|
/*$terms = get_terms( 'give_log_type', array( 'fields' => 'ids', 'hide_empty' => false ) ); |
1885
|
|
|
if ( ! empty( $terms ) ) { |
1886
|
|
|
foreach ( $terms as $term ) { |
1887
|
|
|
wp_delete_term( $term, 'give_log_type' ); |
1888
|
|
|
} |
1889
|
|
|
}*/ |
1890
|
|
|
|
1891
|
|
|
// @todo: Delete logs after releases 2.0. |
1892
|
|
|
/*$logIDs = get_posts( array( |
1893
|
|
|
'order' => 'DESC', |
1894
|
|
|
'post_type' => 'give_log', |
1895
|
|
|
'post_status' => 'any', |
1896
|
|
|
'posts_per_page' => - 1, |
1897
|
|
|
'fields' => 'ids', |
1898
|
|
|
) |
1899
|
|
|
);*/ |
1900
|
|
|
|
1901
|
|
|
/*if ( ! empty( $logIDs ) ) { |
1902
|
|
|
foreach ( $logIDs as $log ) { |
1903
|
|
|
// Delete term relationship and posts. |
1904
|
|
|
wp_delete_object_term_relationships( $log, 'give_log_type' ); |
1905
|
|
|
wp_delete_post( $log, true ); |
1906
|
|
|
} |
1907
|
|
|
}*/ |
1908
|
|
|
|
1909
|
|
|
// @todo: Unregister taxonomy after releases 2.0. |
1910
|
|
|
/*unregister_taxonomy( 'give_log_type' );*/ |
1911
|
|
|
|
1912
|
|
|
// Delete log cache. |
1913
|
|
|
Give()->logs->delete_cache(); |
1914
|
|
|
|
1915
|
|
|
// No more forms found, finish up. |
1916
|
|
|
give_set_upgrade_complete( 'v20_logs_upgrades' ); |
1917
|
|
|
} |
1918
|
|
|
} |
1919
|
|
|
|
1920
|
|
|
|
1921
|
|
|
/** |
1922
|
|
|
* Move payment and form metadata to new table |
1923
|
|
|
* |
1924
|
|
|
* @since 2.0 |
1925
|
|
|
* @return void |
1926
|
|
|
*/ |
1927
|
|
View Code Duplication |
function give_v20_move_metadata_into_new_table_callback() { |
|
|
|
|
1928
|
|
|
global $wpdb; |
1929
|
|
|
$give_updates = Give_Updates::get_instance(); |
1930
|
|
|
|
1931
|
|
|
// form query |
1932
|
|
|
$payments = new WP_Query( array( |
1933
|
|
|
'paged' => $give_updates->step, |
1934
|
|
|
'status' => 'any', |
1935
|
|
|
'order' => 'ASC', |
1936
|
|
|
'post_type' => array( 'give_forms', 'give_payment' ), |
1937
|
|
|
'posts_per_page' => 100, |
|
|
|
|
1938
|
|
|
) |
1939
|
|
|
); |
1940
|
|
|
|
1941
|
|
|
if ( $payments->have_posts() ) { |
1942
|
|
|
$give_updates->set_percentage( $payments->found_posts, $give_updates->step * 100 ); |
1943
|
|
|
|
1944
|
|
|
while ( $payments->have_posts() ) { |
1945
|
|
|
$payments->the_post(); |
1946
|
|
|
global $post; |
1947
|
|
|
|
1948
|
|
|
$meta_data = $wpdb->get_results( |
|
|
|
|
1949
|
|
|
$wpdb->prepare( |
1950
|
|
|
"SELECT * FROM $wpdb->postmeta where post_id=%d", |
1951
|
|
|
get_the_ID() |
1952
|
|
|
), |
1953
|
|
|
ARRAY_A |
1954
|
|
|
); |
1955
|
|
|
|
1956
|
|
|
if ( ! empty( $meta_data ) ) { |
1957
|
|
|
foreach ( $meta_data as $index => $data ) { |
1958
|
|
|
// Check for duplicate meta values. |
1959
|
|
|
if( $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->paymentmeta ) . " WHERE meta_id=%d", $data['meta_id'] ), ARRAY_A ) ) { |
|
|
|
|
1960
|
|
|
continue; |
1961
|
|
|
} |
1962
|
|
|
|
1963
|
|
|
switch ( $post->post_type ) { |
1964
|
|
|
case 'give_forms': |
1965
|
|
|
$data['form_id'] = $data['post_id']; |
1966
|
|
|
unset( $data['post_id'] ); |
1967
|
|
|
|
1968
|
|
|
Give()->form_meta->insert( $data ); |
1969
|
|
|
// @todo: delete form meta from post meta table after releases 2.0. |
1970
|
|
|
/*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
1971
|
|
|
|
1972
|
|
|
break; |
1973
|
|
|
|
1974
|
|
|
case 'give_payment': |
1975
|
|
|
$data['payment_id'] = $data['post_id']; |
1976
|
|
|
unset( $data['post_id'] ); |
1977
|
|
|
|
1978
|
|
|
Give()->payment_meta->insert( $data ); |
1979
|
|
|
|
1980
|
|
|
// @todo: delete donation meta from post meta table after releases 2.0. |
1981
|
|
|
/*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
1982
|
|
|
|
1983
|
|
|
break; |
1984
|
|
|
} |
1985
|
|
|
} |
1986
|
|
|
} |
|
|
|
|
1987
|
|
|
|
1988
|
|
|
}// End while(). |
1989
|
|
|
|
1990
|
|
|
wp_reset_postdata(); |
1991
|
|
|
} else { |
1992
|
|
|
// No more forms found, finish up. |
1993
|
|
|
give_set_upgrade_complete( 'v20_move_metadata_into_new_table' ); |
1994
|
|
|
} |
1995
|
|
|
|
1996
|
|
|
} |
1997
|
|
|
|
1998
|
|
|
/** |
1999
|
|
|
* Upgrade routine for splitting donor name into first name and last name. |
2000
|
|
|
* |
2001
|
|
|
* @since 2.0 |
2002
|
|
|
* |
2003
|
|
|
* @return void |
2004
|
|
|
*/ |
2005
|
|
|
function give_v20_upgrades_donor_name() { |
2006
|
|
|
/* @var Give_Updates $give_updates */ |
2007
|
|
|
$give_updates = Give_Updates::get_instance(); |
2008
|
|
|
|
2009
|
|
|
$donors = Give()->donors->get_donors( array( |
2010
|
|
|
'paged' => $give_updates->step, |
2011
|
|
|
'number' => 100, |
2012
|
|
|
) ); |
2013
|
|
|
|
2014
|
|
|
if ( $donors ) { |
2015
|
|
|
$give_updates->set_percentage( count( $donors ), $give_updates->step * 100 ); |
2016
|
|
|
// Loop through Donors |
2017
|
|
|
foreach ( $donors as $donor ) { |
2018
|
|
|
|
2019
|
|
|
$donor_name = explode( ' ', $donor->name, 2 ); |
2020
|
|
|
$donor_first_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_first_name' ); |
2021
|
|
|
$donor_last_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_last_name' ); |
2022
|
|
|
|
2023
|
|
|
// If first name meta of donor is not created, then create it. |
2024
|
|
View Code Duplication |
if ( ! $donor_first_name && isset( $donor_name[0] ) ) { |
|
|
|
|
2025
|
|
|
Give()->donor_meta->add_meta( $donor->id, '_give_donor_first_name', $donor_name[0] ); |
2026
|
|
|
} |
2027
|
|
|
|
2028
|
|
|
// If last name meta of donor is not created, then create it. |
2029
|
|
View Code Duplication |
if ( ! $donor_last_name && isset( $donor_name[1] ) ) { |
|
|
|
|
2030
|
|
|
Give()->donor_meta->add_meta( $donor->id, '_give_donor_last_name', $donor_name[1] ); |
2031
|
|
|
} |
2032
|
|
|
|
2033
|
|
|
// If Donor is connected with WP User then update user meta. |
2034
|
|
View Code Duplication |
if ( $donor->user_id ) { |
|
|
|
|
2035
|
|
|
if ( isset( $donor_name[0] ) ) { |
2036
|
|
|
update_user_meta( $donor->user_id, 'first_name', $donor_name[0] ); |
|
|
|
|
2037
|
|
|
} |
2038
|
|
|
if ( isset( $donor_name[1] ) ) { |
2039
|
|
|
update_user_meta( $donor->user_id, 'last_name', $donor_name[1] ); |
|
|
|
|
2040
|
|
|
} |
2041
|
|
|
} |
2042
|
|
|
} |
|
|
|
|
2043
|
|
|
|
2044
|
|
|
} else { |
2045
|
|
|
// The Update Ran. |
2046
|
|
|
give_set_upgrade_complete( 'v20_upgrades_donor_name' ); |
2047
|
|
|
} |
2048
|
|
|
|
2049
|
|
|
} |
2050
|
|
|
|
2051
|
|
|
/** |
2052
|
|
|
* Upgrade routine for user addresses. |
2053
|
|
|
* |
2054
|
|
|
* @since 2.0 |
2055
|
|
|
* @global wpdb $wpdb |
2056
|
|
|
* |
2057
|
|
|
* @return void |
2058
|
|
|
*/ |
2059
|
|
|
function give_v20_upgrades_user_address() { |
2060
|
|
|
global $wpdb; |
2061
|
|
|
|
2062
|
|
|
/* @var Give_Updates $give_updates */ |
2063
|
|
|
$give_updates = Give_Updates::get_instance(); |
2064
|
|
|
|
2065
|
|
|
/* @var WP_User_Query $user_query */ |
2066
|
|
|
$user_query = new WP_User_Query( |
2067
|
|
|
array( |
2068
|
|
|
'number' => 100, |
2069
|
|
|
'paged' => $give_updates->step, |
2070
|
|
|
) |
2071
|
|
|
); |
2072
|
|
|
|
2073
|
|
|
$users = $user_query->get_results(); |
2074
|
|
|
|
2075
|
|
|
if ( $users ) { |
2076
|
|
|
$give_updates->set_percentage( $user_query->get_total(), $give_updates->step * 100 ); |
2077
|
|
|
|
2078
|
|
|
// Loop through Donors |
2079
|
|
|
foreach ( $users as $user ) { |
2080
|
|
|
/* @var Give_Donor $donor */ |
2081
|
|
|
$donor = new Give_Donor( $user->ID, true ); |
2082
|
|
|
|
2083
|
|
|
if ( ! $donor->id ) { |
2084
|
|
|
continue; |
2085
|
|
|
} |
2086
|
|
|
|
2087
|
|
|
$address = $wpdb->get_var( |
|
|
|
|
2088
|
|
|
$wpdb->prepare( |
2089
|
|
|
" |
2090
|
|
|
SELECT meta_value FROM {$wpdb->usermeta} |
|
|
|
|
2091
|
|
|
WHERE user_id=%s |
2092
|
|
|
AND meta_key=%s |
2093
|
|
|
", |
2094
|
|
|
$user->ID, |
2095
|
|
|
'_give_user_address' |
2096
|
|
|
) |
2097
|
|
|
); |
2098
|
|
|
|
2099
|
|
View Code Duplication |
if ( ! empty( $address ) ) { |
|
|
|
|
2100
|
|
|
$address = maybe_unserialize( $address ); |
2101
|
|
|
$donor->add_address( 'personal', $address ); |
2102
|
|
|
$donor->add_address( 'billing[]', $address ); |
2103
|
|
|
|
|
|
|
|
2104
|
|
|
|
2105
|
|
|
// @todo: delete _give_user_address from user meta after releases 2.0. |
2106
|
|
|
/*delete_user_meta( $user->ID, '_give_user_address' );*/ |
2107
|
|
|
} |
2108
|
|
|
} |
|
|
|
|
2109
|
|
|
|
2110
|
|
|
} else { |
2111
|
|
|
// The Update Ran. |
2112
|
|
|
give_set_upgrade_complete( 'v20_upgrades_user_address' ); |
2113
|
|
|
} |
2114
|
|
|
|
2115
|
|
|
} |
2116
|
|
|
|
2117
|
|
|
/** |
2118
|
|
|
* Upgrade logs data. |
2119
|
|
|
* |
2120
|
|
|
* @since 2.0 |
2121
|
|
|
* @global wpdb $wpdb |
2122
|
|
|
* @return void |
2123
|
|
|
*/ |
2124
|
|
|
function give_v20_rename_donor_tables_callback() { |
2125
|
|
|
global $wpdb; |
2126
|
|
|
|
2127
|
|
|
/* @var Give_Updates $give_updates */ |
2128
|
|
|
$give_updates = Give_Updates::get_instance(); |
2129
|
|
|
|
2130
|
|
|
$tables = array( |
2131
|
|
|
"{$wpdb->prefix}give_customers" => "{$wpdb->prefix}give_donors", |
2132
|
|
|
"{$wpdb->prefix}give_customermeta" => "{$wpdb->prefix}give_donormeta", |
2133
|
|
|
); |
2134
|
|
|
|
2135
|
|
|
// Alter customer table |
2136
|
|
|
foreach ( $tables as $old_table => $new_table ) { |
2137
|
|
|
if ( |
2138
|
|
|
$wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $old_table ) ) && |
|
|
|
|
2139
|
|
|
! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $new_table ) ) |
|
|
|
|
2140
|
|
|
) { |
2141
|
|
|
$wpdb->query( "ALTER TABLE {$old_table} RENAME TO {$new_table}" ); |
|
|
|
|
2142
|
|
|
|
2143
|
|
|
if ( "{$wpdb->prefix}give_donormeta" === $new_table ) { |
2144
|
|
|
$wpdb->query( "ALTER TABLE {$new_table} CHANGE COLUMN customer_id donor_id bigint(20)" ); |
|
|
|
|
2145
|
|
|
} |
2146
|
|
|
} |
2147
|
|
|
} |
2148
|
|
|
|
2149
|
|
|
$give_updates->percentage = 100; |
|
|
|
|
2150
|
|
|
|
2151
|
|
|
// No more forms found, finish up. |
2152
|
|
|
give_set_upgrade_complete( 'v20_rename_donor_tables' ); |
2153
|
|
|
|
2154
|
|
|
// Re initiate donor classes. |
2155
|
|
|
Give()->donors = new Give_DB_Donors(); |
2156
|
|
|
Give()->donor_meta = new Give_DB_Donor_Meta(); |
2157
|
|
|
} |
2158
|
|
|
|
2159
|
|
|
|
2160
|
|
|
/** |
2161
|
|
|
* Create missing meta tables. |
2162
|
|
|
* |
2163
|
|
|
* @since 2.0.1 |
2164
|
|
|
* @global wpdb $wpdb |
2165
|
|
|
* @return void |
2166
|
|
|
*/ |
2167
|
|
|
function give_v201_create_tables(){ |
2168
|
|
|
global $wpdb; |
2169
|
|
|
|
2170
|
|
|
if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_paymentmeta" ) ) ) { |
|
|
|
|
2171
|
|
|
Give()->payment_meta->create_table(); |
2172
|
|
|
} |
2173
|
|
|
|
2174
|
|
|
if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_formmeta" ) ) ) { |
|
|
|
|
2175
|
|
|
Give()->form_meta->create_table(); |
2176
|
|
|
} |
2177
|
|
|
|
2178
|
|
|
if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_logs" ) ) ) { |
|
|
|
|
2179
|
|
|
Give()->logs->log_db->create_table(); |
2180
|
|
|
} |
2181
|
|
|
|
2182
|
|
|
if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_logmeta" ) ) ) { |
|
|
|
|
2183
|
|
|
Give()->logs->logmeta_db->create_table(); |
2184
|
|
|
} |
2185
|
|
|
} |
2186
|
|
|
|
2187
|
|
|
/** |
2188
|
|
|
* Upgrade payment metadata for new metabox settings. |
2189
|
|
|
* |
2190
|
|
|
* @since 2.0.1 |
2191
|
|
|
* @global wpdb $wpdb |
2192
|
|
|
* @return void |
2193
|
|
|
*/ |
2194
|
|
|
function give_v201_upgrades_payment_metadata_callback() { |
2195
|
|
|
global $wpdb; |
2196
|
|
|
$give_updates = Give_Updates::get_instance(); |
2197
|
|
|
|
2198
|
|
|
// form query |
2199
|
|
|
$forms = new WP_Query( array( |
2200
|
|
|
'paged' => $give_updates->step, |
2201
|
|
|
'status' => 'any', |
2202
|
|
|
'order' => 'ASC', |
2203
|
|
|
'post_type' => 'give_payment', |
2204
|
|
|
'posts_per_page' => 100, |
|
|
|
|
2205
|
|
|
'date_query' => array( |
2206
|
|
|
'after' => array( |
2207
|
|
|
'year' => 2018, |
2208
|
|
|
'month' => 1, |
2209
|
|
|
'day' => 8, |
2210
|
|
|
), |
2211
|
|
|
'inclusive' => true, |
2212
|
|
|
) |
2213
|
|
|
) |
2214
|
|
|
); |
2215
|
|
|
|
2216
|
|
|
if ( $forms->have_posts() ) { |
2217
|
|
|
$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
2218
|
|
|
|
2219
|
|
|
while ( $forms->have_posts() ) { |
2220
|
|
|
$forms->the_post(); |
2221
|
|
|
global $post; |
2222
|
|
|
|
2223
|
|
|
// Do not add new meta keys if already refactored. |
2224
|
|
|
if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, '_give_payment_donor_id' ) ) ) { |
|
|
|
|
2225
|
|
|
continue; |
2226
|
|
|
} |
2227
|
|
|
|
|
|
|
|
2228
|
|
|
|
2229
|
|
|
// Split _give_payment_meta meta. |
2230
|
|
|
// @todo Remove _give_payment_meta after releases 2.0 |
2231
|
|
|
$payment_meta = give_get_meta( $post->ID, '_give_payment_meta', true ); |
2232
|
|
|
|
2233
|
|
|
if ( ! empty( $payment_meta ) ) { |
2234
|
|
|
_give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
2235
|
|
|
} |
2236
|
|
|
|
2237
|
|
|
$deprecated_meta_keys = array( |
2238
|
|
|
'_give_payment_customer_id' => '_give_payment_donor_id', |
2239
|
|
|
'_give_payment_user_email' => '_give_payment_donor_email', |
2240
|
|
|
'_give_payment_user_ip' => '_give_payment_donor_ip', |
2241
|
|
|
); |
2242
|
|
|
|
2243
|
|
View Code Duplication |
foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
|
|
|
|
2244
|
|
|
// Do not add new meta key if already exist. |
2245
|
|
|
if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, $new_meta_key ) ) ) { |
|
|
|
|
2246
|
|
|
continue; |
2247
|
|
|
} |
2248
|
|
|
|
2249
|
|
|
$wpdb->insert( |
|
|
|
|
2250
|
|
|
$wpdb->postmeta, |
2251
|
|
|
array( |
2252
|
|
|
'post_id' => $post->ID, |
2253
|
|
|
'meta_key' => $new_meta_key, |
|
|
|
|
2254
|
|
|
'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ) |
|
|
|
|
2255
|
|
|
) |
2256
|
|
|
); |
2257
|
|
|
} |
2258
|
|
|
|
2259
|
|
|
// Bailout |
2260
|
|
View Code Duplication |
if ( $donor_id = give_get_meta( $post->ID, '_give_payment_donor_id', true ) ) { |
|
|
|
|
2261
|
|
|
/* @var Give_Donor $donor */ |
2262
|
|
|
$donor = new Give_Donor( $donor_id ); |
2263
|
|
|
|
2264
|
|
|
$address['line1'] = give_get_meta( $post->ID, '_give_donor_billing_address1', true, '' ); |
|
|
|
|
2265
|
|
|
$address['line2'] = give_get_meta( $post->ID, '_give_donor_billing_address2', true, '' ); |
|
|
|
|
2266
|
|
|
$address['city'] = give_get_meta( $post->ID, '_give_donor_billing_city', true, '' ); |
|
|
|
|
2267
|
|
|
$address['state'] = give_get_meta( $post->ID, '_give_donor_billing_state', true, '' ); |
|
|
|
|
2268
|
|
|
$address['zip'] = give_get_meta( $post->ID, '_give_donor_billing_zip', true, '' ); |
|
|
|
|
2269
|
|
|
$address['country'] = give_get_meta( $post->ID, '_give_donor_billing_country', true, '' ); |
|
|
|
|
2270
|
|
|
|
2271
|
|
|
// Save address. |
2272
|
|
|
$donor->add_address( 'billing[]', $address ); |
2273
|
|
|
} |
|
|
|
|
2274
|
|
|
|
2275
|
|
|
}// End while(). |
2276
|
|
|
|
2277
|
|
|
wp_reset_postdata(); |
2278
|
|
|
} else { |
2279
|
|
|
// @todo Delete user id meta after releases 2.0 |
2280
|
|
|
// $wpdb->get_var( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_user_id' ) ); |
2281
|
|
|
|
2282
|
|
|
// No more forms found, finish up. |
2283
|
|
|
give_set_upgrade_complete( 'v201_upgrades_payment_metadata' ); |
2284
|
|
|
} |
2285
|
|
|
} |
2286
|
|
|
|
2287
|
|
|
/** |
2288
|
|
|
* Move payment and form metadata to new table |
2289
|
|
|
* |
2290
|
|
|
* @since 2.0.1 |
2291
|
|
|
* @return void |
2292
|
|
|
*/ |
2293
|
|
View Code Duplication |
function give_v201_move_metadata_into_new_table_callback() { |
|
|
|
|
2294
|
|
|
global $wpdb; |
2295
|
|
|
$give_updates = Give_Updates::get_instance(); |
2296
|
|
|
|
2297
|
|
|
// form query |
2298
|
|
|
$payments = new WP_Query( array( |
2299
|
|
|
'paged' => $give_updates->step, |
2300
|
|
|
'status' => 'any', |
2301
|
|
|
'order' => 'ASC', |
2302
|
|
|
'post_type' => array( 'give_forms', 'give_payment' ), |
2303
|
|
|
'posts_per_page' => 100, |
|
|
|
|
2304
|
|
|
) |
2305
|
|
|
); |
2306
|
|
|
|
2307
|
|
|
if ( $payments->have_posts() ) { |
2308
|
|
|
$give_updates->set_percentage( $payments->found_posts, $give_updates->step * 100 ); |
2309
|
|
|
|
2310
|
|
|
while ( $payments->have_posts() ) { |
2311
|
|
|
$payments->the_post(); |
2312
|
|
|
global $post; |
2313
|
|
|
|
2314
|
|
|
$meta_data = $wpdb->get_results( |
|
|
|
|
2315
|
|
|
$wpdb->prepare( |
2316
|
|
|
"SELECT * FROM $wpdb->postmeta where post_id=%d", |
2317
|
|
|
get_the_ID() |
2318
|
|
|
), |
2319
|
|
|
ARRAY_A |
2320
|
|
|
); |
2321
|
|
|
|
2322
|
|
|
if ( ! empty( $meta_data ) ) { |
2323
|
|
|
foreach ( $meta_data as $index => $data ) { |
2324
|
|
|
// Check for duplicate meta values. |
2325
|
|
|
if( $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->paymentmeta ) . " WHERE meta_id=%d", $data['meta_id'] ), ARRAY_A ) ) { |
|
|
|
|
2326
|
|
|
continue; |
2327
|
|
|
} |
2328
|
|
|
|
2329
|
|
|
switch ( $post->post_type ) { |
2330
|
|
|
case 'give_forms': |
2331
|
|
|
$data['form_id'] = $data['post_id']; |
2332
|
|
|
unset( $data['post_id'] ); |
2333
|
|
|
|
2334
|
|
|
Give()->form_meta->insert( $data ); |
2335
|
|
|
// @todo: delete form meta from post meta table after releases 2.0. |
2336
|
|
|
/*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
2337
|
|
|
|
2338
|
|
|
break; |
2339
|
|
|
|
2340
|
|
|
case 'give_payment': |
2341
|
|
|
$data['payment_id'] = $data['post_id']; |
2342
|
|
|
unset( $data['post_id'] ); |
2343
|
|
|
|
2344
|
|
|
Give()->payment_meta->insert( $data ); |
2345
|
|
|
|
2346
|
|
|
// @todo: delete donation meta from post meta table after releases 2.0. |
2347
|
|
|
/*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
2348
|
|
|
|
2349
|
|
|
break; |
2350
|
|
|
} |
2351
|
|
|
} |
2352
|
|
|
} |
|
|
|
|
2353
|
|
|
|
2354
|
|
|
}// End while(). |
2355
|
|
|
|
2356
|
|
|
wp_reset_postdata(); |
2357
|
|
|
} else { |
2358
|
|
|
// No more forms found, finish up. |
2359
|
|
|
give_set_upgrade_complete( 'v201_move_metadata_into_new_table' ); |
2360
|
|
|
} |
2361
|
|
|
|
2362
|
|
|
} |
2363
|
|
|
|
2364
|
|
|
/** |
2365
|
|
|
* Move data to new log table. |
2366
|
|
|
* |
2367
|
|
|
* @since 2.0.1 |
2368
|
|
|
* @return void |
2369
|
|
|
*/ |
2370
|
|
View Code Duplication |
function give_v201_logs_upgrades_callback() { |
|
|
|
|
2371
|
|
|
global $wpdb; |
2372
|
|
|
$give_updates = Give_Updates::get_instance(); |
2373
|
|
|
|
2374
|
|
|
// form query |
2375
|
|
|
$forms = new WP_Query( array( |
2376
|
|
|
'paged' => $give_updates->step, |
2377
|
|
|
'order' => 'DESC', |
2378
|
|
|
'post_type' => 'give_log', |
2379
|
|
|
'post_status' => 'any', |
2380
|
|
|
'posts_per_page' => 100, |
|
|
|
|
2381
|
|
|
) |
2382
|
|
|
); |
2383
|
|
|
|
2384
|
|
|
if ( $forms->have_posts() ) { |
2385
|
|
|
$give_updates->set_percentage( $forms->found_posts, $give_updates->step * 100 ); |
2386
|
|
|
|
2387
|
|
|
while ( $forms->have_posts() ) { |
2388
|
|
|
$forms->the_post(); |
2389
|
|
|
global $post; |
2390
|
|
|
|
2391
|
|
|
if( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { |
|
|
|
|
2392
|
|
|
continue; |
2393
|
|
|
} |
2394
|
|
|
|
2395
|
|
|
$term = get_the_terms( $post->ID, 'give_log_type' ); |
2396
|
|
|
$term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); |
2397
|
|
|
$term_name = ! empty( $term ) ? $term->slug : ''; |
2398
|
|
|
|
2399
|
|
|
$log_data = array( |
2400
|
|
|
'ID' => $post->ID, |
2401
|
|
|
'log_title' => $post->post_title, |
2402
|
|
|
'log_content' => $post->post_content, |
2403
|
|
|
'log_parent' => 0, |
2404
|
|
|
'log_type' => $term_name, |
2405
|
|
|
'log_date' => $post->post_date, |
2406
|
|
|
'log_date_gmt' => $post->post_date_gmt, |
2407
|
|
|
); |
2408
|
|
|
$log_meta = array(); |
2409
|
|
|
|
2410
|
|
|
if ( $old_log_meta = get_post_meta( $post->ID ) ) { |
2411
|
|
|
foreach ( $old_log_meta as $meta_key => $meta_value ) { |
2412
|
|
|
switch ( $meta_key ) { |
2413
|
|
|
case '_give_log_payment_id': |
2414
|
|
|
$log_data['log_parent'] = current( $meta_value ); |
2415
|
|
|
$log_meta['_give_log_form_id'] = $post->post_parent; |
2416
|
|
|
break; |
2417
|
|
|
|
2418
|
|
|
default: |
2419
|
|
|
$log_meta[ $meta_key ] = current( $meta_value ); |
2420
|
|
|
} |
2421
|
|
|
} |
2422
|
|
|
} |
2423
|
|
|
|
2424
|
|
|
if ( 'api_request' === $term_name ) { |
2425
|
|
|
$log_meta['_give_log_api_query'] = $post->post_excerpt; |
2426
|
|
|
} |
2427
|
|
|
|
2428
|
|
|
$wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); |
|
|
|
|
2429
|
|
|
|
2430
|
|
|
if ( ! empty( $log_meta ) ) { |
2431
|
|
|
foreach ( $log_meta as $meta_key => $meta_value ) { |
2432
|
|
|
Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); |
2433
|
|
|
} |
2434
|
|
|
} |
2435
|
|
|
|
2436
|
|
|
$logIDs[] = $post->ID; |
2437
|
|
|
}// End while(). |
2438
|
|
|
|
2439
|
|
|
wp_reset_postdata(); |
2440
|
|
|
} else { |
2441
|
|
|
// Delete log cache. |
2442
|
|
|
Give()->logs->delete_cache(); |
2443
|
|
|
|
2444
|
|
|
// No more forms found, finish up. |
2445
|
|
|
give_set_upgrade_complete( 'v201_logs_upgrades' ); |
2446
|
|
|
} |
2447
|
|
|
} |
2448
|
|
|
|
2449
|
|
|
|
2450
|
|
|
/** |
2451
|
|
|
* Add missing donor. |
2452
|
|
|
* |
2453
|
|
|
* @since 2.0.1 |
2454
|
|
|
* @return void |
2455
|
|
|
*/ |
2456
|
|
|
function give_v201_add_missing_donors_callback(){ |
2457
|
|
|
global $wpdb; |
2458
|
|
|
|
2459
|
|
|
if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_customers" ) ) ) { |
|
|
|
|
2460
|
|
|
$customers = wp_list_pluck( $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}give_customers" ), 'id' ); |
|
|
|
|
2461
|
|
|
$donors = wp_list_pluck( $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}give_donors" ), 'id' ); |
|
|
|
|
2462
|
|
|
$donor_data = array(); |
2463
|
|
|
|
2464
|
|
|
if ( $missing_donors = array_diff( $customers, $donors ) ) { |
2465
|
|
|
foreach ( $missing_donors as $donor_id ) { |
2466
|
|
|
$donor_data[] = array( |
2467
|
|
|
'info' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customers WHERE id=%d", $donor_id ) ), |
|
|
|
|
2468
|
|
|
'meta' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customermeta WHERE customer_id=%d", $donor_id ) ), |
|
|
|
|
2469
|
|
|
|
2470
|
|
|
); |
2471
|
|
|
} |
2472
|
|
|
} |
2473
|
|
|
|
2474
|
|
|
if( ! empty( $donor_data ) ) { |
|
|
|
|
2475
|
|
|
$donor_table_name = Give()->donors->table_name; |
2476
|
|
|
$donor_meta_table_name = Give()->donor_meta->table_name; |
2477
|
|
|
|
2478
|
|
|
Give()->donors->table_name = "{$wpdb->prefix}give_donors"; |
2479
|
|
|
Give()->donor_meta->table_name = "{$wpdb->prefix}give_donormeta"; |
2480
|
|
|
|
2481
|
|
|
foreach ( $donor_data as $donor ) { |
2482
|
|
|
$donor['info'][0] = (array) $donor['info'][0]; |
2483
|
|
|
|
2484
|
|
|
// Prevent duplicate meta id issue. |
2485
|
|
|
if( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_donors WHERE id=%d", $donor['info'][0]['id'] ) ) ){ |
|
|
|
|
2486
|
|
|
continue; |
2487
|
|
|
} |
2488
|
|
|
|
2489
|
|
|
$donor_id = Give()->donors->add( $donor['info'][0] ); |
2490
|
|
|
|
2491
|
|
|
if( ! empty( $donor['meta'] ) ) { |
|
|
|
|
2492
|
|
|
foreach ( $donor['meta'] as $donor_meta ) { |
2493
|
|
|
$donor_meta = (array) $donor_meta; |
2494
|
|
|
|
2495
|
|
|
// Prevent duplicate meta id issue. |
2496
|
|
|
if( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_donormeta WHERE meta_id=%d", $donor_meta['meta_id'] ) ) ){ |
|
|
|
|
2497
|
|
|
unset( $donor_meta['meta_id'] ); |
2498
|
|
|
} |
2499
|
|
|
|
2500
|
|
|
$donor_meta['donor_id'] = $donor_meta['customer_id']; |
2501
|
|
|
unset( $donor_meta['customer_id'] ); |
2502
|
|
|
|
2503
|
|
|
Give()->donor_meta->insert( $donor_meta ); |
2504
|
|
|
} |
2505
|
|
|
} |
2506
|
|
|
|
2507
|
|
|
/** |
2508
|
|
|
* Fix donor name and address |
2509
|
|
|
*/ |
2510
|
|
|
$address = $wpdb->get_var( |
|
|
|
|
2511
|
|
|
$wpdb->prepare( |
2512
|
|
|
" |
2513
|
|
|
SELECT meta_value FROM {$wpdb->usermeta} |
|
|
|
|
2514
|
|
|
WHERE user_id=%s |
2515
|
|
|
AND meta_key=%s |
2516
|
|
|
", |
2517
|
|
|
$donor['info'][0]['user_id'], |
2518
|
|
|
'_give_user_address' |
2519
|
|
|
) |
2520
|
|
|
); |
2521
|
|
|
|
2522
|
|
|
$donor = new Give_Donor( $donor_id ); |
2523
|
|
|
|
2524
|
|
View Code Duplication |
if ( ! empty( $address ) ) { |
|
|
|
|
2525
|
|
|
$address = maybe_unserialize( $address ); |
2526
|
|
|
$donor->add_address( 'personal', $address ); |
2527
|
|
|
$donor->add_address( 'billing[]', $address ); |
2528
|
|
|
} |
2529
|
|
|
|
2530
|
|
|
$donor_name = explode( ' ', $donor->name, 2 ); |
2531
|
|
|
$donor_first_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_first_name' ); |
2532
|
|
|
$donor_last_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_last_name' ); |
2533
|
|
|
|
2534
|
|
|
// If first name meta of donor is not created, then create it. |
2535
|
|
View Code Duplication |
if ( ! $donor_first_name && isset( $donor_name[0] ) ) { |
|
|
|
|
2536
|
|
|
Give()->donor_meta->add_meta( $donor->id, '_give_donor_first_name', $donor_name[0] ); |
2537
|
|
|
} |
2538
|
|
|
|
2539
|
|
|
// If last name meta of donor is not created, then create it. |
2540
|
|
View Code Duplication |
if ( ! $donor_last_name && isset( $donor_name[1] ) ) { |
|
|
|
|
2541
|
|
|
Give()->donor_meta->add_meta( $donor->id, '_give_donor_last_name', $donor_name[1] ); |
2542
|
|
|
} |
2543
|
|
|
|
2544
|
|
|
// If Donor is connected with WP User then update user meta. |
2545
|
|
View Code Duplication |
if ( $donor->user_id ) { |
|
|
|
|
2546
|
|
|
if ( isset( $donor_name[0] ) ) { |
2547
|
|
|
update_user_meta( $donor->user_id, 'first_name', $donor_name[0] ); |
|
|
|
|
2548
|
|
|
} |
2549
|
|
|
if ( isset( $donor_name[1] ) ) { |
2550
|
|
|
update_user_meta( $donor->user_id, 'last_name', $donor_name[1] ); |
|
|
|
|
2551
|
|
|
} |
2552
|
|
|
} |
2553
|
|
|
} |
2554
|
|
|
|
2555
|
|
|
Give()->donors->table_name = $donor_table_name; |
2556
|
|
|
Give()->donor_meta->table_name = $donor_meta_table_name; |
2557
|
|
|
} |
2558
|
|
|
} |
2559
|
|
|
|
2560
|
|
|
Give_Updates::get_instance()->percentage = 100; |
|
|
|
|
2561
|
|
|
give_set_upgrade_complete('v201_add_missing_donors' ); |
|
|
|
|
2562
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.