Completed
Push — issues/1132 ( ce98cf...c1497a )
by Ravinder
544:59 queued 534:53
created

upgrade-functions.php ➔ give_v20_upgrades_payment_metadata_callback()   B

Complexity

Conditions 8
Paths 18

Size

Total Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 18
nop 0
dl 0
loc 72
rs 7.3664
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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: /includes/install.php @ Appox Line 156
12
 */
13
14
// Exit if accessed directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
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;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
40
41
		case version_compare( $give_version, '1.7', '<' ) :
42
			give_v17_upgrades();
43
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
44
45
		case version_compare( $give_version, '1.8', '<' ) :
46
			give_v18_upgrades();
47
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
48
49
		case version_compare( $give_version, '1.8.7', '<' ) :
50
			give_v187_upgrades();
51
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
52
53
		case version_compare( $give_version, '1.8.8', '<' ) :
54
			give_v188_upgrades();
55
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
56
57
		case version_compare( $give_version, '1.8.9', '<' ) :
58
			give_v189_upgrades();
59
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
60
61
		case version_compare( $give_version, '1.8.12', '<' ) :
62
			give_v1812_upgrades();
63
			$did_upgrade = true;
0 ignored issues
show
Unused Code introduced by
$did_upgrade is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
64
65
		case version_compare( $give_version, '2.0', '<' ) :
66
			give_v20_upgrades();
67
			$did_upgrade = true;
68
	}
69
70
	if ( $did_upgrade ) {
71
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
72
	}
73
}
74
75
add_action( 'admin_init', 'give_do_automatic_upgrades' );
76
add_action( 'give_upgrades', 'give_do_automatic_upgrades' );
77
78
/**
79
 * Display Upgrade Notices
80
 *
81
 * @since 1.0
82
 * @since 1.8.12 Update new update process code.
83
 *
84
 * @param Give_Updates $give_updates
85
 *
86
 * @return void
87
 */
88
function give_show_upgrade_notices( $give_updates ) {
89
	// v1.3.2 Upgrades
90
	$give_updates->register(
91
		array(
92
			'id'       => 'upgrade_give_payment_customer_id',
93
			'version'  => '1.3.2',
94
			'callback' => 'give_v132_upgrade_give_payment_customer_id',
95
		)
96
	);
97
98
	// v1.3.4 Upgrades ensure the user has gone through 1.3.4.
99
	$give_updates->register(
100
		array(
101
			'id'       => 'upgrade_give_offline_status',
102
			'depend'   => 'upgrade_give_payment_customer_id',
103
			'version'  => '1.3.4',
104
			'callback' => 'give_v134_upgrade_give_offline_status',
105
		)
106
	);
107
108
	// v1.8 form metadata upgrades.
109
	$give_updates->register(
110
		array(
111
			'id'       => 'v18_upgrades_form_metadata',
112
			'version'  => '1.8',
113
			'callback' => 'give_v18_upgrades_form_metadata',
114
		)
115
	);
116
117
	// v1.8.9 Upgrades
118
	$give_updates->register(
119
		array(
120
			'id'       => 'v189_upgrades_levels_post_meta',
121
			'version'  => '1.8.9',
122
			'callback' => 'give_v189_upgrades_levels_post_meta_callback',
123
		)
124
	);
125
126
	// v1.8.12 Upgrades
127
	$give_updates->register(
128
		array(
129
			'id'       => 'v1812_update_amount_values',
130
			'version'  => '1.8.12',
131
			'callback' => 'give_v1812_update_amount_values_callback',
132
		)
133
	);
134
135
	// v1.8.12 Upgrades
136
	$give_updates->register(
137
		array(
138
			'id'       => 'v1812_update_donor_purchase_values',
139
			'version'  => '1.8.12',
140
			'callback' => 'give_v1812_update_donor_purchase_value_callback',
141
		)
142
	);
143
144
	// v2.0.0 Upgrades
145
	$give_updates->register(
146
		array(
147
			'id'       => 'v20_upgrades_form_metadata',
148
			'version'  => '2.0.0',
149
			'callback' => 'give_v20_upgrades_form_metadata_callback',
150
		)
151
	);
152
153
	// v2.0.0 Upgrades
154
	$give_updates->register(
155
		array(
156
			'id'       => 'v20_upgrades_payment_metadata',
157
			'version'  => '2.0.0',
158
			'callback' => 'give_v20_upgrades_payment_metadata_callback',
159
		)
160
	);
161
162
	// v2.0.0 Upgrades
163
	$give_updates->register(
164
		array(
165
			'id'       => 'v20_logs_upgrades',
166
			'version'  => '2.0.0',
167
			'callback' => 'give_v20_logs_upgrades_callback',
168
169
		)
170
	);
171
172
	// v2.0.0 Upgrades
173
	$give_updates->register(
174
		array(
175
			'id'       => 'v20_move_metadata_into_new_table',
176
			'version'  => '2.0.0',
177
			'callback' => 'give_v20_move_metadata_into_new_table_callback',
178
			'depend'   => array( 'v20_upgrades_payment_metadata', 'v20_upgrades_form_metadata' )
179
		)
180
	);
181
182
	// v2.0.0 Upgrades
183
	$give_updates->register(
184
		array(
185
			'id'       => 'v20_rename_donor_tables',
186
			'version'  => '2.0.0',
187
			'callback' => 'give_v20_rename_donor_tables_callback',
188
			'depend'   => array(
189
				'v20_move_metadata_into_new_table',
190
				'v20_logs_upgrades',
191
				'v20_upgrades_form_metadata',
192
				'v20_upgrades_payment_metadata'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
193
			),
194
		)
195
	);
196
}
197
198
add_action( 'give_register_updates', 'give_show_upgrade_notices' );
199
200
/**
201
 * Triggers all upgrade functions
202
 *
203
 * This function is usually triggered via AJAX
204
 *
205
 * @since 1.0
206
 * @return void
207
 */
208
function give_trigger_upgrades() {
209
210 View Code Duplication
	if ( ! current_user_can( 'manage_give_settings' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
211
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
212
			'response' => 403,
213
		) );
214
	}
215
216
	$give_version = get_option( 'give_version' );
217
218
	if ( ! $give_version ) {
219
		// 1.0 is the first version to use this option so we must add it.
220
		$give_version = '1.0';
221
		add_option( 'give_version', $give_version );
222
	}
223
224
	update_option( 'give_version', GIVE_VERSION );
225
	delete_option( 'give_doing_upgrade' );
226
227
	if ( DOING_AJAX ) {
228
		die( 'complete' );
229
	} // End if().
