Completed
Push — issues/1132 ( 578281...f0f195 )
by Ravinder
18:50
created

upgrade-functions.php ➔ give_set_upgrade_complete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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;
40
41
		case version_compare( $give_version, '1.7', '<' ) :
42
			give_v17_upgrades();
43
			$did_upgrade = true;
44
45
		case version_compare( $give_version, '1.8', '<' ) :
46
			give_v18_upgrades();
47
			$did_upgrade = true;
48
49
		case version_compare( $give_version, '1.8.7', '<' ) :
50
			give_v187_upgrades();
51
			$did_upgrade = true;
52
53
		case version_compare( $give_version, '1.8.8', '<' ) :
54
			give_v188_upgrades();
55
			$did_upgrade = true;
56
57
		case version_compare( $give_version, '2.0', '<' ) :
58
			give_v20_upgrades();
59
			$did_upgrade = true;
60
61
	}
62
63
	if ( $did_upgrade ) {
64
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
65
	}
66
}
67
68
add_action( 'admin_init', 'give_do_automatic_upgrades' );
69
add_action( 'give_upgrades', 'give_do_automatic_upgrades' );
70
71
/**
72
 * Display Upgrade Notices
73
 *
74
 * @since 1.0
75
 * @return void
76
 */
77
function give_show_upgrade_notices() {
78
	// Don't show notices on the upgrades page.
79
	if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-upgrades' ) {
80
		return;
81
	}
82
83
	$give_version = get_option( 'give_version' );
84
85
	if ( ! $give_version ) {
86
		// 1.0 is the first version to use this option so we must add it.
87
		$give_version = '1.0';
88
	}
89
90
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
91
92
	/*
93
	 *  NOTICE:
94
	 *
95
	 *  When adding new upgrade notices, please be sure to put the action into the upgrades array during install:
96
	 *  /includes/install.php @ Appox Line 156
97
	 *
98
	 */
99
100
	// v1.3.2 Upgrades
101
	if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) {
102
		printf(
103
		/* translators: %s: upgrade URL */
104
			'<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
105
			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) )
106
		);
107
	}
108
109
	// v1.3.4 Upgrades //ensure the user has gone through 1.3.4.
110
	if ( version_compare( $give_version, '1.3.4', '<' ) || ( ! give_has_upgrade_completed( 'upgrade_give_offline_status' ) && give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) ) {
111
		printf(
112
		/* translators: %s: upgrade URL */
113
			'<div class="updated"><p>' . __( 'Give needs to upgrade the donations database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
114
			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) )
115
		);
116
	}
117
118
	// Check if we have a stalled upgrade.
119
	$resume_upgrade = give_maybe_resume_upgrade();
120
	if ( ! empty( $resume_upgrade ) ) {
121
		$resume_url = add_query_arg( $resume_upgrade, admin_url( 'index.php' ) );
122
		echo Give_Notices::notice_html(
123
			sprintf(
124
				__( 'Give needs to complete a database upgrade that was previously started, click <a href="%s">here</a> to resume the upgrade.', 'give' ),
125
				esc_url( $resume_url )
126
			)
127
		);
128
129
		return;
130
	}
131
132
	// v1.8 form metadata upgrades.
133
	if ( version_compare( $give_version, '1.8', '<' ) || ! give_has_upgrade_completed( 'v18_upgrades_form_metadata' ) ) {
134
		echo Give_Notices::notice_html(
135
			sprintf(
136
				esc_html__( 'Give needs to upgrade the form database, click %1$shere%2$s to start the upgrade.', 'give' ),
137
				'<a class="give-upgrade-link" href="' . esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=give_v18_upgrades_form_metadata' ) ) . '">',
138
				'</a>'
139
			)
140
		);
141
	}
142
143
	// v1.8.9 Upgrades
