Completed
Push — release/1.8 ( ab8974...e4004b )
by Ravinder
41:06 queued 21:04
created

  A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
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
50
	if ( $did_upgrade ) {
51
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
52
	}
53
}
54
55
add_action( 'admin_init', 'give_do_automatic_upgrades' );
56
57
/**
58
 * Display Upgrade Notices
59
 *
60
 * @since 1.0
61
 * @return void
62
 */
63
function give_show_upgrade_notices() {
64
	// Don't show notices on the upgrades page.
65
	if ( isset( $_GET['page'] ) && $_GET['page'] == 'give-upgrades' ) {
66
		return;
67
	}
68
69
	$give_version = get_option( 'give_version' );
70
71
	if ( ! $give_version ) {
72
		// 1.0 is the first version to use this option so we must add it.
73
		$give_version = '1.0';
74
	}
75
76
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
77
78
	/*
79
	 *  NOTICE:
80
	 *
81
	 *  When adding new upgrade notices, please be sure to put the action into the upgrades array during install:
82
	 *  /includes/install.php @ Appox Line 156
83
	 *
84
	 */
85
86
	// v1.3.2 Upgrades
87
	if ( version_compare( $give_version, '1.3.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_payment_customer_id' ) ) {
88
		printf(
89
		/* translators: %s: upgrade URL */
90
			'<div class="updated"><p>' . __( 'Give needs to upgrade the donor database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
91
			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_payment_customer_id' ) )
92
		);
93
	}
94
95
	// v1.3.4 Upgrades //ensure the user has gone through 1.3.4.
96
	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' ) ) ) {
97
		printf(
98
		/* translators: %s: upgrade URL */
99
			'<div class="updated"><p>' . __( 'Give needs to upgrade the donations database, click <a href="%s">here</a> to start the upgrade.', 'give' ) . '</p></div>',
100
			esc_url( admin_url( 'index.php?page=give-upgrades&give-upgrade=upgrade_give_offline_status' ) )
101
		);
102
	}
103
104
	// End 'Stepped' upgrade process notices.
105
}
106
107
add_action( 'admin_notices', 'give_show_upgrade_notices' );
108
109
/**
110
 * Triggers all upgrade functions
111
 *
112
 * This function is usually triggered via AJAX
113
 *
114
 * @since 1.0
115
 * @return void
116
 */
117
function give_trigger_upgrades() {
118
119
	if ( ! current_user_can( 'manage_give_settings' ) ) {
120
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
121
	}
122
123
	$give_version = get_option( 'give_version' );
124
125
	if ( ! $give_version ) {
126
		// 1.0 is the first version to use this option so we must add it.
127
		$give_version = '1.0';
128
		add_option( 'give_version', $give_version );
129
	}
130
131
	update_option( 'give_version', GIVE_VERSION );
132
133
	if ( DOING_AJAX ) {
134
		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...
135
	} // Let AJAX know that the upgrade is complete.
136
}
137
138
add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' );
139
140
/**
141
 * Upgrades the
142
 *
143
 * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id`
144
 *
145
 * @since      1.3.2
146
 */
147
function give_v132_upgrade_give_payment_customer_id() {
148
	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...
149
	if ( ! current_user_can( 'manage_give_settings' ) ) {
150
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
151
	}
152
153
	ignore_user_abort( true );
154
155
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
156
		@set_time_limit( 0 );
157
	}
158
159
	// UPDATE DB METAKEYS.
160
	$sql   = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'";
161
	$query = $wpdb->query( $sql );
162
163
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
164
	give_set_upgrade_complete( 'upgrade_give_payment_customer_id' );
165
	delete_option( 'give_doing_upgrade' );
166
	wp_redirect( admin_url() );
167
	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...
168
169
}
170
171
add_action( 'give_upgrade_give_payment_customer_id', 'give_v132_upgrade_give_payment_customer_id' );
172
173
/**
174
 * Upgrades the Offline Status
175
 *
176
 * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned
177
 *
178
 * @since      1.3.4
179
 */
180
function give_v134_upgrade_give_offline_status() {
181
182
	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...
183
184
	if ( ! current_user_can( 'manage_give_settings' ) ) {
185
		wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
186
	}
187
188
	ignore_user_abort( true );
189
190
	if ( ! give_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
191
		@set_time_limit( 0 );
192
	}
193
194
	// Get abandoned offline payments.
195
	$select = "SELECT ID FROM $wpdb->posts p ";
196
	$join   = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id ";
197
	$where  = "WHERE p.post_type = 'give_payment' ";
198
	$where .= "AND ( p.post_status = 'abandoned' )";
199
	$where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )";