230
}
231
232
add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' );
233
234
235
/**
236
 * Upgrades the
237
 *
238
 * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id`
239
 *
240
 * @since      1.3.2
241
 */
242
function give_v132_upgrade_give_payment_customer_id() {
243
	global $wpdb;
244
245
	/* @var Give_Updates $give_updates */
246
	$give_updates = Give_Updates::get_instance();
247
248 View Code Duplication
	if ( ! current_user_can( 'manage_give_settings' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
249
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
250
			'response' => 403,
251
		) );
252
	}
253
254
	ignore_user_abort( true );
255
256
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
257
		@set_time_limit( 0 );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Coding Style introduced by
Silencing errors is discouraged
Loading history...
258
	}
259
260
	// UPDATE DB METAKEYS.
261
	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
262
	$query = $wpdb->query( $sql );
0 ignored issues
show
Unused Code introduced by
$query is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
263
264
	$give_updates->percentage = 100;
0 ignored issues
show
Documentation Bug introduced by
It seems like 100 of type integer is incompatible with the declared type array of property $percentage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
265
	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
266
}
267
268
269
/**
270
 * Upgrades the Offline Status
271
 *
272
 * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned
273
 *
274
 * @since      1.3.4
275
 */
276
function give_v134_upgrade_give_offline_status() {
277
	global $wpdb;
278
279
	/* @var Give_Updates $give_updates */
280
	$give_updates = Give_Updates::get_instance();
281
282
	// Get abandoned offline payments.
283
	$select = "SELECT ID FROM $wpdb->posts p ";
284
	$join   = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
285
	$where  = "WHERE p.post_type = 'give_payment' ";
286
	$where  .= "AND ( p.post_status = 'abandoned' )";
287
	$where  .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
288
289
	$sql            = $select . $join . $where;
290
	$found_payments = $wpdb->get_col( $sql );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
291
292
	foreach ( $found_payments as $payment ) {
293
294
		// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves.
295
		$modified_time = get_post_modified_time( 'U', false, $payment );
296
297
		// 1450124863 =  12/10/2015 20:42:25.
298
		if ( $modified_time >= 1450124863 ) {
299
300
			give_update_payment_status( $payment, 'pending' );
301
302
		}
303
	}
304
305
	$give_updates->percentage = 100;
0 ignored issues
show
Documentation Bug introduced by
It seems like 100 of type integer is incompatible with the declared type array of property $percentage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
306
	give_set_upgrade_complete( 'upgrade_give_offline_status' );
307
}
308
309
310
/**
311
 * Cleanup User Roles
312
 *
313
 * This upgrade routine removes unused roles and roles with typos
314
 *
315
 * @since      1.5.2
316
 */
317
function give_v152_cleanup_users() {
318
319
	$give_version = get_option( 'give_version' );
320
321
	if ( ! $give_version ) {
322
		// 1.0 is the first version to use this option so we must add it.
323
		$give_version = '1.0';
324
	}
325
326
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
327
328
	// v1.5.2 Upgrades
329
	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
330
331
		// Delete all caps with "ss".
332
		// Also delete all unused "campaign" roles.
333
		$delete_caps = array(
334
			'delete_give_formss',
335
			'delete_others_give_formss',
336
			'delete_private_give_formss',
337
			'delete_published_give_formss',
338
			'read_private_forms',
339
			'edit_give_formss',
340
			'edit_others_give_formss',
341
			'edit_private_give_formss',
342
			'edit_published_give_formss',
343
			'publish_give_formss',
344
			'read_private_give_formss',
345
			'assign_give_campaigns_terms',
346
			'delete_give_campaigns',
347
			'delete_give_campaigns_terms',
348
			'delete_give_campaignss',
349
			'delete_others_give_campaignss',
350
			'delete_private_give_campaignss',
351
			'delete_published_give_campaignss',
352
			'edit_give_campaigns',
353
			'edit_give_campaigns_terms',
354
			'edit_give_campaignss',
355
			'edit_others_give_campaignss',
356
			'edit_private_give_campaignss',
357
			'edit_published_give_campaignss',
358
			'manage_give_campaigns_terms',
359
			'publish_give_campaignss',
360
			'read_give_campaigns',
361
			'read_private_give_campaignss',
362
			'view_give_campaigns_stats',
363
			'delete_give_paymentss',
364
			'delete_others_give_paymentss',
365
			'delete_private_give_paymentss',
366
			'delete_published_give_paymentss',
367
			'edit_give_paymentss',
368
			'edit_others_give_paymentss',
369
			'edit_private_give_paymentss',
370
			'edit_published_give_paymentss',
371
			'publish_give_paymentss',
372
			'read_private_give_paymentss',
373
		);
374
375
		global $wp_roles;
376
		foreach ( $delete_caps as $cap ) {
377
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
378
				$wp_roles->remove_cap( $role, $cap );
379
			}
380
		}
381
382
		// Create Give plugin roles.
383
		$roles = new Give_Roles();
384
		$roles->add_roles();
385
		$roles->add_caps();
386
387
		// The Update Ran.
388
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
389
		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
390
		delete_option( 'give_doing_upgrade' );
391
392
	}// End if().
393
394
}
395
396
add_action( 'admin_init', 'give_v152_cleanup_users' );
397
398
/**
399
 * 1.6 Upgrade routine to create the customer meta table.
400
 *
401
 * @since  1.6
402
 * @return void
403
 */
404
function give_v16_upgrades() {
405
	// Create the donor databases.
406
	$donors_db = new Give_DB_Donors();
407
	$donors_db->create_table();
408
	$donor_meta = new Give_DB_Donor_Meta();
409
	$donor_meta->create_table();
410
}
411
412
/**
413
 * 1.7 Upgrades.
414
 *
415
 * a. Update license api data for plugin addons.
416
 * b. Cleanup user roles.
417
 *
418
 * @since  1.7
419
 * @return void
420
 */
421
function give_v17_upgrades() {
422
	// Upgrade license data.
423
	give_v17_upgrade_addon_license_data();
424
	give_v17_cleanup_roles();
425
}
426
427
/**
428
 * Upgrade license data
429
 *
430
 * @since 1.7
431
 */
