Completed
Push — currency-issue ( df424f )
by Ravinder
192:16 queued 185:58
created

upgrade-functions.php ➔ give_v1817_update_donation_iranian_currency_code()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 0
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
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, '1.8.13', '<' ) :
66
			give_v1813_upgrades();
67
			$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...
68
69
		case version_compare( $give_version, '1.8.17', '<' ) :
70
			give_v1817_upgrades();
71
			$did_upgrade = true;
72
	}
73
74
	if ( $did_upgrade ) {
75
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
76
	}
77
}
78
79
add_action( 'admin_init', 'give_do_automatic_upgrades' );
80
add_action( 'give_upgrades', 'give_do_automatic_upgrades' );
81
82
/**
83
 * Display Upgrade Notices
84
 *
85
 * @since 1.0
86
 * @since 1.8.12 Update new update process code.
87
 *
88
 * @param Give_Updates $give_updates
89
 *
90
 * @return void
91
 */
92
function give_show_upgrade_notices( $give_updates ) {
93
	// v1.3.2 Upgrades
94
	$give_updates->register(
95
		array(
96
			'id'       => 'upgrade_give_payment_customer_id',
97
			'version'  => '1.3.2',
98
			'callback' => 'give_v132_upgrade_give_payment_customer_id',
99
		)
100
	);
101
102
	// v1.3.4 Upgrades ensure the user has gone through 1.3.4.
103
	$give_updates->register(
104
		array(
105
			'id'       => 'upgrade_give_offline_status',
106
			'depend'   => 'upgrade_give_payment_customer_id',
107
			'version'  => '1.3.4',
108
			'callback' => 'give_v134_upgrade_give_offline_status',
109
		)
110
	);
111
112
	// v1.8 form metadata upgrades.
113
	$give_updates->register(
114
		array(
115
			'id'       => 'v18_upgrades_form_metadata',
116
			'version'  => '1.8',
117
			'callback' => 'give_v18_upgrades_form_metadata',
118
		)
119
	);
120
121
	// v1.8.9 Upgrades
122
	$give_updates->register(
123
		array(
124
			'id'       => 'v189_upgrades_levels_post_meta',
125
			'version'  => '1.8.9',
126
			'callback' => 'give_v189_upgrades_levels_post_meta_callback',
127
		)
128
	);
129
130
	// v1.8.12 Upgrades
131
	$give_updates->register(
132
		array(
133
			'id'       => 'v1812_update_amount_values',
134
			'version'  => '1.8.12',
135
			'callback' => 'give_v1812_update_amount_values_callback',
136
		)
137
	);
138
139
	// v1.8.12 Upgrades
140
	$give_updates->register(
141
		array(
142
			'id'       => 'v1812_update_donor_purchase_values',
143
			'version'  => '1.8.12',
144
			'callback' => 'give_v1812_update_donor_purchase_value_callback',
145
		)
146
	);
147
148
	// v1.8.13 Upgrades for donor
149
	$give_updates->register(
150
		array(
151
			'id'       => 'v1813_update_donor_user_roles',
152
			'version'  => '1.8.13',
153
			'callback' => 'give_v1813_update_donor_user_roles_callback',
154
		)
155
	);
156
157
	// v1.8.17 Upgrades for donations.
158
	$give_updates->register( array(
159
		'id'       => 'v1817_update_donation_iranian_currency_code',
160
		'version'  => '1.8.17',
161
		'callback' => 'give_v1817_update_donation_iranian_currency_code',
162
	) );
163
}
164
165
add_action( 'give_register_updates', 'give_show_upgrade_notices' );
166
167
/**
168
 * Triggers all upgrade functions
169
 *
170
 * This function is usually triggered via AJAX
171
 *
172
 * @since 1.0
173
 * @return void
174
 */
175
function give_trigger_upgrades() {
176
177 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...
178
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
179
			'response' => 403,
180
		) );
181
	}
182
183
	$give_version = get_option( 'give_version' );
184
185
	if ( ! $give_version ) {
186
		// 1.0 is the first version to use this option so we must add it.
187
		$give_version = '1.0';
188
		add_option( 'give_version', $give_version );
189
	}
190
191
	update_option( 'give_version', GIVE_VERSION );
192
	delete_option( 'give_doing_upgrade' );
193
194
	if ( DOING_AJAX ) {
195
		die( 'complete' );
196
	} // End if().
197
}
198
199
add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' );
200
201
202
/**
203
 * Upgrades the
204
 *
205
 * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id`
206
 *
207
 * @since      1.3.2
208
 */
