Issues (4296)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

includes/admin/plugins.php (23 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Admin Plugins
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Plugins
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.4
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Plugins row action links
19
 *
20
 * @since 1.4
21
 *
22
 * @param array $actions An array of plugin action links.
23
 *
24
 * @return array An array of updated action links.
25
 */
26
function give_plugin_action_links( $actions ) {
27
	$new_actions = array(
28
		'settings' => sprintf(
29
			'<a href="%1$s">%2$s</a>',
30
			admin_url( 'edit.php?post_type=give_forms&page=give-settings' ),
31
			__( 'Settings', 'give' )
32
		),
33
	);
34
35
	return array_merge( $new_actions, $actions );
36
}
37
38
add_filter( 'plugin_action_links_' . GIVE_PLUGIN_BASENAME, 'give_plugin_action_links' );
39
40
41
/**
42
 * Plugin row meta links
43
 *
44
 * @since 1.4
45
 *
46
 * @param array $plugin_meta An array of the plugin's metadata.
47
 * @param string $plugin_file Path to the plugin file, relative to the plugins directory.
48
 *
49
 * @return array
50
 */
51
function give_plugin_row_meta( $plugin_meta, $plugin_file ) {
52
	if ( GIVE_PLUGIN_BASENAME !== $plugin_file ) {
53
		return $plugin_meta;
54
	}
55
56
	$new_meta_links = array(
57
		sprintf(
58
			'<a href="%1$s" target="_blank">%2$s</a>',
59
			esc_url(
60
				add_query_arg(
61
					array(
62
						'utm_source'   => 'plugins-page',
63
						'utm_medium'   => 'plugin-row',
64
						'utm_campaign' => 'admin',
65
					), 'https://givewp.com/documentation/'
66
				)
67
			),
68
			__( 'Documentation', 'give' )
69
		),
70
		sprintf(
71
			'<a href="%1$s" target="_blank">%2$s</a>',
72
			esc_url(
73
				add_query_arg(
74
					array(
75
						'utm_source'   => 'plugins-page',
76
						'utm_medium'   => 'plugin-row',
77
						'utm_campaign' => 'admin',
78
					), 'https://givewp.com/addons/'
79
				)
80
			),
81
			__( 'Add-ons', 'give' )
82
		),
83
	);
84
85
	return array_merge( $plugin_meta, $new_meta_links );
86
}
87
88
add_filter( 'plugin_row_meta', 'give_plugin_row_meta', 10, 2 );
89
90
91
/**
92
 * Get the Parent Page Menu Title in admin section.
93
 * Based on get_admin_page_title WordPress Function.
94
 *
95
 * @since 1.8.17
96
 *
97
 * @global array $submenu
98
 * @global string $plugin_page
99
 *
100
 * @return string $title Page title
101
 */
102
function give_get_admin_page_menu_title() {
103
	$title = '';
104
	global $submenu, $plugin_page;
105
106
	foreach ( array_keys( $submenu ) as $parent ) {
107
		if ( 'edit.php?post_type=give_forms' !== $parent ) {
108
			continue;
109
		}
110
111
		foreach ( $submenu[ $parent ] as $submenu_array ) {
112
			if ( $plugin_page !== $submenu_array[2] ) {
113
				continue;
114
			}
115
116
			$title = isset( $submenu_array[0] ) ?
117
				$submenu_array[0] :
118
				$submenu_array[3];
119
		}
120
	}
121
122
	return $title;
123
}
124
125
/**
126
 * Store recently activated Give's addons to wp options.
127
 *
128
 * @since 2.1.0
129
 */
130
function give_recently_activated_addons() {
131
	// Check if action is set.
132
	if ( isset( $_REQUEST['action'] ) ) {
133
		$plugin_action = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : ( isset( $_REQUEST['action2'] ) ? $_REQUEST['action2'] : '' );
0 ignored issues
show
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
134
		$plugins       = array();
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
135
136
		switch ( $plugin_action ) {
137
			case 'activate': // Single add-on activation.
138
				$plugins[] = $_REQUEST['plugin'];
0 ignored issues
show
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
139
				break;
140
			case 'activate-selected': // If multiple add-ons activated.
141
				$plugins = $_REQUEST['checked'];
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
142
				break;
143
		}
144
0 ignored issues
show
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
145
146
		if ( ! empty( $plugins ) ) {
147
148
			$give_addons = give_get_recently_activated_addons();
149
150
			foreach ( $plugins as $plugin ) {
151
				// Get plugins which has 'Give-' as prefix.
152
				if ( stripos( $plugin, 'Give-' ) !== false ) {
0 ignored issues
show
Found "!== false". Use Yoda Condition checks, you must
Loading history...
153
					$give_addons[] = $plugin;
154
				}
155
			}
156
157
			if ( ! empty( $give_addons ) ) {
158
				// Update the Give's activated add-ons.
159
				update_option( 'give_recently_activated_addons', $give_addons, false );
160
			}
161
		}
162
	}
163
}
164
165
// Add add-on plugins to wp option table.
166
add_action( 'activated_plugin', 'give_recently_activated_addons', 10 );
167
168
/**
169
 * Create new menu in plugin section that include all the add-on
170
 *
171
 * @since 2.1.0
172
 *
173
 * @param $plugin_menu
174
 *
175
 * @return mixed
176
 */
177
function give_filter_addons_do_filter_addons( $plugin_menu ) {
178
	global $plugins;
179
180
	foreach ( $plugins['all'] as $plugin_slug => $plugin_data ) {
181
182
		if ( false !== strpos( $plugin_data['Name'], 'Give' ) && false !== strpos( $plugin_data['AuthorName'], 'WordImpress' ) ) {
183
			$plugins['give'][ $plugin_slug ]           = $plugins['all'][ $plugin_slug ];
184
			$plugins['give'][ $plugin_slug ]['plugin'] = $plugin_slug;
185
			// replicate the next step.
186
			if ( current_user_can( 'update_plugins' ) ) {
187
				$current = get_site_transient( 'update_plugins' );
188
				if ( isset( $current->response[ $plugin_slug ] ) ) {
189
					$plugins['give'][ $plugin_slug ]['update'] = true;
190
				}
191
			}
192
		}
193
	}
194
195
	return $plugin_menu;
196
197
}
198
199
add_filter( 'show_advanced_plugins', 'give_filter_addons_do_filter_addons' );
200
add_filter( 'show_network_active_plugins', 'give_filter_addons_do_filter_addons' );
201
202
/**
203
 * Keep activating the same add-on when admin activate or deactivate from Give Menu
204
 *
205
 * @since 2.2.0
206
 *
207
 * @param $action
208
 * @param $result
209
 */
210
function give_prepare_filter_addons_referer( $action, $result ) {
0 ignored issues
show
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $result is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
211
	if ( ! function_exists( 'get_current_screen' ) ) {
212
		return;
213
	}
214
	$screen = get_current_screen();
215
	if ( is_object( $screen ) && $screen->base === 'plugins' && ! empty( $_REQUEST['plugin_status'] ) && $_REQUEST['plugin_status'] === 'give' ) {
0 ignored issues
show
Found "=== '". Use Yoda Condition checks, you must
Loading history...
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
216
		global $status;
217
		$status = 'give';
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
218
	}
219
}
220
221
add_action( 'check_admin_referer', 'give_prepare_filter_addons_referer', 10, 2 );
222
223
/**
224
 * Make the Give Menu as an default menu and update the Menu Name
225
 *
226
 * @since 2.1.0
227
 *
228
 * @param $views
229
 *
230
 * @return mixed
231
 */
232
function give_filter_addons_filter_addons( $views ) {
233
234
	global $status, $plugins;
235
236
	if ( ! empty( $plugins['give'] ) ) {
237
		$class = '';
238
239
		if ( 'give' === $status ) {
240
			$class = 'current';
241
		}
242
243
		$views['give'] = sprintf(
244
			'<a class="%s" href="plugins.php?plugin_status=give"> %s <span class="count">(%s) </span></a>',
245
			$class,
246
			__( 'Give', 'give' ),
247
			count( $plugins['give'] )
248
		);
249
	}
250
251
	return $views;
252
}
253
254
add_filter( 'views_plugins', 'give_filter_addons_filter_addons' );
255
add_filter( 'views_plugins-network', 'give_filter_addons_filter_addons' );
256
257
/**
258
 * Set the Give as the Main menu when admin click on the Give Menu in Plugin section.
259
 *
260
 * @since 2.1.0
261
 *
262
 * @param $plugins
263
 *
264
 * @return mixed
265
 */
266
function give_prepare_filter_addons( $plugins ) {
267
	global $status;
268
269
	if ( isset( $_REQUEST['plugin_status'] ) && 'give' === $_REQUEST['plugin_status'] ) {
270
		$status = 'give';
0 ignored issues
show
Overridding WordPress globals is prohibited
Loading history...
271
	}
272
273
	return $plugins;
274
}
275
276
add_filter( 'all_plugins', 'give_prepare_filter_addons' );
277
278
279
/**
280
 * Display the upgrade notice message.
281
 *
282
 * @param array $data Array of plugin metadata.
283
 * @param array $response An array of metadata about the available plugin update.
284
 *
285
 * @since 2.1
286
 */
287
function give_in_plugin_update_message( $data, $response ) {
0 ignored issues
show
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
288
	$new_version           = $data['new_version'];
289
	$current_version_parts = explode( '.', GIVE_VERSION );
290
	$new_version_parts     = explode( '.', $new_version );
291
292
	// If it is a minor upgrade then return.
293
	if ( version_compare( $current_version_parts[0] . '.' . $current_version_parts[1], $new_version_parts[0] . '.' . $new_version_parts[1], '=' ) ) {
294
295
		return;
296
	}
297
298
	// Get the upgrade notice from the trunk.
299
	$upgrade_notice = give_get_plugin_upgrade_notice( $new_version );
300
301
	// Display upgrade notice.
302
	echo apply_filters( 'give_in_plugin_update_message', $upgrade_notice ? '</p>' . wp_kses_post( $upgrade_notice ) . '<p class="dummy">' : '' );
0 ignored issues
show
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
303
}
304
305
// Display upgrade notice.
306
add_action( 'in_plugin_update_message-' . GIVE_PLUGIN_BASENAME, 'give_in_plugin_update_message', 10, 2 );
307
308
309
/**
310
 * Get the upgrade notice from WordPress.org.
311
 *
312
 * Note: internal purpose use only
313
 *
314
 * @since 2.1
315
 *
316
 * @param string $new_version New verison of the plugin.
317
 *
318
 * @return string
319
 */
320
function give_get_plugin_upgrade_notice( $new_version ) {
321
322
	// Cache the upgrade notice.
323
	$transient_name = "give_upgrade_notice_{$new_version}";
324
	$upgrade_notice = get_transient( $transient_name );
325
326
	if ( false === $upgrade_notice ) {
327
		$response = wp_safe_remote_get( 'https://plugins.svn.wordpress.org/give/trunk/readme.txt' );
328
329
		if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) {
330
			$upgrade_notice = give_parse_plugin_update_notice( $response['body'], $new_version );
331
			set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS );
332
		}
333
	}