144
	if ( version_compare( $give_version, '1.8.9', '<' ) || ( ! give_has_upgrade_completed( 'v189_upgrades_levels_post_meta' ) ) ) {
145
		printf(
146
		/* translators: %s: upgrade URL */
147
			'<div class="updated"><p>' . __( 'Give needs to upgrade the donation forms meta-fields in database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
148
			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=v189_upgrades_levels_post_meta' ) )
149
		);
150
	}
151
152
	// v2.0 form metadata upgrades.
153
	if ( version_compare( $give_version, '2.0', '<' ) || ! give_has_upgrade_completed( 'v20_upgrades_form_metadata' ) ) {
154
		echo Give_Notices::notice_html(
155
			sprintf(
156
				esc_html__( 'Give needs to upgrade the form database, click %1$shere%2$s to start the upgrade.', 'give' ),
157
				'<a class="give-upgrade-link" href="' . esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=give_v20_upgrades_form_metadata' ) ) . '">',
158
				'</a>'
159
			) );
160
	}
161
162
163
	// End 'Stepped' upgrade process notices.
164
	?>
165
	<script>
166
		jQuery(document).ready(function ($) {
167
			var $upgrade_links = $('.give-upgrade-link');
168
			if ($upgrade_links.length) {
169
				$upgrade_links.on('click', function (e) {
170
					e.preventDefault();
171
172
					if (!window.confirm('<?php _e( 'Please make sure to create a database backup before initiating the upgrade.', 'give' ); ?>')) {
173
						return;
174
					}
175
176
					// Redirect to upgrdae link.
177
					window.location.assign($(this).attr('href'));
178
				});
179
			}
180
		});
181
	</script>
182
	<?php
183
}
184
185
add_action( 'admin_notices', 'give_show_upgrade_notices' );
186
187
/**
188
 * Upgrades the
189
 *
190
 * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id`
191
 *
192
 * @since      1.3.2
193
 */
194
function give_v132_upgrade_give_payment_customer_id() {
195
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
196
	if ( ! current_user_can( 'manage_give_settings' ) ) {
197
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
198
			'response' => 403,
199
		) );
200
	}
201
202
	ignore_user_abort( true );
203
204
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
205
		@set_time_limit( 0 );
206
	}
207
208
	// UPDATE DB METAKEYS.
209
	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
210
	$query = $wpdb->query( $sql );
211
212
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
213
	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
214
	delete_option( 'give_doing_upgrade' );
215
	wp_redirect( admin_url() );
216
	exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v132_upgrade_give_payment_customer_id() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
217
218
}
219
220
add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' );
221
222
/**
223
 * Upgrades the Offline Status
224
 *
225
 * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned
226
 *
227
 * @since      1.3.4
228
 */
229
function give_v134_upgrade_give_offline_status() {
230
231
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
232
233
	if ( ! current_user_can( 'manage_give_settings' ) ) {
234
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
235
			'response' => 403,
236
		) );
237
	}
238
239
	ignore_user_abort( true );
240
241
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
242
		@set_time_limit( 0 );
243
	}
244
245
	// Get abandoned offline payments.
246
	$select = "SELECT ID FROM $wpdb->posts p ";
247
	$join   = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
248
	$where  = "WHERE p.post_type = 'give_payment' ";
249
	$where  .= "AND ( p.post_status = 'abandoned' )";
250
	$where  .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
251
252
	$sql            = $select . $join . $where;
253
	$found_payments = $wpdb->get_col( $sql );
254
255
	foreach ( $found_payments as $payment ) {
256
257
		// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves.
258
		$modified_time = get_post_modified_time( 'U', false, $payment );
259
260
		// 1450124863 =  12/10/2015 20:42:25.
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
261
		if ( $modified_time >= 1450124863 ) {
262
263
			give_update_payment_status( $payment, 'pending' );
264
265
		}
266
	}
267
268
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
269
	give_set_upgrade_complete( 'upgrade_give_offline_status' );
270
	delete_option( 'give_doing_upgrade' );
271
	wp_redirect( admin_url() );
272
	exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v134_upgrade_give_offline_status() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
273
274
}
275
276
add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' );
277
278
/**
279
 * Cleanup User Roles
280
 *
281
 * This upgrade routine removes unused roles and roles with typos
282
 *
283
 * @since      1.5.2
284
 */