209
function give_v132_upgrade_give_payment_customer_id() {
210
	global $wpdb;
211
212
	/* @var Give_Updates $give_updates */
213
	$give_updates = Give_Updates::get_instance();
214
215 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...
216
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
217
			'response' => 403,
218
		) );
219
	}
220
221
	ignore_user_abort( true );
222
223
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
224
		@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...
225
	}
226
227
	// UPDATE DB METAKEYS.
228
	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
229
	$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...
230
231
	$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...
232
	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
233
}
234
235
236
/**
237
 * Upgrades the Offline Status
238
 *
239
 * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned
240
 *
241
 * @since      1.3.4
242
 */
243
function give_v134_upgrade_give_offline_status() {
244
	global $wpdb;
245
246
	/* @var Give_Updates $give_updates */
247
	$give_updates = Give_Updates::get_instance();
248
249
	// Get abandoned offline payments.
250
	$select = "SELECT ID FROM $wpdb->posts p ";
251
	$join   = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
252
	$where  = "WHERE p.post_type = 'give_payment' ";
253
	$where  .= "AND ( p.post_status = 'abandoned' )";
254
	$where  .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
255
256
	$sql            = $select . $join . $where;
257
	$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...
258
259
	foreach ( $found_payments as $payment ) {
260
261
		// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves.
262
		$modified_time = get_post_modified_time( 'U', false, $payment );
263
264
		// 1450124863 =  12/10/2015 20:42:25.
265
		if ( $modified_time >= 1450124863 ) {
266
267
			give_update_payment_status( $payment, 'pending' );
268
269
		}
270
	}
271
272
	$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...
273
	give_set_upgrade_complete( 'upgrade_give_offline_status' );
274
}
275
276
277
/**
278
 * Cleanup User Roles
279
 *
280
 * This upgrade routine removes unused roles and roles with typos
281
 *
282
 * @since      1.5.2
283
 */
284
function give_v152_cleanup_users() {
285
286
	$give_version = get_option( 'give_version' );
287
288
	if ( ! $give_version ) {
289
		// 1.0 is the first version to use this option so we must add it.
290
		$give_version = '1.0';
291
	}
292
293
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
294
295
	// v1.5.2 Upgrades
296
	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
297
298
		// Delete all caps with "ss".
299
		// Also delete all unused "campaign" roles.
300
		$delete_caps = array(
301
			'delete_give_formss',
302
			'delete_others_give_formss',
303
			'delete_private_give_formss',
304
			'delete_published_give_formss',
305
			'read_private_forms',
306
			'edit_give_formss',
307
			'edit_others_give_formss',
308
			'edit_private_give_formss',
309
			'edit_published_give_formss',
310
			'publish_give_formss',
311
			'read_private_give_formss',
312
			'assign_give_campaigns_terms',
313
			'delete_give_campaigns',
314
			'delete_give_campaigns_terms',
315
			'delete_give_campaignss',
316
			'delete_others_give_campaignss',
317
			'delete_private_give_campaignss',
318
			'delete_published_give_campaignss',
319
			'edit_give_campaigns',
320
			'edit_give_campaigns_terms',
321
			'edit_give_campaignss',
322
			'edit_others_give_campaignss',
323
			'edit_private_give_campaignss',
324
			'edit_published_give_campaignss',
325
			'manage_give_campaigns_terms',
326
			'publish_give_campaignss',
327
			'read_give_campaigns',
328
			'read_private_give_campaignss',
329
			'view_give_campaigns_stats',
330
			'delete_give_paymentss',
331
			'delete_others_give_paymentss',
332
			'delete_private_give_paymentss',
333
			'delete_published_give_paymentss',
334
			'edit_give_paymentss',
335
			'edit_others_give_paymentss',
336
			'edit_private_give_paymentss',
337
			'edit_published_give_paymentss',
338
			'publish_give_paymentss',
339
			'read_private_give_paymentss',
340
		);
341
342
		global $wp_roles;
343
		foreach ( $delete_caps as $cap ) {
344
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
345
				$wp_roles->remove_cap( $role, $cap );
346
			}
347
		}
348
349
		// Create Give plugin roles.
350
		$roles = new Give_Roles();
351
		$roles->add_roles();
352
		$roles->add_caps();
353
354
		// The Update Ran.
355
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
356
		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
357
		delete_option( 'give_doing_upgrade' );
358
359
	}// End if().
360
361
}
362
363
add_action( 'admin_init', 'give_v152_cleanup_users' );
364
365
/**
366
 * 1.6 Upgrade routine to create the customer meta table.
367
 *
368
 * @since  1.6
369
 * @return void
370
 */