432
function give_v17_upgrade_addon_license_data() {
433
	$give_options = give_get_settings();
434
435
	$api_url = 'https://givewp.com/give-sl-api/';
436
437
	// Get addons license key.
438
	$addons = array();
439
	foreach ( $give_options as $key => $value ) {
440
		if ( false !== strpos( $key, '_license_key' ) ) {
441
			$addons[ $key ] = $value;
442
		}
443
	}
444
445
	// Bailout: We do not have any addon license data to upgrade.
446
	if ( empty( $addons ) ) {
447
		return false;
448
	}
449
450
	foreach ( $addons as $key => $addon_license ) {
451
452
		// Get addon shortname.
453
		$shortname = str_replace( '_license_key', '', $key );
454
455
		// Addon license option name.
456
		$addon_license_option_name = $shortname . '_license_active';
457
458
		// bailout if license is empty.
459
		if ( empty( $addon_license ) ) {
460
			delete_option( $addon_license_option_name );
461
			continue;
462
		}
463
464
		// Get addon name.
465
		$addon_name       = array();
466
		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
467
		foreach ( $addon_name_parts as $name_part ) {
468
469
			// Fix addon name
470
			switch ( $name_part ) {
471
				case 'authorizenet' :
472
					$name_part = 'authorize.net';
473
					break;
474
			}
475
476
			$addon_name[] = ucfirst( $name_part );
477
		}
478
479
		$addon_name = implode( ' ', $addon_name );
480
481
		// Data to send to the API
482
		$api_params = array(
483
			'edd_action' => 'activate_license', // never change from "edd_" to "give_"!
484
			'license'    => $addon_license,
485
			'item_name'  => urlencode( $addon_name ),
486
			'url'        => home_url(),
487
		);
488
489
		// Call the API.
490
		$response = wp_remote_post(
491
			$api_url,
492
			array(
493
				'timeout'   => 15,
494
				'sslverify' => false,
495
				'body'      => $api_params,
496
			)
497
		);
498
499
		// Make sure there are no errors.
500
		if ( is_wp_error( $response ) ) {
501
			delete_option( $addon_license_option_name );
502
			continue;
503
		}
504
505
		// Tell WordPress to look for updates.
506
		set_site_transient( 'update_plugins', null );
507
508
		// Decode license data.
509
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
510
		update_option( $addon_license_option_name, $license_data );
511
	}// End foreach().
512
}
513
514
515
/**
516
 * Cleanup User Roles.
517
 *
518
 * This upgrade routine removes unused roles and roles with typos.
519
 *
520
 * @since      1.7
521
 */
522
function give_v17_cleanup_roles() {
523
524
	// Delete all caps with "_give_forms_" and "_give_payments_"
525
	// These roles have no usage; the proper is singular.
526
	$delete_caps = array(
527
		'view_give_forms_stats',
528
		'delete_give_forms_terms',
529
		'assign_give_forms_terms',
530
		'edit_give_forms_terms',
531
		'manage_give_forms_terms',
532
		'view_give_payments_stats',
533
		'manage_give_payments_terms',
534
		'edit_give_payments_terms',
535
		'assign_give_payments_terms',
536
		'delete_give_payments_terms',
537
	);
538
539
	global $wp_roles;
540
	foreach ( $delete_caps as $cap ) {
541
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
542
			$wp_roles->remove_cap( $role, $cap );
543
		}
544
	}
545
546
	// Set roles again.
547
	$roles = new Give_Roles();
548
	$roles->add_roles();
549
	$roles->add_caps();
550
551
}
552
553
/**
554
 * 1.8 Upgrades.
555
 *
556
 * a. Upgrade checkbox settings to radio button settings.
557
 * a. Update form meta for new metabox settings.
558
 *
559
 * @since  1.8
560
 * @return void
561
 */
562
function give_v18_upgrades() {
563
	// Upgrade checkbox settings to radio button settings.
564
	give_v18_upgrades_core_setting();
565
}
566
567
/**
568
 * Upgrade core settings.
569
 *
570
 * @since  1.8
571
 * @return void
572
 */
573
function give_v18_upgrades_core_setting() {
574
	// Core settings which changes from checkbox to radio.
575
	$core_setting_names = array_merge(
576
		array_keys( give_v18_renamed_core_settings() ),
577
		array(
578
			'uninstall_on_delete',
579
			'scripts_footer',
580
			'test_mode',
581
			'email_access',
582
			'terms',
583
			'give_offline_donation_enable_billing_fields',
584
		)
585
	);
586
587
	// Bailout: If not any setting define.
588
	if ( $give_settings = get_option( 'give_settings' ) ) {
589
590
		$setting_changed = false;
591
592
		// Loop: check each setting field.
593
		foreach ( $core_setting_names as $setting_name ) {
594
			// New setting name.
595
			$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name );
596
597
			// Continue: If setting already set.
598
			if (
599
				array_key_exists( $new_setting_name, $give_settings )
600
				&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) )
601
			) {
602
				continue;
603
			}
604
605
			// Set checkbox value to radio value.
606
			$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' );
607
608
			// @see https://github.com/WordImpress/Give/issues/1063
609
			if ( false !== strpos( $setting_name, 'disable_' ) ) {
610
611
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' );
612
			} elseif ( false !== strpos( $setting_name, 'enable_' ) ) {
613
614
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' );
615
			}
616
617
			// Tell bot to update core setting to db.
618
			if ( ! $setting_changed ) {
619
				$setting_changed = true;
620
			}
621
		}
622
623
		// Update setting only if they changed.
624
		if ( $setting_changed ) {
625
			update_option( 'give_settings', $give_settings );
626
		}
627
	}// End if().
628
629
	give_set_upgrade_complete( 'v18_upgrades_core_setting' );
630
}
631
632
/**
633
 * Upgrade form metadata for new metabox settings.
634
 *
635
 * @since  1.8
636
 * @return void
637
 */
638
function give_v18_upgrades_form_metadata() {
639
	/* @var Give_Updates $give_updates */
640
	$give_updates = Give_Updates::get_instance();
641
642
	// form query
643
	$forms = new WP_Query( array(
644
			'paged'          => $give_updates->step,
645
			'status'         => 'any',
646
			'order'          => 'ASC',
647
			'post_type'      => 'give_forms',
648
			'posts_per_page' => 20,
649
		)
650
	);
651
652
	if ( $forms->have_posts() ) {
653
		$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) );
654
655
		while ( $forms->have_posts() ) {
656
			$forms->the_post();
657
658
			// Form content.
659
			// Note in version 1.8 display content setting split into display content and content placement setting.
660
			// You can delete _give_content_option in future
661
			$show_content = give_get_meta( get_the_ID(), '_give_content_option', true );
662
			if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) {
663
				$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' );
664
				give_update_meta( get_the_ID(), '_give_display_content', $field_value );
665
666
				$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' );
667
				give_update_meta( get_the_ID(), '_give_content_placement', $field_value );
668
			}
669
670
			// "Disable" Guest Donation. Checkbox
671
			// See: https://github.com/WordImpress/Give/issues/1470
