Completed
Push — issues/1132 ( 716ec5 )
by Ravinder
40:09 queued 19:53
created

upgrade-functions.php ➔ give_do_automatic_upgrades()   D

Complexity

Conditions 9
Paths 28

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 26
nc 28
nop 0
dl 0
loc 41
rs 4.909
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
	// v2.0 form metadata upgrades.
144
	if ( version_compare( $give_version, '2.0', '<' ) || ! give_has_upgrade_completed( 'v20_upgrades_form_metadata' ) ) {
145
		echo Give_Notices::notice_html(
146
			sprintf(
147
				esc_html__( 'Give needs to upgrade the form database, click %1$shere%2$s to start the upgrade.', 'give' ),
148
				'<a class="give-upgrade-link" href="' . esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=give_v20_upgrades_form_metadata' ) ) . '">',
149
				'</a>'
150
			)
151
		);
152
	}
153
154
	// End 'Stepped' upgrade process notices.
155
	?>
156
	<script>
157
		jQuery(document).ready(function($){
158
			var $upgrade_links = $('.give-upgrade-link');
159
			if( $upgrade_links.length ) {
160
				$upgrade_links.on( 'click', function(e){
161
					e.preventDefault();
162
163
					if( ! window.confirm( '<?php _e( 'Please make sure to create a database backup before initiating the upgrade.', 'give' ); ?>' ) ) {
164
						return;
165
					}
166
167
					// Redirect to upgrdae link.
168
					window.location.assign( $(this).attr('href') );
169
				});
170
			}
171
		});
172
	</script>
173
	<?php
174
}
175
176
add_action( 'admin_notices', 'give_show_upgrade_notices' );
177
178
/**
179
 * Triggers all upgrade functions
180
 *
181
 * This function is usually triggered via AJAX
182
 *
183
 * @since 1.0
184
 * @return void
185
 */
186
function give_trigger_upgrades() {
187
188
	if ( ! current_user_can( 'manage_give_settings' ) ) {
189
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
190
			'response' => 403,
191
		) );
192
	}
193
194
	$give_version = get_option( 'give_version' );
195
196
	if ( ! $give_version ) {
197
		// 1.0 is the first version to use this option so we must add it.
198
		$give_version = '1.0';
199
		add_option( 'give_version', $give_version );
200
	}
201
202
	update_option( 'give_version', GIVE_VERSION );
203
	delete_option( 'give_doing_upgrade' );
204
205
	if ( DOING_AJAX ) {
206
		die( 'complete' );
0 ignored issues
show
Coding Style Compatibility introduced by
The function give_trigger_upgrades() 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...
207
	} // 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...
208
}
209
210
add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' );
211
212
/**
213
 * Check if the upgrade routine has been run for a specific action
214
 *
215
 * @since  1.0
216
 *
217
 * @param  string $upgrade_action The upgrade action to check completion for
218
 *
219
 * @return bool                   If the action has been added to the completed actions array
220
 */
221
function give_has_upgrade_completed( $upgrade_action = '' ) {
222
223
	if ( empty( $upgrade_action ) ) {
224
		return false;
225
	}
226
227
	$completed_upgrades = give_get_completed_upgrades();
228
229
	return in_array( $upgrade_action, $completed_upgrades );
230
231
}
232
233
/**
234
 * For use when doing 'stepped' upgrade routines, to see if we need to start somewhere in the middle
235
 *
236
 * @since 1.8
237
 *
238
 * @return mixed   When nothing to resume returns false, otherwise starts the upgrade where it left off
239
 */
240
function give_maybe_resume_upgrade() {
241
	$doing_upgrade = get_option( 'give_doing_upgrade', false );
242
	if ( empty( $doing_upgrade ) ) {
243
		return false;
244
	}
245
246
	return $doing_upgrade;
247
}
248
249
/**
250
 * Adds an upgrade action to the completed upgrades array
251
 *
252
 * @since  1.0
253
 *
254
 * @param  string $upgrade_action The action to add to the completed upgrades array
255
 *
256
 * @return bool                   If the function was successfully added
257
 */