334
335
	return $upgrade_notice;
336
}
337
338
339
/**
340
 * Parse update notice from readme file.
341
 *
342
 * Note: internal purpose use only
343
 *
344
 * @since 2.1
345
 *
346
 * @param  string $content Content of the readme.txt file.
347
 * @param  string $new_version The version with current version is compared.
348
 *
349
 * @return string
350
 */
351
function give_parse_plugin_update_notice( $content, $new_version ) {
352
	$version_parts     = explode( '.', $new_version );
353
	$check_for_notices = array(
354
		$version_parts[0] . '.0',
355
		$version_parts[0] . '.0.0',
356
		$version_parts[0] . '.' . $version_parts[1] . '.' . '0',
357
	);
358
359
	// Regex to extract Upgrade notice from the readme.txt file.
360
	$notice_regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( $new_version ) . '\s*=|$)~Uis';
361
362
	$upgrade_notice = '';
363
364
	foreach ( $check_for_notices as $check_version ) {
365
		if ( version_compare( GIVE_VERSION, $check_version, '>' ) ) {
366
			continue;
367
		}
368
369
		$matches = null;
370
371
		if ( preg_match( $notice_regexp, $content, $matches ) ) {
372
			$notices = (array) preg_split( '~[\r\n]+~', trim( $matches[2] ) );
373
374
			if ( version_compare( trim( $matches[1] ), $check_version, '=' ) ) {
375
				$upgrade_notice .= '<p class="give-plugin-upgrade-notice">';
376
377
				foreach ( $notices as $index => $line ) {
378
					$upgrade_notice .= preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $line );
379
				}
380
381
				$upgrade_notice .= '</p>';
382
			}
383
384
			if ( ! empty( $upgrade_notice ) ) {
385
				break;
386
			}
387
		}
388
	}