672
			$guest_donation        = give_get_meta( get_the_ID(), '_give_logged_in_only', true );
673
			$guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' );
674
			give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval );
675
676
			// Offline Donations
677
			// See: https://github.com/WordImpress/Give/issues/1579
678
			$offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true );
679
			if ( 'no' === $offline_donation ) {
680
				$offline_donation_newval = 'global';
681
			} elseif ( 'yes' === $offline_donation ) {
682
				$offline_donation_newval = 'enabled';
683
			} else {
684
				$offline_donation_newval = 'disabled';
685
			}
686
			give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval );
687
688
			// Convert yes/no setting field to enabled/disabled.
689
			$form_radio_settings = array(
690
				// Custom Amount.
691
				'_give_custom_amount',
692
693
				// Donation Gaol.
694
				'_give_goal_option',
695
696
				// Close Form.
697
				'_give_close_form_when_goal_achieved',
698
699
				// Term & conditions.
700
				'_give_terms_option',
701
702
				// Billing fields.
703
				'_give_offline_donation_enable_billing_fields_single',
704
			);
705
706
			foreach ( $form_radio_settings as $meta_key ) {
707
				// Get value.
708
				$field_value = give_get_meta( get_the_ID(), $meta_key, true );
709
710
				// Convert meta value only if it is in yes/no/none.
711
				if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) {
712
713
					$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' );
714
					give_update_meta( get_the_ID(), $meta_key, $field_value );
715
				}
716
			}
717
		}// End while().
718
719
		wp_reset_postdata();
720
721
	} else {
722
		// No more forms found, finish up.
723
		give_set_upgrade_complete( 'v18_upgrades_form_metadata' );
724
	}
725
}
726
727
728
/**
729
 * Get list of core setting renamed in version 1.8.
730
 *
731
 * @since  1.8
732
 * @return array
733
 */
734
function give_v18_renamed_core_settings() {
735
	return array(
736
		'disable_paypal_verification' => 'paypal_verification',
737
		'disable_css'                 => 'css',
738
		'disable_welcome'             => 'welcome',
739
		'disable_forms_singular'      => 'forms_singular',
740
		'disable_forms_archives'      => 'forms_archives',
741
		'disable_forms_excerpt'       => 'forms_excerpt',
742
		'disable_form_featured_img'   => 'form_featured_img',
743
		'disable_form_sidebar'        => 'form_sidebar',
744
		'disable_admin_notices'       => 'admin_notices',
745
		'disable_the_content_filter'  => 'the_content_filter',
746
		'enable_floatlabels'          => 'floatlabels',
747
		'enable_categories'           => 'categories',
748
		'enable_tags'                 => 'tags',
749
	);
750
}
751
752
753
/**
754
 * Upgrade core settings.
755
 *
756
 * @since  1.8.7
757
 * @return void
758
 */
759
function give_v187_upgrades() {
760
	global $wpdb;
761
762
	/**
763
	 * Upgrade 1: Remove stat and cache transients.
764
	 */
765
	$cached_options = $wpdb->get_col(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
766
		$wpdb->prepare(
767
			"SELECT * FROM {$wpdb->options} where (option_name LIKE '%%%s%%' OR option_name LIKE '%%%s%%')",
768
			array(
769
				'_transient_give_stats_',
770
				'give_cache',
771
				'_transient_give_add_ons_feed',
772
				'_transient__give_ajax_works',
773
				'_transient_give_total_api_keys',
774
				'_transient_give_i18n_give_promo_hide',
775
				'_transient_give_contributors',
776
				'_transient_give_estimated_monthly_stats',
777
				'_transient_give_earnings_total',
778
				'_transient_give_i18n_give_',
779
				'_transient__give_installed',
780
				'_transient__give_activation_redirect',
781
				'_transient__give_hide_license_notices_shortly_',
782
				'give_income_total',
783
			)
784
		),
785
		1
786
	);
787
788
	// User related transients.
789
	$user_apikey_options = $wpdb->get_results(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
790
		$wpdb->prepare(
791
			"SELECT user_id, meta_key
792
			FROM $wpdb->usermeta
0 ignored issues
show
introduced by
Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.
Loading history...
793
			WHERE meta_value=%s",
794
			'give_user_public_key'
795
		),
796
		ARRAY_A
797
	);
798
799
	if ( ! empty( $user_apikey_options ) ) {
800
		foreach ( $user_apikey_options as $user ) {
801
			$cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] );
802
			$cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] );
803
			$cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] );
804
		}
805
	}
806
807
	if ( ! empty( $cached_options ) ) {
808
		foreach ( $cached_options as $option ) {
809 View Code Duplication
			switch ( true ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
810
				case ( false !== strpos( $option, 'transient' ) ):
811
					$option = str_replace( '_transient_', '', $option );
812
					delete_transient( $option );
813
					break;
814
815
				default:
816
					delete_option( $option );
817
			}
818
		}
819
	}
820
}
821
822
/**
823
 * Update Capabilities for Give_Worker User Role.
824
 *
825
 * This upgrade routine will update access rights for Give_Worker User Role.
826
 *
827
 * @since      1.8.8
828
 */
829
function give_v188_upgrades() {
830
831
	global $wp_roles;
832
833
	// Get the role object.
834
	$give_worker = get_role( 'give_worker' );
835
836
	// A list of capabilities to add for give workers.
837
	$caps_to_add = array(
838
		'edit_posts',
839
		'edit_pages',
840
	);
841
842
	foreach ( $caps_to_add as $cap ) {
843
		// Add the capability.
844
		$give_worker->add_cap( $cap );
845
	}
846
847
}
848
849
/**
850
 * Update Post meta for minimum and maximum amount for multi level donation forms
851
 *
852
 * This upgrade routine adds post meta for give_forms CPT for multi level donation form.
853
 *
854
 * @since      1.8.9
855
 */
856
function give_v189_upgrades_levels_post_meta_callback() {
857
	/* @var Give_Updates $give_updates */
858
	$give_updates = Give_Updates::get_instance();
859
860
	// form query
861
	$donation_forms = new WP_Query( array(
862
			'paged'          => $give_updates->step,
863
			'status'         => 'any',
864
			'order'          => 'ASC',
865
			'post_type'      => 'give_forms',
866
			'posts_per_page' => 20,
867
		)
868
	);
869
870
	if ( $donation_forms->have_posts() ) {
871
		$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) );