258
function give_set_upgrade_complete( $upgrade_action = '' ) {
259
260
	if ( empty( $upgrade_action ) ) {
261
		return false;
262
	}
263
264
	$completed_upgrades   = give_get_completed_upgrades();
265
	$completed_upgrades[] = $upgrade_action;
266
267
	// Remove any blanks, and only show uniques.
268
	$completed_upgrades = array_unique( array_values( $completed_upgrades ) );
269
270
	return update_option( 'give_completed_upgrades', $completed_upgrades );
271
}
272
273
/**
274
 * Get's the array of completed upgrade actions
275
 *
276
 * @since  1.0
277
 * @return array The array of completed upgrades
278
 */
279
function give_get_completed_upgrades() {
280
281
	$completed_upgrades = get_option( 'give_completed_upgrades' );
282
283
	if ( false === $completed_upgrades ) {
284
		$completed_upgrades = array();
285
	}
286
287
	return $completed_upgrades;
288
289
}
290
291
/**
292
 * Upgrades the
293
 *
294
 * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id`
295
 *
296
 * @since      1.3.2
297
 */
298
function give_v132_upgrade_give_payment_customer_id() {
299
	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...
300
	if ( ! current_user_can( 'manage_give_settings' ) ) {
301
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
302
			'response' => 403,
303
		) );
304
	}
305
306
	ignore_user_abort( true );
307
308
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
309
		@set_time_limit( 0 );
310
	}
311
312
	// UPDATE DB METAKEYS.
313
	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
314
	$query = $wpdb->query( $sql );
315
316
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
317
	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
318
	delete_option( 'give_doing_upgrade' );
319
	wp_redirect( admin_url() );
320
	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...
321
322
}
323
324
add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' );
325
326
/**
327
 * Upgrades the Offline Status
328
 *
329
 * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned
330
 *
331
 * @since      1.3.4
332
 */
333
function give_v134_upgrade_give_offline_status() {
334
335
	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...
336
337
	if ( ! current_user_can( 'manage_give_settings' ) ) {
338
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
339
			'response' => 403,
340
		) );
341
	}
342
343
	ignore_user_abort( true );
344
345
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
346
		@set_time_limit( 0 );
347
	}
348
349
	// Get abandoned offline payments.
350
	$select = "SELECT ID FROM $wpdb->posts p ";
351
	$join   = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
352
	$where  = "WHERE p.post_type = 'give_payment' ";
353
	$where .= "AND ( p.post_status = 'abandoned' )";
354
	$where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
355
356
	$sql            = $select . $join . $where;
357
	$found_payments = $wpdb->get_col( $sql );
358
359
	foreach ( $found_payments as $payment ) {
360
361
		// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves.
362
		$modified_time = get_post_modified_time( 'U', false, $payment );
363
364
		// 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...
365
		if ( $modified_time >= 1450124863 ) {
366
367
			give_update_payment_status( $payment, 'pending' );
368
369
		}
370
	}
371
372
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
373
	give_set_upgrade_complete( 'upgrade_give_offline_status' );
374
	delete_option( 'give_doing_upgrade' );
375
	wp_redirect( admin_url() );
376
	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...
377
378
}
379
380
add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' );
381
382
/**
383
 * Cleanup User Roles
384
 *
385
 * This upgrade routine removes unused roles and roles with typos
386
 *
387
 * @since      1.5.2
388
 */
389
function give_v152_cleanup_users() {
390
391
	$give_version = get_option( 'give_version' );
392
393
	if ( ! $give_version ) {
394
		// 1.0 is the first version to use this option so we must add it.
395
		$give_version = '1.0';
396
	}
397
398
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
399
400
	// v1.5.2 Upgrades
401
	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
402
403
		// Delete all caps with "ss".
404
		// Also delete all unused "campaign" roles.
405
		$delete_caps = array(
406
			'delete_give_formss',
407
			'delete_others_give_formss',
408
			'delete_private_give_formss',
409
			'delete_published_give_formss',
410
			'read_private_forms',
411
			'edit_give_formss',
412
			'edit_others_give_formss',
413
			'edit_private_give_formss',
414
			'edit_published_give_formss',
415
			'publish_give_formss',
416
			'read_private_give_formss',
417
			'assign_give_campaigns_terms',
418
			'delete_give_campaigns',
419
			'delete_give_campaigns_terms',
420
			'delete_give_campaignss',
421
			'delete_others_give_campaignss',
422
			'delete_private_give_campaignss',
423
			'delete_published_give_campaignss',
424
			'edit_give_campaigns',
425
			'edit_give_campaigns_terms',
426
			'edit_give_campaignss',
427
			'edit_others_give_campaignss',
428
			'edit_private_give_campaignss',
429
			'edit_published_give_campaignss',
430
			'manage_give_campaigns_terms',
431
			'publish_give_campaignss',
432
			'read_give_campaigns',
433
			'read_private_give_campaignss',
434
			'view_give_campaigns_stats',
435
			'delete_give_paymentss',
436
			'delete_others_give_paymentss',
437
			'delete_private_give_paymentss',
438
			'delete_published_give_paymentss',
439
			'edit_give_paymentss',
440
			'edit_others_give_paymentss',
441
			'edit_private_give_paymentss',
442
			'edit_published_give_paymentss',
443
			'publish_give_paymentss',
444
			'read_private_give_paymentss',
445
		);
446
447
		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...
448
		foreach ( $delete_caps as $cap ) {
449
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
450
				$wp_roles->remove_cap( $role, $cap );
451
			}
452
		}