285
function give_v152_cleanup_users() {
286
287
	$give_version = get_option( 'give_version' );
288
289
	if ( ! $give_version ) {
290
		// 1.0 is the first version to use this option so we must add it.
291
		$give_version = '1.0';
292
	}
293
294
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
295
296
	// v1.5.2 Upgrades
297
	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
298
299
		// Delete all caps with "ss".
300
		// Also delete all unused "campaign" roles.
301
		$delete_caps = array(
302
			'delete_give_formss',
303
			'delete_others_give_formss',
304
			'delete_private_give_formss',
305
			'delete_published_give_formss',
306
			'read_private_forms',
307
			'edit_give_formss',
308
			'edit_others_give_formss',
309
			'edit_private_give_formss',
310
			'edit_published_give_formss',
311
			'publish_give_formss',
312
			'read_private_give_formss',
313
			'assign_give_campaigns_terms',
314
			'delete_give_campaigns',
315
			'delete_give_campaigns_terms',
316
			'delete_give_campaignss',
317
			'delete_others_give_campaignss',
318
			'delete_private_give_campaignss',
319
			'delete_published_give_campaignss',
320
			'edit_give_campaigns',
321
			'edit_give_campaigns_terms',
322
			'edit_give_campaignss',
323
			'edit_others_give_campaignss',
324
			'edit_private_give_campaignss',
325
			'edit_published_give_campaignss',
326
			'manage_give_campaigns_terms',
327
			'publish_give_campaignss',
328
			'read_give_campaigns',
329
			'read_private_give_campaignss',
330
			'view_give_campaigns_stats',
331
			'delete_give_paymentss',
332
			'delete_others_give_paymentss',
333
			'delete_private_give_paymentss',
334
			'delete_published_give_paymentss',
335
			'edit_give_paymentss',
336
			'edit_others_give_paymentss',
337
			'edit_private_give_paymentss',
338
			'edit_published_give_paymentss',
339
			'publish_give_paymentss',
340
			'read_private_give_paymentss',
341
		);
342
343
		global $wp_roles;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
344
		foreach ( $delete_caps as $cap ) {
345
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
346
				$wp_roles->remove_cap( $role, $cap );
347
			}
348
		}
349
350
		// Create Give plugin roles.
351
		$roles = new Give_Roles();
352
		$roles->add_roles();
353
		$roles->add_caps();
354
355
		// The Update Ran.
356
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
357
		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
358
		delete_option( 'give_doing_upgrade' );
359
360
	}// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
361
362
}
363
364
add_action( 'admin_init', 'give_v152_cleanup_users' );
365
366
/**
367
 * 1.6 Upgrade routine to create the customer meta table.
368
 *
369
 * @since  1.6
370
 * @return void
371
 */
372
function give_v16_upgrades() {
373
	// Create the donor databases.
374
	$donors_db = new Give_DB_Donors();
375
	$donors_db->create_table();
376
	$donor_meta = new Give_DB_Donor_Meta();
377
	$donor_meta->create_table();
378
}
379
380
/**
381
 * 1.7 Upgrades.
382
 *
383
 * a. Update license api data for plugin addons.
384
 * b. Cleanup user roles.
385
 *
386
 * @since  1.7
387
 * @return void
388
 */
389
function give_v17_upgrades() {
390
	// Upgrade license data.
391
	give_v17_upgrade_addon_license_data();
392
	give_v17_cleanup_roles();
393
}
394
395
/**
396
 * Upgrade license data
397
 *
398
 * @since 1.7
399
 */
400
function give_v17_upgrade_addon_license_data() {
401
	$give_options = give_get_settings();
402
403
	$api_url = 'https://givewp.com/give-sl-api/';
404
405
	// Get addons license key.
406
	$addons = array();
407
	foreach ( $give_options as $key => $value ) {
408
		if ( false !== strpos( $key, '_license_key' ) ) {
409
			$addons[ $key ] = $value;
410
		}
411
	}
412
413
	// Bailout: We do not have any addon license data to upgrade.
414
	if ( empty( $addons ) ) {
415
		return false;
416
	}
417
418
	foreach ( $addons as $key => $addon_license ) {
419
420
		// Get addon shortname.
421
		$shortname = str_replace( '_license_key', '', $key );
422
423
		// Addon license option name.
424
		$addon_license_option_name = $shortname . '_license_active';
425
426
		// bailout if license is empty.
427
		if ( empty( $addon_license ) ) {
428
			delete_option( $addon_license_option_name );
429
			continue;
430
		}
431
432
		// Get addon name.
433
		$addon_name       = array();
434
		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
435
		foreach ( $addon_name_parts as $name_part ) {
436
437
			// Fix addon name
438
			switch ( $name_part ) {
439
				case 'authorizenet' :
440
					$name_part = 'authorize.net';
441
					break;
442
			}
443
444
			$addon_name[] = ucfirst( $name_part );
445
		}
446
447
		$addon_name = implode( ' ', $addon_name );
448
449
		// Data to send to the API
450
		$api_params = array(
451
			'edd_action' => 'activate_license', // never change from "edd_" to "give_"!
452
			'license'    => $addon_license,
453
			'item_name'  => urlencode( $addon_name ),
454
			'url'        => home_url(),
455
		);
456
457
		// Call the API.
458
		$response = wp_remote_post(
459
			$api_url,
460
			array(
461
				'timeout'   => 15,
462
				'sslverify' => false,
463
				'body'      => $api_params,
464
			)
465
		);
466
467
		// Make sure there are no errors.
468
		if ( is_wp_error( $response ) ) {
469
			delete_option( $addon_license_option_name );
470
			continue;
471
		}
472
473
		// Tell WordPress to look for updates.
474
		set_site_transient( 'update_plugins', null );
475
476
		// Decode license data.
477
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
478
		update_option( $addon_license_option_name, $license_data );
479
	}// End foreach().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
480
}
481
482
483
/**
484
 * Cleanup User Roles.
485
 *
486
 * This upgrade routine removes unused roles and roles with typos.
487
 *
488
 * @since      1.7
489
 */
