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