453
454
		// Create Give plugin roles.
455
		$roles = new Give_Roles();
456
		$roles->add_roles();
457
		$roles->add_caps();
458
459
		// The Update Ran.
460
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
461
		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
462
		delete_option( 'give_doing_upgrade' );
463
464
	}// 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...
465
466
}
467
468
add_action( 'admin_init', 'give_v152_cleanup_users' );
469
470
/**
471
 * 1.6 Upgrade routine to create the customer meta table.
472
 *
473
 * @since  1.6
474
 * @return void
475
 */
476
function give_v16_upgrades() {
477
	@Give()->customers->create_table();
478
	@Give()->customer_meta->create_table();
479
}
480
481
/**
482
 * 1.7 Upgrades.
483
 *
484
 * a. Update license api data for plugin addons.
485
 * b. Cleanup user roles.
486
 *
487
 * @since  1.7
488
 * @return void
489
 */
490
function give_v17_upgrades() {
491
	// Upgrade license data.
492
	give_v17_upgrade_addon_license_data();
493
	give_v17_cleanup_roles();
494
}
495
496
/**
497
 * Upgrade license data
498
 *
499
 * @since 1.7
500
 */
501
function give_v17_upgrade_addon_license_data() {
502
	$give_options = give_get_settings();
503
504
	$api_url = 'https://givewp.com/give-sl-api/';
505
506
	// Get addons license key.
507
	$addons = array();
508
	foreach ( $give_options as $key => $value ) {
509
		if ( false !== strpos( $key, '_license_key' ) ) {
510
			$addons[ $key ] = $value;
511
		}
512
	}
513
514
	// Bailout: We do not have any addon license data to upgrade.
515
	if ( empty( $addons ) ) {
516
		return false;
517
	}
518
519
	foreach ( $addons as $key => $addon_license ) {
520
521
		// Get addon shortname.
522
		$shortname = str_replace( '_license_key', '', $key );
523
524
		// Addon license option name.
525
		$addon_license_option_name = $shortname . '_license_active';
526
527
		// bailout if license is empty.
528
		if ( empty( $addon_license ) ) {
529
			delete_option( $addon_license_option_name );
530
			continue;
531
		}
532
533
		// Get addon name.
534
		$addon_name       = array();
535
		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
536
		foreach ( $addon_name_parts as $name_part ) {
537
538
			// Fix addon name
539
			switch ( $name_part ) {
540
				case 'authorizenet' :
541
					$name_part = 'authorize.net';
542
					break;
543
			}
544
545
			$addon_name[] = ucfirst( $name_part );
546
		}
547
548
		$addon_name = implode( ' ', $addon_name );
549
550
		// Data to send to the API
551
		$api_params = array(
552
			'edd_action' => 'activate_license', // never change from "edd_" to "give_"!
553
			'license'    => $addon_license,
554
			'item_name'  => urlencode( $addon_name ),
555
			'url'        => home_url(),
556
		);
557
558
		// Call the API.
559
		$response = wp_remote_post(
560
			$api_url,
561
			array(
562
				'timeout'   => 15,
563
				'sslverify' => false,
564
				'body'      => $api_params,
565
			)
566
		);
567
568
		// Make sure there are no errors.
569
		if ( is_wp_error( $response ) ) {
570
			delete_option( $addon_license_option_name );
571
			continue;
572
		}
573
574
		// Tell WordPress to look for updates.
575
		set_site_transient( 'update_plugins', null );
576
577
		// Decode license data.
578
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
579
		update_option( $addon_license_option_name, $license_data );
580
	}// 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...
581
}
582
583
584
/**
585
 * Cleanup User Roles.
586
 *
587
 * This upgrade routine removes unused roles and roles with typos.
588
 *
589
 * @since      1.7
590
 */