490
function give_v17_cleanup_roles() {
491
492
	// Delete all caps with "_give_forms_" and "_give_payments_"
493
	// These roles have no usage; the proper is singular.
494
	$delete_caps = array(
495
		'view_give_forms_stats',
496
		'delete_give_forms_terms',
497
		'assign_give_forms_terms',
498
		'edit_give_forms_terms',
499
		'manage_give_forms_terms',
500
		'view_give_payments_stats',
501
		'manage_give_payments_terms',
502
		'edit_give_payments_terms',
503
		'assign_give_payments_terms',
504
		'delete_give_payments_terms',
505
	);
506
507
	global $wp_roles;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
508
	foreach ( $delete_caps as $cap ) {
509
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
510
			$wp_roles->remove_cap( $role, $cap );
511
		}
512
	}
513
514
	// Set roles again.
515
	$roles = new Give_Roles();
516
	$roles->add_roles();
517
	$roles->add_caps();
518
519
}
520
521
/**
522
 * 1.8 Upgrades.
523
 *
524
 * a. Upgrade checkbox settings to radio button settings.
525
 * a. Update form meta for new metabox settings.
526
 *
527
 * @since  1.8
528
 * @return void
529
 */
530
function give_v18_upgrades() {
531
	// Upgrade checkbox settings to radio button settings.
532
	give_v18_upgrades_core_setting();
533
}
534
535
/**
536
 * Upgrade core settings.
537
 *
538
 * @since  1.8
539
 * @return void
540
 */
541
function give_v18_upgrades_core_setting() {
542
	// Core settings which changes from checkbox to radio.
543
	$core_setting_names = array_merge(
544
		array_keys( give_v18_renamed_core_settings() ),
545
		array(
546
			'uninstall_on_delete',
547
			'scripts_footer',
548
			'test_mode',
549
			'email_access',
550
			'terms',
551
			'give_offline_donation_enable_billing_fields',
552
		)
553
	);
554
555
	// Bailout: If not any setting define.
556
	if ( $give_settings = get_option( 'give_settings' ) ) {
557
558
		$setting_changed = false;
559
560
		// Loop: check each setting field.
561
		foreach ( $core_setting_names as $setting_name ) {
562
			// New setting name.
563
			$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name );
564
565
			// Continue: If setting already set.
566
			if (
567
				array_key_exists( $new_setting_name, $give_settings )
568
				&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) )
569
			) {
570
				continue;
571
			}
572
573
			// Set checkbox value to radio value.
574
			$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' );
575
576
			// @see https://github.com/WordImpress/Give/issues/1063
577
			if ( false !== strpos( $setting_name, 'disable_' ) ) {
578
579
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' );
580
			} elseif ( false !== strpos( $setting_name, 'enable_' ) ) {
581
582
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' );
583
			}
584
585
			// Tell bot to update core setting to db.
586
			if ( ! $setting_changed ) {
587
				$setting_changed = true;
588
			}
589
		}
590
591
		// Update setting only if they changed.
592
		if ( $setting_changed ) {
593
			update_option( 'give_settings', $give_settings );
594
		}
595
	}// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
596
597
	give_set_upgrade_complete( 'v18_upgrades_core_setting' );
598
}
599
600
/**
601
 * Upgrade form metadata for new metabox settings.
602
 *
603
 * @since  1.8
604
 * @return void
605
 */