371
function give_v16_upgrades() {
372
	// Create the donor databases.
373
	$donors_db = new Give_DB_Donors();
374
	$donors_db->create_table();
375
	$donor_meta = new Give_DB_Donor_Meta();
376
	$donor_meta->create_table();
377
}
378
379
/**
380
 * 1.7 Upgrades.
381
 *
382
 * a. Update license api data for plugin addons.
383
 * b. Cleanup user roles.
384
 *
385
 * @since  1.7
386
 * @return void
387
 */
388
function give_v17_upgrades() {
389
	// Upgrade license data.
390
	give_v17_upgrade_addon_license_data();
391
	give_v17_cleanup_roles();
392
}
393
394
/**
395
 * Upgrade license data
396
 *
397
 * @since 1.7
398
 */
399
function give_v17_upgrade_addon_license_data() {
400
	$give_options = give_get_settings();
401
402
	$api_url = 'https://givewp.com/give-sl-api/';
403
404
	// Get addons license key.
405
	$addons = array();
406
	foreach ( $give_options as $key => $value ) {
407
		if ( false !== strpos( $key, '_license_key' ) ) {
408
			$addons[ $key ] = $value;
409
		}
410
	}
411
412
	// Bailout: We do not have any addon license data to upgrade.
413
	if ( empty( $addons ) ) {
414
		return false;
415
	}
416
417
	foreach ( $addons as $key => $addon_license ) {
418
419
		// Get addon shortname.
420
		$shortname = str_replace( '_license_key', '', $key );
421
422
		// Addon license option name.
423
		$addon_license_option_name = $shortname . '_license_active';
424
425
		// bailout if license is empty.
426
		if ( empty( $addon_license ) ) {
427
			delete_option( $addon_license_option_name );
428
			continue;
429
		}
430
431
		// Get addon name.
432
		$addon_name       = array();
433
		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
434
		foreach ( $addon_name_parts as $name_part ) {
435
436
			// Fix addon name
437
			switch ( $name_part ) {
438
				case 'authorizenet' :
439
					$name_part = 'authorize.net';
440
					break;
441
			}
442
443
			$addon_name[] = ucfirst( $name_part );
444
		}
445
446
		$addon_name = implode( ' ', $addon_name );
447
448
		// Data to send to the API
449
		$api_params = array(
450
			'edd_action' => 'activate_license', // never change from "edd_" to "give_"!
451
			'license'    => $addon_license,
452
			'item_name'  => urlencode( $addon_name ),
453
			'url'        => home_url(),
454
		);
455
456
		// Call the API.
457
		$response = wp_remote_post(
458
			$api_url,
459
			array(
460
				'timeout'   => 15,
461
				'sslverify' => false,
462
				'body'      => $api_params,
463
			)
464
		);
465
466
		// Make sure there are no errors.
467
		if ( is_wp_error( $response ) ) {
468
			delete_option( $addon_license_option_name );
469
			continue;
470
		}
471
472
		// Tell WordPress to look for updates.
473
		set_site_transient( 'update_plugins', null );
474
475
		// Decode license data.
476
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
477
		update_option( $addon_license_option_name, $license_data );
478
	}// End foreach().
479
}
480
481
482
/**
483
 * Cleanup User Roles.
484
 *
485
 * This upgrade routine removes unused roles and roles with typos.
486
 *
487
 * @since      1.7
488
 */
489
function give_v17_cleanup_roles() {
490
491
	// Delete all caps with "_give_forms_" and "_give_payments_"
492
	// These roles have no usage; the proper is singular.
493
	$delete_caps = array(
494
		'view_give_forms_stats',
495
		'delete_give_forms_terms',
496
		'assign_give_forms_terms',
497
		'edit_give_forms_terms',
498
		'manage_give_forms_terms',
499
		'view_give_payments_stats',
500
		'manage_give_payments_terms',
501
		'edit_give_payments_terms',
502
		'assign_give_payments_terms',
503
		'delete_give_payments_terms',
504
	);
505
506
	global $wp_roles;
507
	foreach ( $delete_caps as $cap ) {
508
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
509
			$wp_roles->remove_cap( $role, $cap );
510
		}
511
	}
512
513
	// Set roles again.
514
	$roles = new Give_Roles();
515
	$roles->add_roles();
516
	$roles->add_caps();
517
518
}
519
520
/**
521
 * 1.8 Upgrades.
522
 *
523
 * a. Upgrade checkbox settings to radio button settings.
524
 * a. Update form meta for new metabox settings.
525
 *
526
 * @since  1.8
527
 * @return void
528
 */