872
873
		while ( $donation_forms->have_posts() ) {
874
			$donation_forms->the_post();
875
			$form_id = get_the_ID();
876
877
			// Remove formatting from _give_set_price
878
			update_post_meta(
879
				$form_id,
880
				'_give_set_price',
881
				give_sanitize_amount( get_post_meta( $form_id, '_give_set_price', true ) )
882
			);
883
884
			// Remove formatting from _give_custom_amount_minimum
885
			update_post_meta(
886
				$form_id,
887
				'_give_custom_amount_minimum',
888
				give_sanitize_amount( get_post_meta( $form_id, '_give_custom_amount_minimum', true ) )
889
			);
890
891
			// Bailout.
892
			if ( 'set' === get_post_meta( $form_id, '_give_price_option', true ) ) {
893
				continue;
894
			}
895
896
			$donation_levels = get_post_meta( $form_id, '_give_donation_levels', true );
897
898
			if ( ! empty( $donation_levels ) ) {
899
900
				foreach ( $donation_levels as $index => $donation_level ) {
901
					if ( isset( $donation_level['_give_amount'] ) ) {
902
						$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount( $donation_level['_give_amount'] );
903
					}
904
				}
905
906
				update_post_meta( $form_id, '_give_donation_levels', $donation_levels );
907
908
				$donation_levels_amounts = wp_list_pluck( $donation_levels, '_give_amount' );
909
910
				$min_amount = min( $donation_levels_amounts );
911
				$max_amount = max( $donation_levels_amounts );
912
913
				// Set Minimum and Maximum amount for Multi Level Donation Forms
914
				give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount( $min_amount ) : 0 );
915
				give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount( $max_amount ) : 0 );
916
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
917
918
		}
919
920
		/* Restore original Post Data */
921
		wp_reset_postdata();
922
	} else {
923
		// The Update Ran.
924
		give_set_upgrade_complete( 'v189_upgrades_levels_post_meta' );
925
	}
926
927
}
928
929
930
/**
931
 * Give version 1.8.9 upgrades
932
 *
933
 * @since      1.8.9
934
 */
935
function give_v189_upgrades() {
936
	/**
937
	 * 1. Remove user license related notice show blocked ( Give_Notice will handle )
938
	 */
939
	global $wpdb;
940
941
	// Delete permanent notice blocker.
942
	$wpdb->query(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
943
		$wpdb->prepare(
944
			"
945
					DELETE FROM $wpdb->usermeta
0 ignored issues
show
introduced by
Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.
Loading history...
946
					WHERE meta_key
947
					LIKE '%%%s%%'
948
					",
949
			'_give_hide_license_notices_permanently'
950
		)
951
	);
952
953
	// Delete short notice blocker.
954
	$wpdb->query(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
955
		$wpdb->prepare(
956
			"
957
					DELETE FROM $wpdb->options
958
					WHERE option_name
959
					LIKE '%%%s%%'
960
					",
961
			'__give_hide_license_notices_shortly_'
962
		)
963
	);
964
}
965
966
/**
967
 * 2.0 Upgrades.
968
 *
969
 * @since  2.0
970
 * @return void
971
 */
972
function give_v20_upgrades() {
973
	// Upgrade email settings.
974
	give_v20_upgrades_email_setting();
975
}
976
977
/**
978
 * Move old email api settings to new email setting api for following emails:
979
 *    1. new offline donation         [This was hard coded]
980
 *    2. offline donation instruction
981
 *    3. new donation
982
 *    4. donation receipt
983
 *
984
 * @since 2.0
985
 */
986
function give_v20_upgrades_email_setting() {
987
	$all_setting = give_get_settings();
988
989
	// Bailout on fresh install.
990
	if ( empty( $all_setting ) ) {
991
		return;
992
	}
993
994
	$settings = array(
995
		'offline_donation_subject'      => 'offline-donation-instruction_email_subject',
996
		'global_offline_donation_email' => 'offline-donation-instruction_email_message',
997
		'donation_subject'              => 'donation-receipt_email_subject',
998
		'donation_receipt'              => 'donation-receipt_email_message',
999
		'donation_notification_subject' => 'new-donation_email_subject',
1000
		'donation_notification'         => 'new-donation_email_message',
1001
		'admin_notice_emails'           => array(
1002
			'new-donation_recipient',
1003
			'new-offline-donation_recipient',
1004
			'new-donor-register_recipient',
1005
		),
1006
		'admin_notices'                 => 'new-donation_notification',
1007
	);
1008
1009
	foreach ( $settings as $old_setting => $new_setting ) {
1010
		// Do not update already modified
1011
		if ( ! is_array( $new_setting ) ) {
1012
			if ( array_key_exists( $new_setting, $all_setting ) || ! array_key_exists( $old_setting, $all_setting ) ) {
1013
				continue;
1014
			}
1015
		}
1016
1017
		switch ( $old_setting ) {
1018
			case 'admin_notices':
1019
				$notification_status = give_get_option( $old_setting, 'disabled' );
1020
1021
				give_update_option( $new_setting, $notification_status );
0 ignored issues
show
Bug introduced by
It seems like $new_setting defined by $new_setting on line 1009 can also be of type array; however, give_update_option() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1022
				give_delete_option( $old_setting );
1023
				break;
1024
1025
			// @todo: Delete this option later ( version > 2.0 ) because we need this for backward compatibility give_get_admin_notice_emails.
1026
			case 'admin_notice_emails':
1027
				$recipients = give_get_admin_notice_emails();
1028
1029
				foreach ( $new_setting as $setting ) {
0 ignored issues
show
Bug introduced by
The expression $new_setting of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
1030
					// bailout if setting already exist.
1031
					if ( array_key_exists( $setting, $all_setting ) ) {
1032
						continue;
1033
					}
1034
1035
					give_update_option( $setting, $recipients );
1036
				}
1037
				break;
1038
1039
			default:
1040
				give_update_option( $new_setting, give_get_option( $old_setting ) );
0 ignored issues
show
Bug introduced by
It seems like $new_setting defined by $new_setting on line 1009 can also be of type array; however, give_update_option() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1041
				give_delete_option( $old_setting );
1042
		}
1043
	}
1044
}
1045
1046
1047
/**
1048
 * Give version 1.8.9 upgrades
1049
 *
1050
 * @since      1.8.9
1051
 */