591
function give_v17_cleanup_roles() {
592
593
	// Delete all caps with "_give_forms_" and "_give_payments_"
594
	// These roles have no usage; the proper is singular.
595
	$delete_caps = array(
596
		'view_give_forms_stats',
597
		'delete_give_forms_terms',
598
		'assign_give_forms_terms',
599
		'edit_give_forms_terms',
600
		'manage_give_forms_terms',
601
		'view_give_payments_stats',
602
		'manage_give_payments_terms',
603
		'edit_give_payments_terms',
604
		'assign_give_payments_terms',
605
		'delete_give_payments_terms',
606
	);
607
608
	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...
609
	foreach ( $delete_caps as $cap ) {
610
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
611
			$wp_roles->remove_cap( $role, $cap );
612
		}
613
	}
614
615
	// Set roles again.
616
	$roles = new Give_Roles();
617
	$roles->add_roles();
618
	$roles->add_caps();
619
620
}
621
622
/**
623
 * 1.8 Upgrades.
624
 *
625
 * a. Upgrade checkbox settings to radio button settings.
626
 * a. Update form meta for new metabox settings.
627
 *
628
 * @since  1.8
629
 * @return void
630
 */
631
function give_v18_upgrades() {
632
	// Upgrade checkbox settings to radio button settings.
633
	give_v18_upgrades_core_setting();
634
}
635
636
/**
637
 * Upgrade core settings.
638
 *
639
 * @since  1.8
640
 * @return void
641
 */
642
function give_v18_upgrades_core_setting() {
643
	// Core settings which changes from checkbox to radio.
644
	$core_setting_names = array_merge(
645
		array_keys( give_v18_renamed_core_settings() ),
646
		array(
647
			'uninstall_on_delete',
648
			'scripts_footer',
649
			'test_mode',
650
			'email_access',
651
			'terms',
652
			'give_offline_donation_enable_billing_fields',
653
		)
654
	);
655
656
	// Bailout: If not any setting define.
657
	if ( $give_settings = get_option( 'give_settings' ) ) {
658
659
		$setting_changed = false;
660
661
		// Loop: check each setting field.
662
		foreach ( $core_setting_names as $setting_name ) {
663
			// New setting name.
664
			$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name );
665
666
			// Continue: If setting already set.
667
			if (
668
				array_key_exists( $new_setting_name, $give_settings )
669
				&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) )
670
			) {
671
				continue;
672
			}
673
674
			// Set checkbox value to radio value.
675
			$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' );
676
677
			// @see https://github.com/WordImpress/Give/issues/1063
678
			if ( false !== strpos( $setting_name, 'disable_' ) ) {
679
680
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' );
681
			} elseif ( false !== strpos( $setting_name, 'enable_' ) ) {
682
683
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' );
684
			}
685
686
			// Tell bot to update core setting to db.
687
			if ( ! $setting_changed ) {
688
				$setting_changed = true;
689
			}
690
		}
691
692
		// Update setting only if they changed.
693
		if ( $setting_changed ) {
694
			update_option( 'give_settings', $give_settings );
695
		}
696
	}// 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...
697
698
	give_set_upgrade_complete( 'v18_upgrades_core_setting' );
699
}
700
701
/**
702
 * Upgrade form metadata for new metabox settings.
703
 *
704
 * @since  1.8
705
 * @return void
706
 */
707
function give_v18_upgrades_form_metadata() {
708
	if ( ! current_user_can( 'manage_give_settings' ) ) {
709
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
710
			'response' => 403,
711
		) );
712
	}
713
714
	ignore_user_abort( true );
715
716
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
717
		@set_time_limit( 0 );
718
	}
719
720
	$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
721
722
	// form query