529
function give_v18_upgrades() {
530
	// Upgrade checkbox settings to radio button settings.
531
	give_v18_upgrades_core_setting();
532
}
533
534
/**
535
 * Upgrade core settings.
536
 *
537
 * @since  1.8
538
 * @return void
539
 */
540
function give_v18_upgrades_core_setting() {
541
	// Core settings which changes from checkbox to radio.
542
	$core_setting_names = array_merge(
543
		array_keys( give_v18_renamed_core_settings() ),
544
		array(
545
			'uninstall_on_delete',
546
			'scripts_footer',
547
			'test_mode',
548
			'email_access',
549
			'terms',
550
			'give_offline_donation_enable_billing_fields',
551
		)
552
	);
553
554
	// Bailout: If not any setting define.
555
	if ( $give_settings = get_option( 'give_settings' ) ) {
556
557
		$setting_changed = false;
558
559
		// Loop: check each setting field.
560
		foreach ( $core_setting_names as $setting_name ) {
561
			// New setting name.
562
			$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name );
563
564
			// Continue: If setting already set.
565
			if (
566
				array_key_exists( $new_setting_name, $give_settings )
567
				&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) )
568
			) {
569
				continue;
570
			}
571
572
			// Set checkbox value to radio value.
573
			$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' );
574
575
			// @see https://github.com/WordImpress/Give/issues/1063
576
			if ( false !== strpos( $setting_name, 'disable_' ) ) {
577
578
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' );
579
			} elseif ( false !== strpos( $setting_name, 'enable_' ) ) {
580
581
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' );
582
			}
583
584
			// Tell bot to update core setting to db.
585
			if ( ! $setting_changed ) {
586
				$setting_changed = true;
587
			}
588
		}
589
590
		// Update setting only if they changed.
591
		if ( $setting_changed ) {
592
			update_option( 'give_settings', $give_settings );
593
		}
594
	}// End if().
595
596
	give_set_upgrade_complete( 'v18_upgrades_core_setting' );
597
}
598
599
/**
600
 * Upgrade form metadata for new metabox settings.
601
 *
602
 * @since  1.8
603
 * @return void
604
 */
605
function give_v18_upgrades_form_metadata() {
606
	/* @var Give_Updates $give_updates */
607
	$give_updates = Give_Updates::get_instance();
608
609
	// form query
610
	$forms = new WP_Query( array(
611
			'paged'          => $give_updates->step,
612
			'status'         => 'any',
613
			'order'          => 'ASC',
614
			'post_type'      => 'give_forms',
615
			'posts_per_page' => 20,
616
		)
617
	);
618
619
	if ( $forms->have_posts() ) {
620
		$give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) );
621
622
		while ( $forms->have_posts() ) {
623
			$forms->the_post();
624
625
			// Form content.
626
			// Note in version 1.8 display content setting split into display content and content placement setting.
627
			// You can delete _give_content_option in future
628
			$show_content = give_get_meta( get_the_ID(), '_give_content_option', true );
629
			if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) {
630
				$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' );
631
				give_update_meta( get_the_ID(), '_give_display_content', $field_value );
632
633
				$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' );
634
				give_update_meta( get_the_ID(), '_give_content_placement', $field_value );
635
			}
636
637
			// "Disable" Guest Donation. Checkbox
638
			// See: https://github.com/WordImpress/Give/issues/1470
639
			$guest_donation        = give_get_meta( get_the_ID(), '_give_logged_in_only', true );
640
			$guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' );
641
			give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval );
642
643
			// Offline Donations
644
			// See: https://github.com/WordImpress/Give/issues/1579
645
			$offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true );
646
			if ( 'no' === $offline_donation ) {
647
				$offline_donation_newval = 'global';
648
			} elseif ( 'yes' === $offline_donation ) {
649
				$offline_donation_newval = 'enabled';
650
			} else {
651
				$offline_donation_newval = 'disabled';
652
			}
653
			give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval );
654
655
			// Convert yes/no setting field to enabled/disabled.
656
			$form_radio_settings = array(
657
				// Custom Amount.
658
				'_give_custom_amount',
659
660
				// Donation Gaol.
661
				'_give_goal_option',
662
663
				// Close Form.
664
				'_give_close_form_when_goal_achieved',
665
666
				// Term & conditions.
667
				'_give_terms_option',
668
669
				// Billing fields.
670
				'_give_offline_donation_enable_billing_fields_single',
671
			);
672
673
			foreach ( $form_radio_settings as $meta_key ) {
674
				// Get value.
675
				$field_value = give_get_meta( get_the_ID(), $meta_key, true );
676
677
				// Convert meta value only if it is in yes/no/none.
678
				if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) {
679
680
					$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' );
681
					give_update_meta( get_the_ID(), $meta_key, $field_value );
682
				}