606
function give_v18_upgrades_form_metadata() {
607
	if ( ! current_user_can( 'manage_give_settings' ) ) {
608
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
609
			'response' => 403,
610
		) );
611
	}
612
613
	ignore_user_abort( true );
614
615
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
616
		@set_time_limit( 0 );
617
	}
618
619
	$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
620
621
	// form query
622
	$forms = new WP_Query( array(
623
			'paged'          => $step,
624
			'status'         => 'any',
625
			'order'          => 'ASC',
626
			'post_type'      => 'give_forms',
627
			'posts_per_page' => 20,
628
		)
629
	);
630
631
	if ( $forms->have_posts() ) {
632
		while ( $forms->have_posts() ) {
633
			$forms->the_post();
634
635
			// Form content.
636
			// Note in version 1.8 display content setting split into display content and content placement setting.
637
			// You can delete _give_content_option in future
638
			$show_content = give_get_meta( get_the_ID(), '_give_content_option', true );
639
			if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) {
640
				$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' );
641
				give_update_meta( get_the_ID(), '_give_display_content', $field_value );
642
643
				$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' );
644
				give_update_meta( get_the_ID(), '_give_content_placement', $field_value );
645
			}
646
647
			// "Disable" Guest Donation. Checkbox
648
			// See: https://github.com/WordImpress/Give/issues/1470
649
			$guest_donation        = give_get_meta( get_the_ID(), '_give_logged_in_only', true );
650
			$guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' );
651
			give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval );
652
653
			// Offline Donations
654
			// See: https://github.com/WordImpress/Give/issues/1579
655
			$offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true );
656
			if ( 'no' === $offline_donation ) {
657
				$offline_donation_newval = 'global';
658
			} elseif ( 'yes' === $offline_donation ) {
659
				$offline_donation_newval = 'enabled';
660
			} else {
661
				$offline_donation_newval = 'disabled';
662
			}
663
			give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval );
664
665
			// Convert yes/no setting field to enabled/disabled.
666
			$form_radio_settings = array(
667
				// Custom Amount.
668
				'_give_custom_amount',
669
670
				// Donation Gaol.
671
				'_give_goal_option',
672
673
				// Close Form.
674
				'_give_close_form_when_goal_achieved',
675
676
				// Term & conditions.
677
				'_give_terms_option',
678
679
				// Billing fields.
680
				'_give_offline_donation_enable_billing_fields_single',
681
			);
682
683
			foreach ( $form_radio_settings as $meta_key ) {
684
				// Get value.
685
				$field_value = give_get_meta( get_the_ID(), $meta_key, true );
686
687
				// Convert meta value only if it is in yes/no/none.
688
				if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) {
689
690
					$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' );
691
					give_update_meta( get_the_ID(), $meta_key, $field_value );
692
				}
693
			}
694
		}// End while().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
695
696
		wp_reset_postdata();
697
698
		// Forms found so upgrade them
699
		$step ++;
700
		$redirect = add_query_arg( array(
701
			'page'         => 'give-upgrades',
702
			'give-upgrade' => 'give_v18_upgrades_form_metadata',
703
			'step'         => $step,
704
		), admin_url( 'index.php' ) );
705
		wp_redirect( $redirect );
706
		exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v18_upgrades_form_metadata() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
707
708
	} else {
709
		// No more forms found, finish up.
710
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
711
		delete_option( 'give_doing_upgrade' );
712
		give_set_upgrade_complete( 'v18_upgrades_form_metadata' );
713
714
		wp_redirect( admin_url() );
715
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v18_upgrades_form_metadata() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
716
	}
717
}
718
719
add_action( 'give_give_v18_upgrades_form_metadata', 'give_v18_upgrades_form_metadata' );
720
721
/**
722
 * Get list of core setting renamed in version 1.8.
723
 *
724
 * @since  1.8
725
 * @return array
726
 */