723
	$forms = new WP_Query( array(
724
			'paged'          => $step,
725
			'status'         => 'any',
726
			'order'          => 'ASC',
727
			'post_type'      => 'give_forms',
728
			'posts_per_page' => 20,
729
		)
730
	);
731
732
	if ( $forms->have_posts() ) {
733
		while ( $forms->have_posts() ) {
734
			$forms->the_post();
735
736
			// Form content.
737
			// Note in version 1.8 display content setting split into display content and content placement setting.
738
			// You can delete _give_content_option in future
739
			$show_content = give_get_meta( get_the_ID(), '_give_content_option', true );
740
			if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) {
741
				$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' );
742
				give_update_meta( get_the_ID(), '_give_display_content', $field_value );
743
744
				$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' );
745
				give_update_meta( get_the_ID(), '_give_content_placement', $field_value );
746
			}
747
748
			// "Disable" Guest Donation. Checkbox
749
			// See: https://github.com/WordImpress/Give/issues/1470
750
			$guest_donation = give_get_meta( get_the_ID(), '_give_logged_in_only', true );
751
			$guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' );
752
			give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval );
753
754
			// Offline Donations
755
			// See: https://github.com/WordImpress/Give/issues/1579
756
			$offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true );
757
			if ( 'no' === $offline_donation ) {
758
				$offline_donation_newval = 'global';
759
			} elseif ( 'yes' === $offline_donation ) {
760
				$offline_donation_newval = 'enabled';
761
			} else {
762
				$offline_donation_newval = 'disabled';
763
			}
764
			give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval );
765
766
			// Convert yes/no setting field to enabled/disabled.
767
			$form_radio_settings = array(
768
				// Custom Amount.
769
				'_give_custom_amount',
770
771
				// Donation Gaol.
772
				'_give_goal_option',
773
774
				// Close Form.
775
				'_give_close_form_when_goal_achieved',
776
777
				// Term & conditions.
778
				'_give_terms_option',
779
780
				// Billing fields.
781
				'_give_offline_donation_enable_billing_fields_single',
782
			);
783
784
			foreach ( $form_radio_settings as $meta_key ) {
785
				// Get value.
786
				$field_value = give_get_meta( get_the_ID(), $meta_key, true );
787
788
				// Convert meta value only if it is in yes/no/none.
789
				if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) {
790
791
					$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' );
792
					give_update_meta( get_the_ID(), $meta_key, $field_value );
793
				}
794
			}
795
		}// 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...
796
797
		wp_reset_postdata();
798
799
		// Forms found so upgrade them
800
		$step ++;
801
		$redirect = add_query_arg( array(
802
			'page'         => 'give-upgrades',
803
			'give-upgrade' => 'give_v18_upgrades_form_metadata',
804
			'step'         => $step,
805
		), admin_url( 'index.php' ) );
806
		wp_redirect( $redirect );
807
		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...
808
809
	} else {
810
		// No more forms found, finish up.
811
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
812
		delete_option( 'give_doing_upgrade' );
813
		give_set_upgrade_complete( 'v18_upgrades_form_metadata' );
814
815
		wp_redirect( admin_url() );
816
		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...
817
	}
818
}
819
820
add_action( 'give_give_v18_upgrades_form_metadata', 'give_v18_upgrades_form_metadata' );
821
822
/**
823
 * Get list of core setting renamed in version 1.8.
824
 *
825
 * @since  1.8
826
 * @return array
827
 */
828
function give_v18_renamed_core_settings() {
829
	return array(
830
		'disable_paypal_verification' => 'paypal_verification',
831
		'disable_css'                 => 'css',
832
		'disable_welcome'             => 'welcome',
833
		'disable_forms_singular'      => 'forms_singular',
834
		'disable_forms_archives'      => 'forms_archives',
835
		'disable_forms_excerpt'       => 'forms_excerpt',
836
		'disable_form_featured_img'   => 'form_featured_img',
837
		'disable_form_sidebar'        => 'form_sidebar',
838
		'disable_admin_notices'       => 'admin_notices',
839
		'disable_the_content_filter'  => 'the_content_filter',
840
		'enable_floatlabels'          => 'floatlabels',
841
		'enable_categories'           => 'categories',
842
		'enable_tags'                 => 'tags',
843
	);
844
}
845
846
847
/**
848
 * Upgrade core settings.
849
 *
850
 * @since  1.8.7
851
 * @return void
852
 */