389
390
	return wp_kses_post( $upgrade_notice );
391
}
392
393
394
/**
395
 * Add styling to the plugin upgrade notice.
396
 *
397
 * @since 2.1
398
 */
399
function give_plugin_notice_css() {
400
	?>
401
	<style type="text/css">
402
		#give-update .give-plugin-upgrade-notice {
403
			font-weight: 400;
404
			background: #fff8e5 !important;
405
			border-left: 4px solid #ffb900;
406
			border-top: 1px solid #ffb900;
407
			padding: 9px 0 9px 12px !important;
408
			margin: 0 -12px 0 -16px !important;
409
		}
410
411
		#give-update .give-plugin-upgrade-notice:before {
412
			content: '\f348';
413
			display: inline-block;
414
			font: 400 18px/1 dashicons;
415
			speak: none;
416
			margin: 0 8px 0 -2px;
417
			vertical-align: top;
418
		}
419
420
		#give-update .dummy {
421
			display: none;
422
		}
423
	</style>
424
	<?php
425
}
426
427
add_action( 'admin_head', 'give_plugin_notice_css' );
428
429
/**
430
 * Get list of add-on last activated.
431
 *
432
 * @since 2.1.3
433
 *
434
 * @return mixed|array list of recently activated add-on
435
 */
436
function give_get_recently_activated_addons() {
437
	return get_option( 'give_recently_activated_addons', array() );
438
}
439
440
/**
441
 * Renders the Give Deactivation Survey Form.
442
 * Note: only for internal use
443
 *
444
 * @since 2.2
445
 */
