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