727
function give_v18_renamed_core_settings() {
728
	return array(
729
		'disable_paypal_verification' => 'paypal_verification',
730
		'disable_css'                 => 'css',
731
		'disable_welcome'             => 'welcome',
732
		'disable_forms_singular'      => 'forms_singular',
733
		'disable_forms_archives'      => 'forms_archives',
734
		'disable_forms_excerpt'       => 'forms_excerpt',
735
		'disable_form_featured_img'   => 'form_featured_img',
736
		'disable_form_sidebar'        => 'form_sidebar',
737
		'disable_admin_notices'       => 'admin_notices',
738
		'disable_the_content_filter'  => 'the_content_filter',
739
		'enable_floatlabels'          => 'floatlabels',
740
		'enable_categories'           => 'categories',
741
		'enable_tags'                 => 'tags',
742
	);
743
}
744
745
746
/**
747
 * Upgrade core settings.
748
 *
749
 * @since  1.8.7
750
 * @return void
751
 */
752
function give_v187_upgrades() {
753
	global $wpdb;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
754
755
	/**
756
	 * Upgrade 1: Remove stat and cache transients.
757
	 */
758
	$cached_options = $wpdb->get_col(
759
		$wpdb->prepare(
760
			"SELECT * FROM {$wpdb->options} where (option_name LIKE '%%%s%%' OR option_name LIKE '%%%s%%')",
761
			array(
762
				'_transient_give_stats_',
763
				'give_cache',
764
				'_transient_give_add_ons_feed',
765
				'_transient__give_ajax_works',
766
				'_transient_give_total_api_keys',
767
				'_transient_give_i18n_give_promo_hide',
768
				'_transient_give_contributors',
769
				'_transient_give_estimated_monthly_stats',
770
				'_transient_give_earnings_total',
771
				'_transient_give_i18n_give_',
772
				'_transient__give_installed',
773
				'_transient__give_activation_redirect',
774
				'_transient__give_hide_license_notices_shortly_',
775
				'give_income_total',
776
			)
777
		),
778
		1
779
	);
780
781
	// User related transients.
782
	$user_apikey_options = $wpdb->get_results(
783
		$wpdb->prepare(
784
			"SELECT user_id, meta_key
785
			FROM $wpdb->usermeta
786
			WHERE meta_value=%s",
787
			'give_user_public_key'
788
		),
789
		ARRAY_A
790
	);
791
792
	if ( ! empty( $user_apikey_options ) ) {
793
		foreach ( $user_apikey_options as $user ) {
794
			$cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] );
795
			$cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] );
796
			$cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] );
797
		}
798
	}
799
800
	if ( ! empty( $cached_options ) ) {
801
		foreach ( $cached_options as $option ) {
802
			switch ( true ) {
803
				case ( false !== strpos( $option, 'transient' ) ):
804
					$option = str_replace( '_transient_', '', $option );
805
					delete_transient( $option );
806
					break;
807
808
				default:
809
					delete_option( $option );
810
			}
811
		}
812
	}
813
}
814
815
816
/**
817
 * Update Capabilities for Give_Worker User Role.
818
 *
819
 * This upgrade routine will update access rights for Give_Worker User Role.
820
 *
821
 * @since      1.8.8
822
 */
823
function give_v188_upgrades() {
824
825
	global $wp_roles;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
826
827
	// Get the role object.
828
	$give_worker = get_role( 'give_worker' );
829
830
	// A list of capabilities to add for give workers.
831
	$caps_to_add = array(
832
		'edit_posts',
833
		'edit_pages',
834
	);
835
836
	foreach ( $caps_to_add as $cap ) {
837
		// Add the capability.
838
		$give_worker->add_cap( $cap );
839
	}
840
841
}
842
843
/**
844
 * Update Post meta for minimum and maximum amount for multi level donation forms
845
 *
846
 * This upgrade routine adds post meta for give_forms CPT for multi level donation form.
847
 *
848
 * @since      1.8.9
849
 */
850
function give_v189_upgrades_levels_post_meta_callback() {
851
852
	if ( ! current_user_can( 'manage_give_settings' ) ) {
853
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
854
			'response' => 403,
855
		) );
856
	}
857
858
	ignore_user_abort( true );
859
860
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
861
		@set_time_limit( 0 );
862
	}
863
864
	$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
865
866
	// form query
867
	$donation_forms = new WP_Query( array(
868
			'paged'          => $step,
869
			'status'         => 'any',
870
			'order'          => 'ASC',
871
			'post_type'      => 'give_forms',
872
			'posts_per_page' => 20,
873
		)
874
	);