1052
function give_v1812_upgrades() {
1053
	/**
1054
	 * Validate number format settings.
1055
	 */
1056
	$give_settings        = give_get_settings();
1057
	$give_setting_updated = false;
1058
1059
	if ( $give_settings['thousands_separator'] === $give_settings['decimal_separator'] ) {
1060
		$give_settings['number_decimals']   = 0;
1061
		$give_settings['decimal_separator'] = '';
1062
		$give_setting_updated               = true;
1063
1064
	} elseif ( empty( $give_settings['decimal_separator'] ) ) {
1065
		$give_settings['number_decimals'] = 0;
1066
		$give_setting_updated             = true;
1067
1068
	} elseif ( 6 < absint( $give_settings['number_decimals'] ) ) {
1069
		$give_settings['number_decimals'] = 5;
1070
		$give_setting_updated             = true;
1071
	}
1072
1073
	if ( $give_setting_updated ) {
1074
		update_option( 'give_settings', $give_settings );
1075
	}
1076
}
1077
1078
1079
/**
1080
 * Give version 1.8.12 update
1081
 *
1082
 * Standardized amount values to six decimal
1083
 *
1084
 * @see        https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602
1085
 *
1086
 * @since      1.8.12
1087
 */
1088
function give_v1812_update_amount_values_callback() {
1089
	/* @var Give_Updates $give_updates */
1090
	$give_updates = Give_Updates::get_instance();
1091
1092
	// form query
1093
	$donation_forms = new WP_Query( array(
1094
			'paged'          => $give_updates->step,
1095
			'status'         => 'any',
1096
			'order'          => 'ASC',
1097
			'post_type'      => array( 'give_forms', 'give_payment' ),
1098
			'posts_per_page' => 20,
1099
		)
1100
	);
1101
	if ( $donation_forms->have_posts() ) {
1102
		$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) );
1103
1104
		while ( $donation_forms->have_posts() ) {
1105
			$donation_forms->the_post();
1106
			global $post;
1107
1108
			$meta = get_post_meta( $post->ID );
1109
1110
			switch ( $post->post_type ) {
1111
				case 'give_forms':
1112
					// _give_set_price
1113
					if ( ! empty( $meta['_give_set_price'][0] ) ) {
1114
						update_post_meta( $post->ID, '_give_set_price', give_sanitize_amount_for_db( $meta['_give_set_price'][0] ) );
1115
					}
1116
1117
					// _give_custom_amount_minimum
1118
					if ( ! empty( $meta['_give_custom_amount_minimum'][0] ) ) {
1119
						update_post_meta( $post->ID, '_give_custom_amount_minimum', give_sanitize_amount_for_db( $meta['_give_custom_amount_minimum'][0] ) );
1120
					}
1121
1122
					// _give_levels_minimum_amount
1123
					if ( ! empty( $meta['_give_levels_minimum_amount'][0] ) ) {
1124
						update_post_meta( $post->ID, '_give_levels_minimum_amount', give_sanitize_amount_for_db( $meta['_give_levels_minimum_amount'][0] ) );
1125
					}
1126
1127
					// _give_levels_maximum_amount
1128
					if ( ! empty( $meta['_give_levels_maximum_amount'][0] ) ) {
1129
						update_post_meta( $post->ID, '_give_levels_maximum_amount', give_sanitize_amount_for_db( $meta['_give_levels_maximum_amount'][0] ) );
1130
					}
1131
1132
					// _give_set_goal
1133
					if ( ! empty( $meta['_give_set_goal'][0] ) ) {
1134
						update_post_meta( $post->ID, '_give_set_goal', give_sanitize_amount_for_db( $meta['_give_set_goal'][0] ) );
1135
					}
1136
1137
					// _give_form_earnings
1138
					if ( ! empty( $meta['_give_form_earnings'][0] ) ) {
1139
						update_post_meta( $post->ID, '_give_form_earnings', give_sanitize_amount_for_db( $meta['_give_form_earnings'][0] ) );
1140
					}
1141
1142
					// _give_custom_amount_minimum
1143
					if ( ! empty( $meta['_give_donation_levels'][0] ) ) {
1144
						$donation_levels = unserialize( $meta['_give_donation_levels'][0] );
1145
1146
						foreach ( $donation_levels as $index => $level ) {
1147
							if ( empty( $level['_give_amount'] ) ) {
1148
								continue;
1149
							}
1150
1151
							$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount_for_db( $level['_give_amount'] );
1152
						}
1153
1154
						$meta['_give_donation_levels'] = $donation_levels;
1155
						update_post_meta( $post->ID, '_give_donation_levels', $meta['_give_donation_levels'] );
1156
					}
1157
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1158
1159
					break;
1160
1161
				case 'give_payment':
1162
					// _give_payment_total
1163
					if ( ! empty( $meta['_give_payment_total'][0] ) ) {
1164
						update_post_meta( $post->ID, '_give_payment_total', give_sanitize_amount_for_db( $meta['_give_payment_total'][0] ) );
1165
					}
1166
1167
					break;
1168
			}
1169
		}
1170
1171
		/* Restore original Post Data */
1172
		wp_reset_postdata();
1173
	} else {
1174
		// The Update Ran.
1175
		give_set_upgrade_complete( 'v1812_update_amount_values' );
1176
	}
1177
}
1178
1179
1180
/**
1181
 * Give version 1.8.12 update
1182
 *
1183
 * Standardized amount values to six decimal for donor
1184
 *
1185
 * @see        https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602
1186
 *
1187
 * @since      1.8.12
1188
 */
1189
function give_v1812_update_donor_purchase_value_callback() {
1190
	/* @var Give_Updates $give_updates */
1191
	$give_updates = Give_Updates::get_instance();
1192
	$offset       = 1 === $give_updates->step ? 0 : $give_updates->step * 20;
1193
1194
	// form query
1195
	$donors = Give()->donors->get_donors( array(
1196
			'number' => 20,
1197
			'offset' => $offset,
1198
		)
1199
	);
1200
1201
	if ( ! empty( $donors ) ) {
1202
		$give_updates->set_percentage( Give()->donors->count(), $offset );
1203
1204
		/* @var Object $donor */
1205
		foreach ( $donors as $donor ) {
1206
			Give()->donors->update( $donor->id, array( 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ) );
1207
		}
1208
	} else {
1209
		// The Update Ran.
1210
		give_set_upgrade_complete( 'v1812_update_donor_purchase_values' );
1211
	}
1212
}
1213
1214
/**
1215
 * Upgrade form metadata for new metabox settings.
1216
 *
1217
 * @since  2.0
1218
 * @return void
1219
 */
1220
function give_v20_upgrades_form_metadata_callback() {
1221
	$give_updates = Give_Updates::get_instance();
1222
1223
	// form query
1224
	$forms = new WP_Query( array(
1225
			'paged'          => $give_updates->step,
1226
			'status'         => 'any',
1227
			'order'          => 'ASC',
1228
			'post_type'      => 'give_forms',
1229
			'posts_per_page' => 20,
1230
		)
1231
	);
1232
1233
	if ( $forms->have_posts() ) {
1234
		$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) );