200
201
	$sql            = $select . $join . $where;
202
	$found_payments = $wpdb->get_col( $sql );
203
204
	foreach ( $found_payments as $payment ) {
205
206
		// Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves.
207
		$modified_time = get_post_modified_time( 'U', false, $payment );
208
209
		// 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...
210
		if ( $modified_time >= 1450124863 ) {
211
212
			give_update_payment_status( $payment, 'pending' );
213
214
		}
215
	}
216
217
	update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
218
	give_set_upgrade_complete( 'upgrade_give_offline_status' );
219
	delete_option( 'give_doing_upgrade' );
220
	wp_redirect( admin_url() );
221
	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...
222
223
}
224
225
add_action( 'give_upgrade_give_offline_status', 'give_v134_upgrade_give_offline_status' );
226
227
/**
228
 * Cleanup User Roles
229
 *
230
 * This upgrade routine removes unused roles and roles with typos
231
 *
232
 * @since      1.5.2
233
 */
234
function give_v152_cleanup_users() {
235
236
	$give_version = get_option( 'give_version' );
237
238
	if ( ! $give_version ) {
239
		// 1.0 is the first version to use this option so we must add it.
240
		$give_version = '1.0';
241
	}
242
243
	$give_version = preg_replace( '/[^0-9.].*/', '', $give_version );
244
245
	// v1.5.2 Upgrades
246
	if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) {
247
248
		// Delete all caps with "ss".
249
		// Also delete all unused "campaign" roles.
250
		$delete_caps = array(
251
			'delete_give_formss',
252
			'delete_others_give_formss',
253
			'delete_private_give_formss',
254
			'delete_published_give_formss',
255
			'read_private_forms',
256
			'edit_give_formss',
257
			'edit_others_give_formss',
258
			'edit_private_give_formss',
259
			'edit_published_give_formss',
260
			'publish_give_formss',
261
			'read_private_give_formss',
262
			'assign_give_campaigns_terms',
263
			'delete_give_campaigns',
264
			'delete_give_campaigns_terms',
265
			'delete_give_campaignss',
266
			'delete_others_give_campaignss',
267
			'delete_private_give_campaignss',
268
			'delete_published_give_campaignss',
269
			'edit_give_campaigns',
270
			'edit_give_campaigns_terms',
271
			'edit_give_campaignss',
272
			'edit_others_give_campaignss',
273
			'edit_private_give_campaignss',
274
			'edit_published_give_campaignss',
275
			'manage_give_campaigns_terms',
276
			'publish_give_campaignss',
277
			'read_give_campaigns',
278
			'read_private_give_campaignss',
279
			'view_give_campaigns_stats',
280
			'delete_give_paymentss',
281
			'delete_others_give_paymentss',
282
			'delete_private_give_paymentss',
283
			'delete_published_give_paymentss',
284
			'edit_give_paymentss',
285
			'edit_others_give_paymentss',
286
			'edit_private_give_paymentss',
287
			'edit_published_give_paymentss',
288
			'publish_give_paymentss',
289
			'read_private_give_paymentss',
290
		);
291
292
		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...
293
		foreach ( $delete_caps as $cap ) {
294
			foreach ( array_keys( $wp_roles->roles ) as $role ) {
295
				$wp_roles->remove_cap( $role, $cap );
296
			}
297
		}
298
299
		// Create Give plugin roles.
300
		$roles = new Give_Roles();
301
		$roles->add_roles();
302
		$roles->add_caps();
303
304
		// The Update Ran.
305
		update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) );
306
		give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' );
307
		delete_option( 'give_doing_upgrade' );
308
309
	}
310
311
}
312
313
add_action( 'admin_init', 'give_v152_cleanup_users' );
314
315
/**
316
 * 1.6 Upgrade routine to create the customer meta table.
317
 *
318
 * @since  1.6
319
 * @return void
320
 */
321
function give_v16_upgrades() {
322
	@Give()->customers->create_table();
323
	@Give()->customer_meta->create_table();
324
}
325
326
/**
327
 * 1.7 Upgrades.
328
 *
329
 * a. Update license api data for plugin addons.
330
 * b. Cleanup user roles.
331
 *
332
 * @since  1.7
333
 * @return void
334
 */
335
function give_v17_upgrades() {
336
	// Upgrade license data.
337
	give_v17_upgrade_addon_license_data();
338
	give_v17_cleanup_roles();
339
}
340
341
/**
342
 * Upgrade license data
343
 *
344
 * @since 1.7
345
 */