446
function give_deactivation_popup() {
447
448
	$results = array();
449
450
	// Start output buffering.
451
	ob_start();
452
	?>
453
454
	<h2 id="deactivation-survey-title">
455
		<img src="<?php echo esc_url( GIVE_PLUGIN_URL ) ?>/assets/dist/images/give-icon-full-circle.svg">
456
		<span><?php esc_html_e( 'Give Deactivation', 'give' ); ?></span>
457
	</h2>
458
	<form class="deactivation-survey-form" method="POST">
459
		<p><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating Give. All submissions are anonymous and we only use this feedback to improve this plugin.', 'give' ); ?></p>
460
461
		<div>
462
			<label class="give-field-description">
463
				<input type="radio" name="give-survey-radios" value="1">
464
				<?php esc_html_e( "I'm only deactivating temporarily", 'give' ); ?>
465
			</label>
466
		</div>
467
468
		<div>
469
			<label class="give-field-description">
470
				<input type="radio" name="give-survey-radios" value="2">
471
				<?php esc_html_e( 'I no longer need the plugin', 'give' ); ?>
472
			</label>
473
		</div>
474
475
		<div>
476
			<label class="give-field-description">
477
				<input type="radio" name="give-survey-radios" value="3" data-has-field="true">
478
				<?php esc_html_e( 'I found a better plugin', 'give' ); ?>
479
			</label>
480
481
			<div class="give-survey-extra-field">
482
				<p><?php esc_html_e( 'What is the name of the plugin?', 'give' ); ?></p>
483
				<input type="text" name="user-reason" class="widefat">
484
			</div>
485
		</div>
486
487
		<div>
488
			<label class="give-field-description">
489
				<input type="radio" name="give-survey-radios" value="4">
490
				<?php esc_html_e( 'I only needed the plugin for a short period', 'give' ); ?>
491
			</label>
492
		</div>
493
494
		<div>
495
			<label class="give-field-description">
496
				<input type="radio" name="give-survey-radios" value="5" data-has-field="true">
497
				<?php esc_html_e( 'The plugin broke my site', 'give' ); ?>
498
			</label>
499
500
			<div class="give-survey-extra-field">
501
				<p><?php
502
					printf(
503
						'%1$s %2$s %3$s',
504
						__( "We're sorry to hear that, check", 'give' ),
505
						'<a href="https://wordpress.org/support/plugin/give">Give Support</a>.',
506
						__( 'Can you describe the issue?', 'give' )
507
					);
508
					?>
509
				</p>
510
				<textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled>
511
			</div>
512
		</div>
513
514
		<div>
515
			<label class="give-field-description">
516
				<input type="radio" name="give-survey-radios" value="6" data-has-field="true">
517
				<?php esc_html_e( 'The plugin suddenly stopped working', 'give' ); ?>
518
			</label>
519
520
			<div class="give-survey-extra-field">
521
				<p><?php
522
					printf(
523
						'%1$s %2$s %3$s',
524
						__( "We're sorry to hear that, check", 'give' ),
525
						'<a href="https://wordpress.org/support/plugin/give">Give Support</a>.',
526
						__( 'Can you describe the issue?', 'give' )
527
					);
528
					?>
529
				</p>
530
				<textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled>
531
			</div>
532
		</div>
533
534
		<div>
535
			<label class="give-field-description">
536
				<input type="radio" name="give-survey-radios" value="7" data-has-field="true">
537
				<?php esc_html_e( 'Other', 'give' ); ?>
538
			</label>
539
540
			<div class="give-survey-extra-field">
541
				<p><?php esc_html_e( "Please describe why you're deactivating Give", 'give' ); ?></p>
542
				<textarea disabled name="user-reason" class="widefat" rows="6"></textarea disabled>
543
			</div>
544
		</div>
545
546
		<div id="survey-and-delete-data">
547
			<p>
548
				<label>
549
					<input type="checkbox" name="confirm_reset_store" value="1">
550
					<?php esc_html_e( 'Would you like to delete all Give data?', 'give' ); ?>
551
				</label>
552
				<section class="give-field-description">
553
					<?php esc_html_e( 'By default the custom roles, Give options, and database entries are not deleted when you deactivate Give. If you are deleting Give completely from your website and want those items removed as well check this option. Note: This will permanently delete all Give data from your database.', 'give' ); ?>
554
				</section>
555
			</p>
556
		</div>
557
		<?php
558
		$current_user       = wp_get_current_user();
559
		$current_user_email = $current_user->user_email;
560
		?>
561
		<input type="hidden" name="current-user-email" value="<?php echo $current_user_email; ?>">
0 ignored issues
show
Expected next thing to be a escaping function, not '$current_user_email'
Loading history...
562
		<input type="hidden" name="current-site-url" value="<?php echo esc_url( get_bloginfo( 'url' ) ); ?>">
563
		<input type="hidden" name="give-export-class" value="Give_Tools_Reset_Stats">
564
		<?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?>
565
	</form>
566
567
	<?php
568
569
	// Echo content (deactivation form) from the output buffer.
570
	$output = ob_get_contents();
571
572
	// Erase and stop output buffer.
573
	ob_end_clean();
574
575
	$results['html'] = $output;
576
577
	wp_send_json( $results );
578
}
579
580
add_action( 'wp_ajax_give_deactivation_popup', 'give_deactivation_popup' );
581
582
/**
583
 * Ajax callback after the deactivation survey form has been submitted.
584
 * Note: only for internal use
585
 *
586
 * @since 2.2
587
 */