1235
1236
		while ( $forms->have_posts() ) {
1237
			$forms->the_post();
1238
			global $post;
1239
1240
			// Update offline instruction email notification status.
1241
			$offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true );
1242
			$offline_instruction_notification_status = give_is_setting_enabled( $offline_instruction_notification_status, array( 'enabled', 'global' ) )
0 ignored issues
show
Documentation introduced by
array('enabled', 'global') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1243
				? $offline_instruction_notification_status
1244
				: 'global';
1245
			update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status );
1246
1247
			// Update offline instruction email message.
1248
			update_post_meta(
1249
				get_the_ID(),
1250
				'_give_offline-donation-instruction_email_message',
1251
				get_post_meta(
1252
					get_the_ID(),
1253
					// @todo: Delete this option later ( version > 2.0 ).
1254
					'_give_offline_donation_email',
1255
					true
1256
				)
1257
			);
1258
1259
			// Update offline instruction email subject.
1260
			update_post_meta(
1261
				get_the_ID(),
1262
				'_give_offline-donation-instruction_email_subject',
1263
				get_post_meta(
1264
					get_the_ID(),
1265
					// @todo: Delete this option later ( version > 2.0 ).
1266
					'_give_offline_donation_subject',
1267
					true
1268
				)
1269
			);
1270
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1271
1272
		}// End while().
1273
1274
		wp_reset_postdata();
1275
	} else {
1276
		// No more forms found, finish up.
1277
		give_set_upgrade_complete( 'v20_upgrades_form_metadata' );
1278
	}
1279
}
1280
1281
1282
/**
1283
 * Upgrade payment metadata for new metabox settings.
1284
 *
1285
 * @since  2.0
1286
 * @global wpdb $wpdb
1287
 * @return void
1288
 */
1289
function give_v20_upgrades_payment_metadata_callback() {
1290
	global $wpdb;
1291
	$give_updates = Give_Updates::get_instance();
1292
1293
	// form query
1294
	$forms = new WP_Query( array(
1295
			'paged'          => $give_updates->step,
1296
			'status'         => 'any',
1297
			'order'          => 'ASC',
1298
			'post_type'      => 'give_payment',
1299
			'posts_per_page' => 20,
1300
		)
1301
	);
1302
1303
	if ( $forms->have_posts() ) {
1304
		$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) );