346
function give_v17_upgrade_addon_license_data() {
347
	$give_options = give_get_settings();
348
349
	$api_url = 'https://givewp.com/give-sl-api/';
350
351
	// Get addons license key.
352
	$addons = array();
353
	foreach ( $give_options as $key => $value ) {
354
		if ( false !== strpos( $key, '_license_key' ) ) {
355
			$addons[ $key ] = $value;
356
		}
357
	}
358
359
	// Bailout: We do not have any addon license data to upgrade.
360
	if ( empty( $addons ) ) {
361
		return false;
362
	}
363
364
	foreach ( $addons as $key => $addon_license ) {
365
366
		// Get addon shortname.
367
		$shortname = str_replace( '_license_key', '', $key );
368
369
		// Addon license option name.
370
		$addon_license_option_name = $shortname . '_license_active';
371
372
		// bailout if license is empty.
373
		if ( empty( $addon_license ) ) {
374
			delete_option( $addon_license_option_name );
375
			continue;
376
		}
377
378
		// Get addon name.
379
		$addon_name       = array();
380
		$addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) );
381
		foreach ( $addon_name_parts as $name_part ) {
382
383
			// Fix addon name
384
			switch ( $name_part ) {
385
				case 'authorizenet' :
386
					$name_part = 'authorize.net';
387
					break;
388
			}
389
390
			$addon_name[] = ucfirst( $name_part );
391
		}
392
393
		$addon_name = implode( ' ', $addon_name );
394
395
		// Data to send to the API
396
		$api_params = array(
397
			'edd_action' => 'activate_license', //never change from "edd_" to "give_"!
398
			'license'    => $addon_license,
399
			'item_name'  => urlencode( $addon_name ),
400
			'url'        => home_url()
401
		);
402
403
		// Call the API.
404
		$response = wp_remote_post(
405
			$api_url,
406
			array(
407
				'timeout'   => 15,
408
				'sslverify' => false,
409
				'body'      => $api_params
410
			)
411
		);
412
413
		// Make sure there are no errors.
414
		if ( is_wp_error( $response ) ) {
415
			delete_option( $addon_license_option_name );
416
			continue;
417
		}
418
419
		// Tell WordPress to look for updates.
420
		set_site_transient( 'update_plugins', null );
421
422
		// Decode license data.
423
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
424
		update_option( $addon_license_option_name, $license_data );
425
	}
426
}
427
428
429
/**
430
 * Cleanup User Roles.
431
 *
432
 * This upgrade routine removes unused roles and roles with typos.
433
 *
434
 * @since      1.7
435
 */
436
function give_v17_cleanup_roles() {
437
438
	//Delete all caps with "_give_forms_" and "_give_payments_"
439
	//These roles have no usage; the proper is singular.
440
	$delete_caps = array(
441
		'view_give_forms_stats',
442
		'delete_give_forms_terms',
443
		'assign_give_forms_terms',
444
		'edit_give_forms_terms',
445
		'manage_give_forms_terms',
446
		'view_give_payments_stats',
447
		'manage_give_payments_terms',
448
		'edit_give_payments_terms',
449
		'assign_give_payments_terms',
450
		'delete_give_payments_terms',
451
	);
452
453
	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...
454
	foreach ( $delete_caps as $cap ) {
455
		foreach ( array_keys( $wp_roles->roles ) as $role ) {
456
			$wp_roles->remove_cap( $role, $cap );
457
		}
458
	}
459
460
	//Set roles again.
461
	$roles = new Give_Roles();
462
	$roles->add_roles();
463
	$roles->add_caps();
464
465
}
466
467
/**
468
 * 1.8 Upgrades.
469
 *
470
 * a. Upgrade checkbox settings to radio button settings..
471
 * a. Update form meta for new metabox settings.
472
 *
473
 * @since  1.8
474
 * @return void
475
 */
476
function give_v18_upgrades() {
477
	// Upgrade checkbox settings to radio button settings.
478
	give_v18_upgrades_core_setting();
479
	// Upgrade form metadata.
480
	give_v18_upgrades_form_metadata();
481
}
482
483
/**
484
 * Upgrade core settings.
485
 *
486
 * @since  1.8
487
 * @return void
488
 */