853
function give_v187_upgrades(){
854
	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...
855
856
	/**
857
	 * Upgrade 1: Remove stat and cache transients.
858
	 */
859
	$cached_options = $wpdb->get_col(
860
		$wpdb->prepare(
861
			"SELECT * FROM {$wpdb->options} where (option_name LIKE '%%%s%%' OR option_name LIKE '%%%s%%')",
862
			array(
863
				'_transient_give_stats_',
864
				'give_cache',
865
				'_transient_give_add_ons_feed',
866
				'_transient__give_ajax_works'.
867
				'_transient_give_total_api_keys',
868
				'_transient_give_i18n_give_promo_hide',
869
				'_transient_give_contributors',
870
				'_transient_give_estimated_monthly_stats',
871
				'_transient_give_earnings_total',
872
				'_transient_give_i18n_give_',
873
				'_transient__give_installed',
874
				'_transient__give_activation_redirect',
875
				'_transient__give_hide_license_notices_shortly_',
876
				'give_income_total'
877
			)
878
		),
879
		1
880
	);
881
882
	// User related transients.
883
	$user_apikey_options = $wpdb->get_results(
884
		$wpdb->prepare(
885
			"SELECT user_id, meta_key
886
			FROM $wpdb->usermeta
887
			WHERE meta_value=%s",
888
			'give_user_public_key'
889
		),
890
		ARRAY_A
891
	);
892
893
	if( ! empty( $user_apikey_options ) ) {
894
		foreach ( $user_apikey_options as $user ) {
895
			$cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] );
896
			$cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] );
897
			$cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] );
898
		}
899
	}
900
901
	if ( ! empty( $cached_options ) ) {
902
		foreach ( $cached_options as $option ) {
903
			switch ( true ) {
904
				case ( false !== strpos( $option, 'transient' ) ):
905
					$option = str_replace( '_transient_', '', $option );
906
					delete_transient( $option );
907
					break;
908
909
				default:
910
					delete_option( $option );
911
			}
912
		}
913
	}
914
}
915
916
917
/** 
918
 * Update Capabilities for Give_Worker User Role.
919
 *
920
 * This upgrade routine will update access rights for Give_Worker User Role.
921
 *
922
 * @since      1.8.8
923
 */
924
function give_v188_upgrades() {
925
926
	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...
927
928
    // Get the role object.
929
    $give_worker = get_role( 'give_worker' );
930
931
	// A list of capabilities to add for give workers.
932
    $caps_to_add = array(
933
        'edit_posts',
934
        'edit_pages'
935
    );
936
937
    foreach ( $caps_to_add as $cap ) {
938
        // Add the capability.
939
        $give_worker->add_cap( $cap );
940
    }
941
942
}
943
944
945
/**
946
 * 2.0 Upgrades.
947
 *
948
 * @since  2.0
949
 * @return void
950
 */
951
function give_v20_upgrades() {
952
	// Upgrade email settings.
953
	give_v20_upgrades_email_setting();
954
}
955
956
/**
957
 * Move old email api settings to new email setting api for following emails:
958
 *    1. new offline donation         [This was hard coded]
959
 *    2. offline donation instruction
960
 *    3. new donation
961
 *    4. donation receipt
962
 *
963
 * @since 2.0
964
 */