683
			}
684
		}// End while().
685
686
		wp_reset_postdata();
687
688
	} else {
689
		// No more forms found, finish up.
690
		give_set_upgrade_complete( 'v18_upgrades_form_metadata' );
691
	}
692
}
693
694
695
/**
696
 * Get list of core setting renamed in version 1.8.
697
 *
698
 * @since  1.8
699
 * @return array
700
 */
701
function give_v18_renamed_core_settings() {
702
	return array(
703
		'disable_paypal_verification' => 'paypal_verification',
704
		'disable_css'                 => 'css',
705
		'disable_welcome'             => 'welcome',
706
		'disable_forms_singular'      => 'forms_singular',
707
		'disable_forms_archives'      => 'forms_archives',
708
		'disable_forms_excerpt'       => 'forms_excerpt',
709
		'disable_form_featured_img'   => 'form_featured_img',
710
		'disable_form_sidebar'        => 'form_sidebar',
711
		'disable_admin_notices'       => 'admin_notices',
712
		'disable_the_content_filter'  => 'the_content_filter',
713
		'enable_floatlabels'          => 'floatlabels',
714
		'enable_categories'           => 'categories',
715
		'enable_tags'                 => 'tags',
716
	);
717
}
718
719
720
/**
721
 * Upgrade core settings.
722
 *
723
 * @since  1.8.7
724
 * @return void
725
 */
726
function give_v187_upgrades() {
727
	global $wpdb;
728
729
	/**
730
	 * Upgrade 1: Remove stat and cache transients.
731
	 */
732
	$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...
733
		$wpdb->prepare(
734
			"SELECT * FROM {$wpdb->options} where (option_name LIKE '%%%s%%' OR option_name LIKE '%%%s%%')",
735
			array(
736
				'_transient_give_stats_',
737
				'give_cache',
738
				'_transient_give_add_ons_feed',
739
				'_transient__give_ajax_works' .
740
				'_transient_give_total_api_keys',
741
				'_transient_give_i18n_give_promo_hide',
742
				'_transient_give_contributors',
743
				'_transient_give_estimated_monthly_stats',
744
				'_transient_give_earnings_total',
745
				'_transient_give_i18n_give_',
746
				'_transient__give_installed',
747
				'_transient__give_activation_redirect',
748
				'_transient__give_hide_license_notices_shortly_',
749
				'give_income_total',
750
			)
751
		),
752
		1
753
	);
754
755
	// User related transients.
756
	$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...
757
		$wpdb->prepare(
758
			"SELECT user_id, meta_key
759
			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...
760
			WHERE meta_value=%s",
761
			'give_user_public_key'
762
		),
763
		ARRAY_A
764
	);
765
766
	if ( ! empty( $user_apikey_options ) ) {
767
		foreach ( $user_apikey_options as $user ) {
768
			$cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] );
769
			$cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] );
770
			$cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] );
771
		}
772
	}
773
774
	if ( ! empty( $cached_options ) ) {
775
		foreach ( $cached_options as $option ) {
776 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...
777
				case ( false !== strpos( $option, 'transient' ) ):
778
					$option = str_replace( '_transient_', '', $option );
779
					delete_transient( $option );
780
					break;
781
782
				default:
783
					delete_option( $option );
784
			}
785
		}
786
	}
787
}
788
789
/**
790
 * Update Capabilities for Give_Worker User Role.
791
 *
792
 * This upgrade routine will update access rights for Give_Worker User Role.
793
 *
794
 * @since      1.8.8
795
 */
796
function give_v188_upgrades() {
797
798
	global $wp_roles;
799
800
	// Get the role object.
801
	$give_worker = get_role( 'give_worker' );
802
803
	// A list of capabilities to add for give workers.
804
	$caps_to_add = array(
805
		'edit_posts',
806
		'edit_pages',
807
	);
808
809
	foreach ( $caps_to_add as $cap ) {
810
		// Add the capability.
811
		$give_worker->add_cap( $cap );
812
	}
813
814
}
815
816
/**
817
 * Update Post meta for minimum and maximum amount for multi level donation forms
818
 *
819
 * This upgrade routine adds post meta for give_forms CPT for multi level donation form.
820
 *
821
 * @since      1.8.9
822
 */