489
function give_v18_upgrades_core_setting() {
490
	// Core settings which changes from checkbox to radio.
491
	$core_setting_names = array_merge(
492
		array_keys( give_v18_renamed_core_settings() ),
493
		array(
494
			'uninstall_on_delete',
495
			'scripts_footer',
496
			'test_mode',
497
			'email_access',
498
			'terms',
499
			'give_offline_donation_enable_billing_fields',
500
		)
501
	);
502
503
	// Bailout: If not any setting define.
504
	if ( $give_settings = get_option( 'give_settings' ) ) {
505
506
		$setting_changed = false;
507
508
		// Loop: check each setting field.
509
		foreach ( $core_setting_names as $setting_name ) {
510
			// New setting name.
511
			$new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name );
512
513
			// Continue: If setting already set.
514
			if (
515
				array_key_exists( $new_setting_name, $give_settings )
516
				&& in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) )
517
			) {
518
				continue;
519
			}
520
521
			// Set checkbox value to radio value.
522
			$give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' );
523
524
			// @see https://github.com/WordImpress/Give/issues/1063
525
			if ( false !== strpos( $setting_name, 'disable_' ) ) {
526
527
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' );
528
			} elseif ( false !== strpos( $setting_name, 'enable_' ) ) {
529
530
				$give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enable' : 'disabled' );
531
			}
532
533
			// Tell bot to update core setting to db.
534
			if ( ! $setting_changed ) {
535
				$setting_changed = true;
536
			}
537
		}
538
539
		// Update setting only if they changed.
540
		if ( $setting_changed ) {
541
			update_option( 'give_settings', $give_settings );
542
		}
543
	}
544
545
	give_set_upgrade_complete( 'v18_upgrades_core_setting' );
546
}
547
548
/**
549
 * Upgrade form metadata for new metabox settings.
550
 *
551
 * @since  1.8
552
 * @return void
553
 */
554
function give_v18_upgrades_form_metadata() {
555
	$forms = new WP_Query( array(
556
			'post_type'      => 'give_forms',
557
			'posts_per_page' => - 1,
558
		)
559
	);
560
561
	if ( $forms->have_posts() ) {
562
		while ( $forms->have_posts() ) {
563
			$forms->the_post();
564
565
			// Form content.
566
			// Note in version 1.8 display content setting split into display content and content placement setting.
567
			$show_content = get_post_meta( get_the_ID(), '_give_content_option', true );
568
			if ( $show_content && ! get_post_meta( get_the_ID(), '_give_display_content', true ) ) {
569
				$field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' );
570
				update_post_meta( get_the_ID(), '_give_display_content', $field_value );
571
572
				$field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' );
573
				update_post_meta( get_the_ID(), '_give_content_option', $field_value );
574
			}
575
576
577
			// Convert yes/no setting field to enabled/disabled.
578
			$form_radio_settings = array(
579
				// Custom Amount.
580
				'_give_custom_amount',
581
582
				// Donation Gaol.
583
				'_give_goal_option',
584
585
				// Close Form.
586
				'_give_close_form_when_goal_achieved',
587
588
				// Guest Donation.
589
				'_give_logged_in_only',
590
591
				// Term & conditions.
592
				'_give_terms_option',
593
594
				// Offline donation.
595
				'_give_customize_offline_donations',
596
597
				// Billing fields.
598
				'_give_offline_donation_enable_billing_fields_single'
599
			);
600
601
602
			foreach ( $form_radio_settings as $meta_key ) {
603
				// Get value.
604
				$field_value = get_post_meta( get_the_ID(), $meta_key, true );
605
606
				// Convert meta value only if it is in yes/no/none.
607
				if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) {
608
609
					$field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' );
610
					update_post_meta( get_the_ID(), $meta_key, $field_value );
611
				}
612
613
			}
614
		}
615
	}
616
617
	wp_reset_postdata();
618
}
619
620
/**
621
 * Get list of core setting which is renamed in version 1.8.
622
 *
623
 * @since  1.8
624
 * @return array
625
 */
626
function give_v18_renamed_core_settings() {
627
	return array(
628
		'disable_paypal_verification' => 'paypal_verification',
629
		'disable_css'                 => 'css',
630
		'disable_welcome'             => 'welcome',
631
		'disable_forms_singular'      => 'forms_singular',
632
		'disable_forms_archives'      => 'forms_archives',
633
		'disable_forms_excerpt'       => 'forms_excerpt',
634
		'disable_form_featured_img'   => 'form_featured_img',
635
		'disable_form_sidebar'        => 'form_sidebar',
636
		'disable_admin_notices'       => 'admin_notices',
637
		'disable_the_content_filter'  => 'the_content_filter',
638
		'enable_floatlabels'          => 'floatlabels',
639
		'enable_categories'           => 'categories',
640
		'enable_tags'                 => 'tags',
641
	);
642
}