875
876
	if ( $donation_forms->have_posts() ) {
877
		while ( $donation_forms->have_posts() ) {
878
			$donation_forms->the_post();
879
			$form_id = get_the_ID();
880
881
			// Remove formatting from _give_set_price
882
			update_post_meta(
883
				$form_id,
884
				'_give_set_price',
885
				give_sanitize_amount( get_post_meta( $form_id, '_give_set_price', true ) )
886
			);
887
888
			// Remove formatting from _give_custom_amount_minimum
889
			update_post_meta(
890
				$form_id,
891
				'_give_custom_amount_minimum',
892
				give_sanitize_amount( get_post_meta( $form_id, '_give_custom_amount_minimum', true ) )
893
			);
894
895
			// Bailout.
896
			if ( 'set' === get_post_meta( $form_id, '_give_price_option', true ) ) {
897
				continue;
898
			}
899
900
			$donation_levels = get_post_meta( $form_id, '_give_donation_levels', true );
901
902
			if ( ! empty( $donation_levels ) ) {
903
904
				foreach ( $donation_levels as $index => $donation_level ) {
905
					if ( isset( $donation_level['_give_amount'] ) ) {
906
						$donation_levels[ $index ]['_give_amount'] = give_sanitize_amount( $donation_level['_give_amount'] );
907
					}
908
				}
909
910
				update_post_meta( $form_id, '_give_donation_levels', $donation_levels );
911
912
				$donation_levels_amounts = wp_list_pluck( $donation_levels, '_give_amount' );
913
914
				$min_amount = min( $donation_levels_amounts );
915
				$max_amount = max( $donation_levels_amounts );
916
917
				// Set Minimum and Maximum amount for Multi Level Donation Forms
918
				give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount( $min_amount ) : 0 );
919
				give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount( $max_amount ) : 0 );
920
			}
921
922
		}
923
924
		/* Restore original Post Data */
925
		wp_reset_postdata();
926
927
		// Forms found so upgrade them
928
		$step ++;
929
		$redirect = add_query_arg( array(
930
			'page'         => 'give-upgrades',
931
			'give-upgrade' => 'v189_upgrades_levels_post_meta',
932
			'step'         => $step,
933
		), admin_url( 'index.php' ) );
934
		wp_redirect( $redirect );
935
		exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v189_upgrades_levels_post_meta_callback() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
936
	} else {
937
		// The Update Ran.
938
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
939
		give_set_upgrade_complete( 'v189_upgrades_levels_post_meta' );
940
		delete_option( 'give_doing_upgrade' );
941
942
		wp_redirect( admin_url() );
943
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v189_upgrades_levels_post_meta_callback() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
944
	}
945
946
}
947
948
949
/**
950
 * 2.0 Upgrades.
951
 *
952
 * @since  2.0
953
 * @return void
954
 */
955
function give_v20_upgrades() {
956
	// Upgrade email settings.
957
	give_v20_upgrades_email_setting();
958
}
959
960
/**
961
 * Move old email api settings to new email setting api for following emails:
962
 *    1. new offline donation         [This was hard coded]
963
 *    2. offline donation instruction
964
 *    3. new donation
965
 *    4. donation receipt
966
 *
967
 * @since 2.0
968
 */
969
function give_v20_upgrades_email_setting() {
970
	$all_setting = give_get_settings();
971
972
	// Bailout on fresh install.
973
	if ( empty( $all_setting ) ) {
974
		return;
975
	}
976
977
	$settings = array(
978
		'offline_donation_subject'      => 'offline-donation-instruction_email_subject',
979
		'global_offline_donation_email' => 'offline-donation-instruction_email_message',
980
		'donation_subject'              => 'donation-receipt_email_subject',
981
		'donation_receipt'              => 'donation-receipt_email_message',
982
		'donation_notification_subject' => 'new-donation_email_subject',
983
		'donation_notification'         => 'new-donation_email_message',
984
		'admin_notice_emails'           => array(
985
			'new-donation_recipient',
986
			'new-offline-donation_recipient',
987
			'new-donor-register_recipient',
988
		),
989
		'admin_notices'                 => 'new-donation_notification',
990
	);
991
992
	foreach ( $settings as $old_setting => $new_setting ) {
993
		// Do not update already modified
994
		if ( ! is_array( $new_setting ) ) {
995
			if ( array_key_exists( $new_setting, $all_setting ) || ! array_key_exists( $old_setting, $all_setting ) ) {
996
				continue;
997
			}
998
		}
999
1000
		switch ( $old_setting ) {
1001
			case 'admin_notices':
1002
				$notification_status = give_get_option( $old_setting, 'disabled' );
1003
1004
				give_update_option( $new_setting, $notification_status );
1005
				give_delete_option( $old_setting );
1006
				break;
1007
1008
			// @todo: Delete this option later ( version > 2.0 ) because we need this for backward compatibility give_get_admin_notice_emails.
1009
			case 'admin_notice_emails':
1010
				$recipients = give_get_admin_notice_emails();
0 ignored issues
show
Deprecated Code introduced by
The function give_get_admin_notice_emails() has been deprecated with message: 2.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1011
1012
				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...
1013
					// bailout if setting already exist.
1014
					if ( array_key_exists( $setting, $all_setting ) ) {
1015
						continue;
1016
					}
1017
1018
					give_update_option( $setting, $recipients );
1019
				}
1020
				break;
1021
1022
			default:
1023
				give_update_option( $new_setting, give_get_option( $old_setting ) );
1024
				give_delete_option( $old_setting );
1025
		}
1026
	}