588
function give_deactivation_form_submit() {
589
590
	if ( ! check_ajax_referer( 'deactivation_survey_nonce', 'nonce', false ) ) {
591
		wp_send_json_error();
592
		wp_die();
593
	}
594
595
	$form_data = give_clean( wp_parse_args( $_POST['form-data'] ) );
0 ignored issues
show
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
Detected usage of a non-validated input variable: $_POST
Loading history...
Detected usage of a non-sanitized input variable: $_POST
Loading history...
596
597
	// Get the selected radio value.
598
	$radio_value = isset( $form_data['give-survey-radios'] ) ? $form_data['give-survey-radios'] : 0;
599
600
	// Get the reason if any radio button has an optional text field.
601
	$user_reason = isset( $form_data['user-reason'] ) ? $form_data['user-reason'] : '';
602
603
	// Get the email of the user who deactivated the plugin.
604
	$user_email = isset( $form_data['current-user-email'] ) ? $form_data['current-user-email'] : '';
605
606
	// Get the URL of the website on which Give plugin is being deactivated.
607
	$site_url = isset( $form_data['current-site-url'] ) ? $form_data['current-site-url'] : '';
608
609
	// Get the value of the checkbox for deleting Give's data.
610
	$delete_data = isset( $form_data['confirm_reset_store'] ) ? $form_data['confirm_reset_store'] : '';
611
612
	/**
613
	 * Make a POST request to the endpoint to send the survey data.
614
	 */
615
	$response = wp_remote_post(
616
		'http://survey.givewp.com/wp-json/give/v2/survey/',
617
		array(
618
			'body' => array(
619
				'radio_value'        => $radio_value,
620
				'user_reason'        => $user_reason,
621
				'current_user_email' => $user_email,
622
				'site_url'           => $site_url,
623
			),
624
		)
625
	);
626
627
	// Check if the data is sent and stored correctly.
628
	$response = wp_remote_retrieve_body( $response );
629
630
	if ( 'true' === $response ) {
631
		if ( '1' === $delete_data ) {
632
			wp_send_json_success(
633
				array(
634
					'delete_data' => true,
635
				)
636
			);
637
		} else {
638
			wp_send_json_success(
639
				array(
640
					'delete_data' => false,
641
				)
642
			);
643
		}
644
	} else {
645
		wp_send_json_error();
646
	}
647
648
	wp_die();
649
}
650
651
add_action( 'wp_ajax_deactivation_form_submit', 'give_deactivation_form_submit' );
652