823
function give_v189_upgrades_levels_post_meta_callback() {
824
	/* @var Give_Updates $give_updates */
825
	$give_updates = Give_Updates::get_instance();
826
827
	// form query
828
	$donation_forms = new WP_Query( array(
829
			'paged'          => $give_updates->step,
830
			'status'         => 'any',
831
			'order'          => 'ASC',
832
			'post_type'      => 'give_forms',
833
			'posts_per_page' => 20,
834
		)
835
	);
836
837
	if ( $donation_forms->have_posts() ) {
838
		$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) );
839
840
		while ( $donation_forms->have_posts() ) {
841
			$donation_forms->the_post();
842
			$form_id = get_the_ID();
843
844
			// Remove formatting from _give_set_price
845
			update_post_meta(
846
				$form_id,
847
				'_give_set_price',
848
				give_sanitize_amount( get_post_meta( $form_id, '_give_set_price', true ) )
849
			);
850
851
			// Remove formatting from _give_custom_amount_minimum
852
			update_post_meta(
853
				$form_id,
854
				'_give_custom_amount_minimum',
855
				give_sanitize_amount( get_post_meta( $form_id, '_give_custom_amount_minimum', true ) )
856
			);
857
858
			// Bailout.
859
			if ( 'set' === get_post_meta( $form_id, '_give_price_option', true ) ) {
860
				continue;
861
			}
862
863
			$donation_levels = get_post_meta( $form_id, '_give_donation_levels', true );
864
865
			if ( ! empty( $donation_levels ) ) {
866
867
				foreach ( $donation_levels as $index => $donation_level ) {
868
					if ( isset( $donation_level['_give_amount'] ) ) {
869
						$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount( $donation_level['_give_amount'] );
870
					}
871
				}
872
873
				update_post_meta( $form_id, '_give_donation_levels', $donation_levels );
874
875
				$donation_levels_amounts = wp_list_pluck( $donation_levels, '_give_amount' );
876
877
				$min_amount = min( $donation_levels_amounts );
878
				$max_amount = max( $donation_levels_amounts );
879
880
				// Set Minimum and Maximum amount for Multi Level Donation Forms
881
				give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount( $min_amount ) : 0 );
882
				give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount( $max_amount ) : 0 );
883
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
884
885
		}
886
887
		/* Restore original Post Data */
888
		wp_reset_postdata();
889
	} else {
890
		// The Update Ran.
891
		give_set_upgrade_complete( 'v189_upgrades_levels_post_meta' );
892
	}
893
894
}
895
896
897
/**
898
 * Give version 1.8.9 upgrades
899
 *
900
 * @since      1.8.9
901
 */
902
function give_v189_upgrades() {
903
	/**
904
	 * 1. Remove user license related notice show blocked ( Give_Notice will handle )
905
	 */
906
	global $wpdb;
907
908
	// Delete permanent notice blocker.
909
	$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...
910
		$wpdb->prepare(
911
			"
912
					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...
913
					WHERE meta_key
914
					LIKE '%%%s%%'
915
					",
916
			'_give_hide_license_notices_permanently'
917
		)
918
	);
919
920
	// Delete short notice blocker.
921
	$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...
922
		$wpdb->prepare(
923
			"
924
					DELETE FROM $wpdb->options
925
					WHERE option_name
926
					LIKE '%%%s%%'
927
					",
928
			'__give_hide_license_notices_shortly_'
929
		)
930
	);
931
932
}
933
934
935
/**
936
 * Give version 1.8.9 upgrades
937
 *
938
 * @since      1.8.9
939
 */
940
function give_v1812_upgrades() {
941
	/**
942
	 * Validate number format settings.
943
	 */
944
	$give_settings        = give_get_settings();
945
	$give_setting_updated = false;
946
947
	if ( $give_settings['thousands_separator'] === $give_settings['decimal_separator'] ) {
948
		$give_settings['number_decimals']   = 0;
949
		$give_settings['decimal_separator'] = '';
950
		$give_setting_updated               = true;
951
952
	} elseif ( empty( $give_settings['decimal_separator'] ) ) {
953
		$give_settings['number_decimals'] = 0;
954
		$give_setting_updated             = true;
955
956
	} elseif ( 6 < absint( $give_settings['number_decimals'] ) ) {
957
		$give_settings['number_decimals'] = 5;
958
		$give_setting_updated             = true;
959
	}
960
961
	if ( $give_setting_updated ) {
962
		update_option( 'give_settings', $give_settings );
963
	}
964
}
965
966
967
/**
968
 * Give version 1.8.12 update
969
 *
970
 * Standardized amount values to six decimal
971
 *
972
 * @see        https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602
973
 *
974
 * @since      1.8.12
975
 */