1027
}
1028
1029
add_action( 'give_v189_upgrades_levels_post_meta', 'give_v189_upgrades_levels_post_meta_callback' );
1030
1031
1032
/**
1033
 * Upgrade form metadata for new metabox settings.
1034
 *
1035
 * @since  1.8
1036
 * @return void
1037
 */
1038
function give_v20_upgrades_form_metadata() {
1039
	if ( ! current_user_can( 'manage_give_settings' ) ) {
1040
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
1041
			'response' => 403,
1042
		) );
1043
	}
1044
1045
	ignore_user_abort( true );
1046
1047
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
1048
		@set_time_limit( 0 );
1049
	}
1050
1051
	$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
1052
1053
	// form query
1054
	$forms = new WP_Query( array(
1055
			'paged'          => $step,
1056
			'status'         => 'any',
1057
			'order'          => 'ASC',
1058
			'post_type'      => 'give_forms',
1059
			'posts_per_page' => 20,
1060
		)
1061
	);
1062
1063
	if ( $forms->have_posts() ) {
1064
		while ( $forms->have_posts() ) {
1065
			$forms->the_post();
1066
1067
			// Update offline instruction email notification status.
1068
			$offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true );
1069
			$offline_instruction_notification_status = give_is_setting_enabled( $offline_instruction_notification_status, array( 'enabled', 'global' ) )
1070
				? $offline_instruction_notification_status
1071
				: 'global';
1072
			update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status );
1073
1074
			// Update offline instruction email message.
1075
			update_post_meta(
1076
				get_the_ID(),
1077
				'_give_offline-donation-instruction_email_message',
1078
				get_post_meta(
1079
					get_the_ID(),
1080
					// @todo: Delete this option later ( version > 2.0 ).
1081
					'_give_offline_donation_email',
1082
					true
1083
				)
1084
			);
1085
1086
			// Update offline instruction email subject.
1087
			update_post_meta(
1088
				get_the_ID(),
1089
				'_give_offline-donation-instruction_email_subject',
1090
				get_post_meta(
1091
					get_the_ID(),
1092
					// @todo: Delete this option later ( version > 2.0 ).
1093
					'_give_offline_donation_subject',
1094
					true
1095
				)
1096
			);
1097
1098
			// @todo add db upgrade for _gove_payment_meta and other renamed mata keys.
1099
1100
1101
		}// End while().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1102
1103
		wp_reset_postdata();
1104
1105
		// Forms found so upgrade them
1106
		$step ++;
1107
		$redirect = add_query_arg( array(
1108
			'page'         => 'give-upgrades',
1109
			'give-upgrade' => 'give_v20_upgrades_form_metadata',
1110
			'step'         => $step,
1111
		), admin_url( 'index.php' ) );
1112
		wp_redirect( $redirect );
1113
		exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v20_upgrades_form_metadata() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1114
1115
	} else {
1116
		// No more forms found, finish up.
1117
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
1118
		delete_option( 'give_doing_upgrade' );
1119
		give_set_upgrade_complete( 'v20_upgrades_form_metadata' );
1120
1121
		wp_redirect( admin_url() );
1122
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_v20_upgrades_form_metadata() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1123
	}
1124
1125
	//  delete _give_payment_user_id now we are getting user id from donor id.
1126
}
1127
1128
add_action( 'give_give_v20_upgrades_form_metadata', 'give_v20_upgrades_form_metadata' );
1129