1305
1306
		while ( $forms->have_posts() ) {
1307
			$forms->the_post();
1308
			global $post;
1309
1310
			// Split _give_payment_meta meta.
1311
			$payment_meta = maybe_unserialize( $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_meta' ) ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
1312
			if ( ! empty( $payment_meta ) ) {
1313
				_give_20_bc_split_and_save_give_payment_meta( $post->ID, maybe_unserialize( $payment_meta ) );
1314
			}
1315
1316
			$deprecated_meta_keys = array(
1317
				'_give_payment_customer_id' => '_give_payment_donor_id',
1318
				'_give_payment_user_email'  => '_give_payment_donor_email',
1319
				'_give_payment_user_ip'     => '_give_payment_donor_ip',
1320
			);
1321
1322
			foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) {
1323
				// Do not add new meta key if already exist.
1324
				if( give_get_meta( $post->ID, $new_meta_key, true )) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
1325
					continue;
1326
				}
1327
1328
				$meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key=%s", $old_meta_key ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
1329
				if ( ! empty( $meta_id ) ) {
1330
					$wpdb->get_var( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_key=%s WHERE meta_id=%d", $new_meta_key, $meta_id ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
1331
				}
1332
			}
1333
1334
			// Bailout
1335
			if ( $donor_id = give_get_meta( $post->ID, '_give_payment_donor_id', true ) ) {
1336
				/* @var Give_Donor $donor */
1337
				$donor = new Give_Donor( $donor_id );
1338
1339
				$address['line1']   = give_get_meta( $post->ID, '_give_donor_billing_address1', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1340
				$address['line2']   = give_get_meta( $post->ID, '_give_donor_billing_address2', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1341
				$address['city']    = give_get_meta( $post->ID, '_give_donor_billing_city', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1342
				$address['state']   = give_get_meta( $post->ID, '_give_donor_billing_state', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1343
				$address['zip']     = give_get_meta( $post->ID, '_give_donor_billing_zip', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1344
				$address['country'] = give_get_meta( $post->ID, '_give_donor_billing_country', true, '' );
0 ignored issues
show
Documentation introduced by
'' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1345
1346
				// Save address.
1347
				$donor->add_address( 'billing[]', $address );
1348
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1349
1350
		}// End while().
1351
1352
		wp_reset_postdata();
1353
	} else {
1354
		// Delete user id meta.
1355
		$wpdb->get_var( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_user_id' ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
1356
1357
		// No more forms found, finish up.
1358
		give_set_upgrade_complete( 'v20_upgrades_payment_metadata' );
1359
	}
1360
}
1361
1362
1363
/**
1364
 * Upgrade logs data.
1365
 *
1366
 * @since  2.0
1367
 * @return void
1368
 */
1369
function give_v20_logs_upgrades_callback() {
1370
	global $wpdb;
1371
	$give_updates = Give_Updates::get_instance();
1372
1373
	// form query
1374
	$forms = new WP_Query( array(
1375
			'paged'          => $give_updates->step,
1376
			'order'          => 'DESC',
1377
			'post_type'      => 'give_log',
1378
			'post_status'    => 'any',
1379
			'posts_per_page' => 20,
1380
		)
1381
	);
1382
1383
	if ( $forms->have_posts() ) {
1384
		$give_updates->set_percentage( $forms->found_posts, $give_updates->step * 20 );
1385
1386
		while ( $forms->have_posts() ) {
1387
			$forms->the_post();
1388
			global $post;
1389
			$term      = get_the_terms( $post->ID, 'give_log_type' );
1390
			$term      = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array();
1391
			$term_name = ! empty( $term ) ? $term->slug : '';
1392
1393
			$log_data = array(
1394
				'ID'           => $post->ID,
1395
				'log_title'    => $post->post_title,
1396
				'log_content'  => $post->post_content,
1397
				'log_parent'   => 0,
1398
				'log_type'     => $term_name,
1399
				'log_date'     => $post->post_date,
1400
				'log_date_gmt' => $post->post_date_gmt,
1401
			);
1402
			$log_meta = array();
1403
1404
			if ( $old_log_meta = get_post_meta( $post->ID ) ) {
1405
				foreach ( $old_log_meta as $meta_key => $meta_value ) {
1406
					switch ( $meta_key ) {
1407
						case '_give_log_payment_id':
1408
							$log_data['log_parent']        = current( $meta_value );
1409
							$log_meta['_give_log_form_id'] = $post->post_parent;
1410
							break;
1411
1412
						default:
1413
							$log_meta[ $meta_key ] = current( $meta_value );
1414
					}
1415
				}
1416
			}
1417
1418
			if ( 'api_request' === $term_name ) {
1419
				$log_meta['_give_log_api_query'] = $post->post_excerpt;
1420
			}
1421
1422
			$wpdb->insert( "{$wpdb->prefix}give_logs", $log_data );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
1423
1424
			if ( ! empty( $log_meta ) ) {
1425
				foreach ( $log_meta as $meta_key => $meta_value ) {
1426
					Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value );
1427
				}
1428
			}
1429
1430
			$logIDs[] = $post->ID;
1431
		}// End while().
1432
1433
		wp_reset_postdata();
1434
	} else {
1435
		// Delete terms and taxonomy.
1436
		$terms = get_terms( 'give_log_type', array( 'fields' => 'ids', 'hide_empty' => false ) );
1437
		if ( ! empty( $terms ) ) {
1438
			foreach ( $terms as $term ) {
1439
				wp_delete_term( $term, 'give_log_type' );
1440
			}
1441
		}
1442
1443
		// Delete logs
1444
		$logIDs = get_posts( array(
1445
				'order'          => 'DESC',
1446
				'post_type'      => 'give_log',
1447
				'post_status'    => 'any',
1448
				'posts_per_page' => - 1,
1449
				'fields'         => 'ids',
1450
			)
1451
		);
1452
1453
		if ( ! empty( $logIDs ) ) {
1454
			foreach ( $logIDs as $log ) {
1455
				// Delete term relationship and posts.
1456
				wp_delete_object_term_relationships( $log, 'give_log_type' );
1457
				wp_delete_post( $log, true );
1458
			}
1459
		}
1460
1461
		unregister_taxonomy( 'give_log_type' );
1462
1463
		// Delete log cache.
1464
		Give()->logs->delete_cache();
1465
1466
		// No more forms found, finish up.
1467
		give_set_upgrade_complete( 'v20_logs_upgrades' );
1468
	}
1469
}
1470
1471
1472
/**
1473
 * Move payment and form metadata to new table
1474
 *
1475
 * @since  2.0
1476
 * @return void
1477
 */
1478
function give_v20_move_metadata_into_new_table_callback() {
1479
	global $wpdb;
1480
	$give_updates = Give_Updates::get_instance();
1481
1482
	// form query
1483
	$payments = new WP_Query( array(
1484
			'paged'          => $give_updates->step,
1485
			'status'         => 'any',
1486
			'order'          => 'ASC',
1487
			'post_type'      => array( 'give_forms', 'give_payment' ),
1488
			'posts_per_page' => 20,
1489
		)
1490
	);
1491
1492
	if ( $payments->have_posts() ) {
1493
		$give_updates->set_percentage( $payments->found_posts, $give_updates->step * 20 );
1494
1495
		while ( $payments->have_posts() ) {
1496
			$payments->the_post();
1497
			global $post;
1498
1499
			$meta_data = $wpdb->get_results(
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
1500
				$wpdb->prepare(
1501
					"SELECT * FROM $wpdb->postmeta where post_id=%d",
1502
					get_the_ID()
1503
				),
1504
				ARRAY_A
1505
			);
1506
1507
			if ( ! empty( $meta_data ) ) {
1508
				foreach ( $meta_data as $index => $data ) {
1509
					switch ( $post->post_type ) {
1510 View Code Duplication
						case 'give_forms':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1511
							$data['form_id'] = $data['post_id'];
1512
							unset( $data['post_id'] );
1513
1514
							Give()->form_meta->insert( $data );
1515
							delete_post_meta( get_the_ID(), $data['meta_key'] );
1516
1517
							break;
1518
1519 View Code Duplication
						case 'give_payment':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1520
							$data['payment_id'] = $data['post_id'];
1521
							unset( $data['post_id'] );
1522
1523
							Give()->payment_meta->insert( $data );
1524
							delete_post_meta( get_the_ID(), $data['meta_key'] );
1525
1526
							break;
1527
					}
1528
				}
1529
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1530
1531
		}// End while().
1532
1533
		wp_reset_postdata();
1534
	} else {
1535
		// No more forms found, finish up.
1536
		give_set_upgrade_complete( 'v20_move_metadata_into_new_table' );
1537
	}
1538
}
1539
1540
1541
/**
1542
 * Upgrade logs data.
1543
 *
1544
 * @since  2.0
1545
 * @global wpdb $wpdb
1546
 * @return void
1547
 */
1548
function give_v20_rename_donor_tables_callback() {
1549
	global $wpdb;
1550
1551
	/* @var Give_Updates $give_updates */
1552
	$give_updates = Give_Updates::get_instance();
1553
1554
	$tables = array(
1555
		"{$wpdb->prefix}give_customers"    => "{$wpdb->prefix}give_donors",
1556
		"{$wpdb->prefix}give_customermeta" => "{$wpdb->prefix}give_donormeta",
1557
	);
1558
1559
	// Alter customer table
1560
	foreach ( $tables as $old_table => $new_table ) {
1561
		if (
1562
			$wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $old_table ) ) &&
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
Coding Style Comprehensibility introduced by
The string literal SHOW TABLES LIKE %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
1563
			! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $new_table ) )
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
Coding Style Comprehensibility introduced by
The string literal SHOW TABLES LIKE %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
1564
		) {
1565
			$wpdb->query( "ALTER TABLE {$old_table} RENAME TO {$new_table}" );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
introduced by
Attempting a database schema change is highly discouraged.
Loading history...
1566
1567
			if ( "{$wpdb->prefix}give_donormeta" === $new_table ) {
1568
				$wpdb->query( "ALTER TABLE {$new_table} CHANGE COLUMN customer_id donor_id bigint(20)" );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
introduced by
Attempting a database schema change is highly discouraged.
Loading history...
1569
			}
1570
		}
1571
	}
1572
1573
	$give_updates->percentage = 100;
0 ignored issues
show
Documentation Bug introduced by
It seems like 100 of type integer is incompatible with the declared type array of property $percentage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1574
1575
	// No more forms found, finish up.
1576
	give_set_upgrade_complete( 'v20_rename_donor_tables' );
1577
1578
	// Re initiate donor classes.
1579
	Give()->donors     = new Give_DB_Donors();
1580
	Give()->donor_meta = new Give_DB_Donor_Meta();
1581
}