965
function give_v20_upgrades_email_setting() {
966
	$all_setting = give_get_settings();
967
968
	// Bailout on fresh install.
969
	if( empty( $all_setting ) ) {
970
		return;
971
	}
972
973
	$settings    = array(
974
		'offline_donation_subject'      => 'offline-donation-instruction_email_subject',
975
		'global_offline_donation_email' => 'offline-donation-instruction_email_message',
976
		'donation_subject'              => 'donation-receipt_email_subject',
977
		'donation_receipt'              => 'donation-receipt_email_message',
978
		'donation_notification_subject' => 'new-donation_email_subject',
979
		'donation_notification'         => 'new-donation_email_message',
980
		'admin_notice_emails'           => array(
981
			'new-donation_recipient',
982
			'new-offline-donation_recipient',
983
			'new-donor-register_recipient',
984
		),
985
		'admin_notices'                 => 'new-donation_notification',
986
	);
987
988
	foreach ( $settings as $old_setting => $new_setting ) {
989
		// Do not update already modified
990
		if( ! is_array( $new_setting ) ) {
991
			if ( array_key_exists( $new_setting, $all_setting ) || ! array_key_exists( $old_setting, $all_setting ) ) {
992
				continue;
993
			}
994
		}
995
996
		switch ( $old_setting ) {
997
			case 'admin_notices':
998
				$notification_status = give_get_option( $old_setting, 'disabled' );
999
1000
				give_update_option( $new_setting, $notification_status );
1001
				give_delete_option( $old_setting );
1002
				break;
1003
1004
			// @todo: Delete this option later ( version > 2.0 ) because we need this for backward compatibility give_get_admin_notice_emails.
1005
			case 'admin_notice_emails':
1006
				$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...
1007
1008
				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...
1009
					// bailout if setting already exist.
1010
					if( array_key_exists( $setting, $all_setting ) ) {
1011
						continue;
1012
					}
1013
1014
					give_update_option( $setting, $recipients );
1015
				}
1016
				break;
1017
1018
			default:
1019
				give_update_option( $new_setting, give_get_option( $old_setting ) );
1020
				give_delete_option( $old_setting );
1021
		}
1022
	}
1023
}
1024
1025
1026
/**
1027
 * Upgrade form metadata for new metabox settings.
1028
 *
1029
 * @since  1.8
1030
 * @return void
1031
 */
1032
function give_v20_upgrades_form_metadata() {
1033
	if ( ! current_user_can( 'manage_give_settings' ) ) {
1034
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array(
1035
			'response' => 403,
1036
		) );
1037
	}
1038
1039
	ignore_user_abort( true );
1040
1041
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
1042
		@set_time_limit( 0 );
1043
	}
1044
1045
	$step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1;
1046
1047
	// form query
1048
	$forms = new WP_Query( array(
1049
			'paged'          => $step,
1050
			'status'         => 'any',
1051
			'order'          => 'ASC',
1052
			'post_type'      => 'give_forms',
1053
			'posts_per_page' => 20,
1054
		)
1055
	);
1056
1057
	if ( $forms->have_posts() ) {
1058
		while ( $forms->have_posts() ) {
1059
			$forms->the_post();
1060
1061
			// Update offline instruction email notification status.
1062
			$offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true );
1063
			$offline_instruction_notification_status = give_is_setting_enabled( $offline_instruction_notification_status, array( 'enabled', 'global' ) )
1064
				? $offline_instruction_notification_status
1065
				: 'global';
1066
			update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status );
1067
1068
			// Update offline instruction email message.
1069
			update_post_meta(
1070
				get_the_ID(),
1071
				'_give_offline-donation-instruction_email_message',
1072
				get_post_meta(
1073
					get_the_ID(),
1074
					// @todo: Delete this option later ( version > 2.0 ).
1075
					'_give_offline_donation_email',
1076
					true
1077
				)
1078
			);
1079
1080
			// Update offline instruction email subject.
1081
			update_post_meta(
1082
				get_the_ID(),
1083
				'_give_offline-donation-instruction_email_subject',
1084
				get_post_meta(
1085
					get_the_ID(),
1086
					// @todo: Delete this option later ( version > 2.0 ).
1087
					'_give_offline_donation_subject',
1088
					true
1089
				)
1090
			);
1091
1092
1093
		}// 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...
1094
1095
		wp_reset_postdata();
1096
1097
		// Forms found so upgrade them
1098
		$step ++;
1099
		$redirect = add_query_arg( array(
1100
			'page'         => 'give-upgrades',
1101
			'give-upgrade' => 'give_v20_upgrades_form_metadata',
1102
			'step'         => $step,
1103
		), admin_url( 'index.php' ) );
1104
		wp_redirect( $redirect );
1105
		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...
1106
1107
	} else {
1108
		// No more forms found, finish up.
1109
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
1110
		delete_option( 'give_doing_upgrade' );
1111
		give_set_upgrade_complete( 'v20_upgrades_form_metadata' );
1112
1113
		wp_redirect( admin_url() );
1114
		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...
1115
	}
1116
}
1117
1118
add_action( 'give_give_v20_upgrades_form_metadata', 'give_v20_upgrades_form_metadata' );