976
function give_v1812_update_amount_values_callback() {
977
	/* @var Give_Updates $give_updates */
978
	$give_updates = Give_Updates::get_instance();
979
980
	// form query
981
	$donation_forms = new WP_Query( array(
982
			'paged'          => $give_updates->step,
983
			'status'         => 'any',
984
			'order'          => 'ASC',
985
			'post_type'      => array( 'give_forms', 'give_payment' ),
986
			'posts_per_page' => 20,
987
		)
988
	);
989
990
	if ( $donation_forms->have_posts() ) {
991
		$give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) );
992
993
		while ( $donation_forms->have_posts() ) {
994
			$donation_forms->the_post();
995
			global $post;
996
997
			$meta = get_post_meta( $post->ID );
998
999
			switch ( $post->post_type ) {
1000
				case 'give_forms':
1001
					// _give_set_price
1002
					if ( ! empty( $meta['_give_set_price'][0] ) ) {
1003
						update_post_meta( $post->ID, '_give_set_price', give_sanitize_amount_for_db( $meta['_give_set_price'][0] ) );
1004
					}
1005
1006
					// _give_custom_amount_minimum
1007
					if ( ! empty( $meta['_give_custom_amount_minimum'][0] ) ) {
1008
						update_post_meta( $post->ID, '_give_custom_amount_minimum', give_sanitize_amount_for_db( $meta['_give_custom_amount_minimum'][0] ) );
1009
					}
1010
1011
					// _give_levels_minimum_amount
1012
					if ( ! empty( $meta['_give_levels_minimum_amount'][0] ) ) {
1013
						update_post_meta( $post->ID, '_give_levels_minimum_amount', give_sanitize_amount_for_db( $meta['_give_levels_minimum_amount'][0] ) );
1014
					}
1015
1016
					// _give_levels_maximum_amount
1017
					if ( ! empty( $meta['_give_levels_maximum_amount'][0] ) ) {
1018
						update_post_meta( $post->ID, '_give_levels_maximum_amount', give_sanitize_amount_for_db( $meta['_give_levels_maximum_amount'][0] ) );
1019
					}
1020
1021
					// _give_set_goal
1022
					if ( ! empty( $meta['_give_set_goal'][0] ) ) {
1023
						update_post_meta( $post->ID, '_give_set_goal', give_sanitize_amount_for_db( $meta['_give_set_goal'][0] ) );
1024
					}
1025
1026
					// _give_form_earnings
1027
					if ( ! empty( $meta['_give_form_earnings'][0] ) ) {
1028
						update_post_meta( $post->ID, '_give_form_earnings', give_sanitize_amount_for_db( $meta['_give_form_earnings'][0] ) );
1029
					}
1030
1031
					// _give_custom_amount_minimum
1032
					if ( ! empty( $meta['_give_donation_levels'][0] ) ) {
1033
						$donation_levels = unserialize( $meta['_give_donation_levels'][0] );
1034
1035
						foreach ( $donation_levels as $index => $level ) {
1036
							if ( empty( $level['_give_amount'] ) ) {
1037
								continue;
1038
							}
1039
1040
							$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount_for_db( $level['_give_amount'] );
1041
						}
1042
1043
						$meta['_give_donation_levels'] = $donation_levels;
1044
						update_post_meta( $post->ID, '_give_donation_levels', $meta['_give_donation_levels'] );
1045
					}
1046
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1047
1048
					break;
1049
1050
				case 'give_payment':
1051
					// _give_payment_total
1052
					if ( ! empty( $meta['_give_payment_total'][0] ) ) {
1053
						update_post_meta( $post->ID, '_give_payment_total', give_sanitize_amount_for_db( $meta['_give_payment_total'][0] ) );
1054
					}
1055
1056
					break;
1057
			}
1058
		}
1059
1060
		/* Restore original Post Data */
1061
		wp_reset_postdata();
1062
	} else {
1063
		// The Update Ran.
1064
		give_set_upgrade_complete( 'v1812_update_amount_values' );
1065
	}
1066
}
1067
1068
1069
/**
1070
 * Give version 1.8.12 update
1071
 *
1072
 * Standardized amount values to six decimal for donor
1073
 *
1074
 * @see        https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602
1075
 *
1076
 * @since      1.8.12
1077
 */
1078
function give_v1812_update_donor_purchase_value_callback() {
1079
	/* @var Give_Updates $give_updates */
1080
	$give_updates = Give_Updates::get_instance();
1081
	$offset       = 1 === $give_updates->step ? 0 : $give_updates->step * 20;
1082
1083
	// form query
1084
	$donors = Give()->donors->get_donors( array(
1085
			'number' => 20,
1086
			'offset' => $offset,
1087
		)
1088
	);
1089
1090
	if ( ! empty( $donors ) ) {
1091
		$give_updates->set_percentage( Give()->donors->count(), ( $give_updates->step * 20 ) );
1092
1093
		/* @var Object $donor */
1094
		foreach ( $donors as $donor ) {
1095
			Give()->donors->update( $donor->id, array( 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ) );
1096
		}
1097
	} else {
1098
		// The Update Ran.
1099
		give_set_upgrade_complete( 'v1812_update_donor_purchase_values' );
1100
	}
1101
}
1102
1103
/**
1104
 * Upgrade routine for updating user roles for existing donors.
1105
 *
1106
 * @since 1.8.13
1107
 */
1108
function give_v1813_update_donor_user_roles_callback() {
1109
	/* @var Give_Updates $give_updates */
1110
	$give_updates = Give_Updates::get_instance();
1111
	$offset       = 1 === $give_updates->step ? 0 : $give_updates->step * 20;
1112
1113
	// Fetch all the existing donors.
1114
	$donors = Give()->donors->get_donors( array(
1115
			'number' => 20,
1116
			'offset' => $offset,
1117
		)
1118
	);
1119
1120
	if ( ! empty( $donors ) ) {
1121
		$give_updates->set_percentage( Give()->donors->count(), ( $give_updates->step * 20 ) );
1122
1123
		/* @var Object $donor */
1124
		foreach ( $donors as $donor ) {
1125
			$user_id = $donor->user_id;
1126
1127
			// Proceed, if donor is attached with user.
1128
			if ( $user_id ) {
1129
				$user = get_userdata( $user_id );
1130
1131
				// Update user role, if user has subscriber role.
1132
				if ( is_array( $user->roles ) && in_array( 'subscriber', $user->roles ) ) {
1133
					wp_update_user(
1134
						array(
1135
							'ID'   => $user_id,
1136
							'role' => 'give_donor',
1137
						)
1138
					);
1139
				}
1140
			}
1141
		}
1142
	} else {
1143
		// The Update Ran.
1144
		give_set_upgrade_complete( 'v1813_update_donor_user_roles' );
1145
	}
1146
}
1147
1148
/**
1149
 * Correct currency code for "Iranian Currency" for all of the payments.
1150
 *
1151
 * @since 1.8.17
1152
 */
1153
function give_v1817_update_donation_iranian_currency_code() {
1154
	/* @var Give_Updates $give_updates */
1155
	$give_updates = Give_Updates::get_instance();
1156
1157
	// form query
1158
	$payments = new WP_Query( array(
1159
			'paged'          => $give_updates->step,
1160
			'status'         => 'any',
1161
			'order'          => 'ASC',
1162
			'post_type'      => array( 'give_payment' ),
1163
			'posts_per_page' => 20,
1164
		)
1165
	);
1166
1167
	if ( $payments->have_posts() ) {
1168
		$give_updates->set_percentage( $payments->found_posts, ( $give_updates->step * 20 ) );
1169
1170
		while( $payments->have_posts() ) {
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...
1171
			$payments->the_post();
1172
1173
			$payment_meta = give_get_payment_meta( get_the_ID() );
1174
1175
			if ( 'RIAL' === $payment_meta['currency'] ) {
1176
				$payment_meta['currency'] = 'IRR';
1177
				give_update_meta( get_the_ID(), '_give_payment_meta', $payment_meta );
1178
			}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1179
1180
		}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1181
1182
	}else{
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...
1183
		// The Update Ran.
1184
		give_set_upgrade_complete( 'v1817_update_donation_iranian_currency_code' );
1185
	}
1186
}
1187
1188
/**
1189
 * Version 1.8.13 automatic updates
1190
 *
1191
 * @since 1.8.13
1192
 */
1193
function give_v1813_upgrades() {
1194
	// Update admin setting.
1195
	give_update_option( 'donor_default_user_role', 'give_donor' );
1196
1197
	// Update Give roles.
1198
	$roles = new Give_Roles();
1199
	$roles->add_roles();
1200
	$roles->add_caps();
1201
}
1202
1203
/**
1204
 * Correct currency code for "Iranian Currency" in Give setting.
1205
 * Version 1.8.17 automatic updates
1206
 *
1207
 * @since 1.8.17
1208
 */
1209
function give_v1817_upgrades() {
1210
	$give_settings = give_get_settings();
1211
1212
	if ( 'RIAL' === $give_settings['currency'] ) {
1213
		$give_settings['currency'] = 'IRR';
1214
		update_option( 'give_settings', $give_settings );
1215
	}
1216
}