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/install.php (22 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
 * Install Function
4
 *
5
 * @package     Give
6
 * @subpackage  Functions/Install
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Install
19
 *
20
 * Runs on plugin install by setting up the post types, custom taxonomies, flushing rewrite rules to initiate the new
21
 * 'donations' slug and also creates the plugin and populates the settings fields for those plugin pages. After
22
 * successful install, the user is redirected to the Give Welcome screen.
23
 *
24
 * @since 1.0
25
 *
26
 * @param bool $network_wide
27
 *
28
 * @global     $wpdb
29 2
 * @return void
30
 */
31 2
function give_install( $network_wide = false ) {
32
33
	global $wpdb;
34
35
	if ( is_multisite() && $network_wide ) {
36
37
		foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) {
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
38
39
			switch_to_blog( $blog_id );
0 ignored issues
show
switch_to_blog is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.
Loading history...
40
			give_run_install();
41
			restore_current_blog();
42
43 2
		}
0 ignored issues
show
Blank line found after control structure
Loading history...
44
45
	} else {
46
47 2
		give_run_install();
48
49
	}
50
51
}
52
53
/**
54
 * Run the Give Install process.
55
 *
56
 * @since  1.5
57
 * @return void
58
 */
59 2
function give_run_install() {
60
	$give_options = give_get_settings();
61
62 2
	// Setup the Give Custom Post Types.
63
	give_setup_post_types();
64
65 2
	// Add Upgraded From Option.
66
	$current_version = get_option( 'give_version' );
67
	if ( $current_version ) {
68 2
		update_option( 'give_version_upgraded_from', $current_version, false );
69 2
	}
70 2
71 2
	// Setup some default options.
72
	$options = array();
73
74 2
	//Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency.
75
	if ( empty( $current_version ) ) {
76
		$options = array_merge( $options, give_get_default_settings() );
77 2
	}
78
79
	// Populate the default values.
80 2
	update_option( 'give_settings', array_merge( $give_options, $options ), false );
81
82 2
	/**
83 2
	 * Run plugin upgrades.
84 2
	 *
85 2
	 * @since 1.8
86 2
	 */
87
	do_action( 'give_upgrades' );
88 2
89 2
	if ( GIVE_VERSION !== get_option( 'give_version' ) ) {
90
		update_option( 'give_version', GIVE_VERSION, false );
91
	}
92 2
93 2
	// Create Give roles.
94
	$roles = new Give_Roles();
95
	$roles->add_roles();
96 2
	$roles->add_caps();
97
98
	// Set api version, end point and refresh permalink.
99 2
	$api = new Give_API();
100
	$api->add_endpoint();
101 2
	update_option( 'give_default_api_version', 'v' . $api->get_version(), false );
102 2
103 2
	flush_rewrite_rules();
104 2
105 2
	// Create the donor databases.
106
	$donors_db = new Give_DB_Donors();
107 2
	$donors_db->create_table();
108 2
	$donor_meta = new Give_DB_Donor_Meta();
109
	$donor_meta->create_table();
110 2
111 2
	// Add a temporary option to note that Give pages have been created.
112
	Give_Cache::set( '_give_installed', $options, 30, true );
113
114 2
	if ( ! $current_version ) {
115
116 2
		require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
117
118 2
		// When new upgrade routines are added, mark them as complete on fresh install.
119 2
		$upgrade_routines = array(
120 2
			'upgrade_give_user_caps_cleanup',
121 2
			'upgrade_give_payment_customer_id',
122 2
			'upgrade_give_offline_status',
123
			'v18_upgrades_core_setting',
124 2
			'v18_upgrades_form_metadata',
125 2
			'v189_upgrades_levels_post_meta',
126
			'v1812_update_amount_values',
127 2
			'v1812_update_donor_purchase_values',
128 2
			'v1813_update_user_roles',
129
			'v1813_update_donor_user_roles',
130
			'v1817_update_donation_iranian_currency_code',
131 2
			'v1817_cleanup_user_roles',
132
			'v1818_assign_custom_amount_set_donation',
133
			'v1818_give_worker_role_cleanup',
134
			'v20_upgrades_form_metadata',
135
			'v20_logs_upgrades',
136
			'v20_move_metadata_into_new_table',
137
			'v20_rename_donor_tables',
138
			'v20_upgrades_donor_name',
139
			'v20_upgrades_user_address',
140
			'v20_upgrades_payment_metadata',
141
			'v201_upgrades_payment_metadata',
142
			'v201_add_missing_donors',
143
			'v201_move_metadata_into_new_table',
144
			'v201_logs_upgrades',
145
			'v210_verify_form_status_upgrades',
146
			'v213_delete_donation_meta',
147
			'v215_update_donor_user_roles',
148 2
			'v220_rename_donation_meta_type',
149 2
			'v224_update_donor_meta',
150
			'v224_update_donor_meta_forms_id'
151
		);
152 2
153 2
		foreach ( $upgrade_routines as $upgrade ) {
154 2
			give_set_upgrade_complete( $upgrade );
155
		}
156
	}
157 2
158 2
	// Bail if activating from network, or bulk.
159 2
	if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
0 ignored issues
show
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
160
		return;
161 2
	}
162 2
163
	// Add the transient to redirect.
164
	Give_Cache::set( '_give_activation_redirect', true, 30, true );
165 2
}
166
167
/**
168 2
 * Network Activated New Site Setup.
169
 *
170
 * When a new site is created when Give is network activated this function runs the appropriate install function to set
171 2
 * up the site for Give.
172
 *
173 2
 * @since      1.3.5
174
 *
175
 * @param  int    $blog_id The Blog ID created.
176
 * @param  int    $user_id The User ID set as the admin.
177
 * @param  string $domain  The URL.
178
 * @param  string $path    Site Path.
179
 * @param  int    $site_id The Site ID.
180
 * @param  array  $meta    Blog Meta.
181
 */
182
function give_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
0 ignored issues
show
The parameter $user_id 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 $domain 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 $path 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 $site_id 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 $meta 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...
183
184
	if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) {
185
186
		switch_to_blog( $blog_id );
0 ignored issues
show
switch_to_blog is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.
Loading history...
187
		give_install();
188
		restore_current_blog();
189
190 2
	}
191 1
192
}
193
194
add_action( 'wpmu_new_blog', 'give_on_create_blog', 10, 6 );
195 1
196
197 1
/**
198
 * Drop Give's custom tables when a mu site is deleted.
199
 *
200
 * @since  1.4.3
201
 *
202
 * @param  array $tables  The tables to drop.
203
 * @param  int   $blog_id The Blog ID being deleted.
204
 *
205
 * @return array          The tables to drop.
206
 */
207
function give_wpmu_drop_tables( $tables, $blog_id ) {
208
209
	switch_to_blog( $blog_id );
0 ignored issues
show
switch_to_blog is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.
Loading history...
210
	$donors_db     = new Give_DB_Donors();
211
	$donor_meta_db = new Give_DB_Donor_Meta();
212
213
	if ( $donors_db->installed() ) {
214
		$tables[] = $donors_db->table_name;
215
		$tables[] = $donor_meta_db->table_name;
216
	}
217
	restore_current_blog();
218
219
	return $tables;
220
221
}
222
223
add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 );
224
225
/**
226
 * Post-installation
227
 *
228
 * Runs just after plugin installation and exposes the give_after_install hook.
229
 *
230
 * @since 1.0
231
 * @return void
232
 */
233
function give_after_install() {
234
235
	if ( ! is_admin() ) {
236
		return;
237
	}
238
239
	$give_options     = Give_Cache::get( '_give_installed', true );
240
	$give_table_check = get_option( '_give_table_check', false );
241
242
	if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) {
243
244
		if ( ! @Give()->donor_meta->installed() ) {
0 ignored issues
show
Silencing errors is discouraged
Loading history...
245
246
			// Create the donor meta database.
247
			// (this ensures it creates it on multisite instances where it is network activated).
248
			@Give()->donor_meta->create_table();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Silencing errors is discouraged
Loading history...
249
250
		}
251
252
		if ( ! @Give()->donors->installed() ) {
0 ignored issues
show
Silencing errors is discouraged
Loading history...
253
			// Create the donor database.
254
			// (this ensures it creates it on multisite instances where it is network activated).
255
			@Give()->donors->create_table();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Silencing errors is discouraged
Loading history...
256
257
			/**
258
			 * Fires after plugin installation.
259
			 *
260
			 * @since 1.0
261
			 *
262
			 * @param array $give_options Give plugin options.
263
			 */
264
			do_action( 'give_after_install', $give_options );
265 3
		}
266 1
267
		update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ), false );
268
269 2
	}
270 2
271
	// Delete the transient
272 2
	if ( false !== $give_options ) {
273
		Give_Cache::delete( Give_Cache::get_key( '_give_installed' ) );
274 2
	}
275
0 ignored issues
show
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
276
277
}
278
279
add_action( 'admin_init', 'give_after_install' );
280
281 2
282
/**
283 2
 * Install user roles on sub-sites of a network
284
 *
285
 * Roles do not get created when Give is network activation so we need to create them during admin_init
286 2
 *
287 1
 * @since 1.0
288 1
 * @return void
289
 */
290
function give_install_roles_on_network() {
291 2
292
	global $wp_roles;
293
294
	if ( ! is_object( $wp_roles ) ) {
295
		return;
296
	}
297
298
	if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) {
299
300
		// Create Give plugin roles
301
		$roles = new Give_Roles();
302
		$roles->add_roles();
303
		$roles->add_caps();
304
305
	}
306 2
307
}
308 2
309 1
add_action( 'admin_init', 'give_install_roles_on_network' );
310
311
/**
312 1
 * Default core setting values.
313
 *
314
 * @since 1.8
315 1
 * @return array
316 1
 */
317 1
function give_get_default_settings() {
318
319 1
	$options = array(
320
		// General.
321 1
		'base_country'                                => 'US',
322
		'test_mode'                                   => 'enabled',
323
		'currency'                                    => 'USD',
324
		'currency_position'                           => 'before',
325
		'session_lifetime'                            => '604800',
326
		'email_access'                                => 'enabled',
327
		'thousands_separator'                         => ',',
328
		'decimal_separator'                           => '.',
329
		'number_decimals'                             => 2,
330
		'sequential-ordering_status'                  => 'enabled',
331
332
		// Display options.
333
		'css'                                         => 'enabled',
334
		'floatlabels'                                 => 'disabled',
335
		'welcome'                                     => 'enabled',
336
		'company_field'                               => 'disabled',
337
		'name_title_prefix'                           => 'disabled',
338
		'forms_singular'                              => 'enabled',
339
		'forms_archives'                              => 'enabled',
340
		'forms_excerpt'                               => 'enabled',
341
		'form_featured_img'                           => 'enabled',
342
		'form_sidebar'                                => 'enabled',
343
		'categories'                                  => 'disabled',
344
		'tags'                                        => 'disabled',
345
		'terms'                                       => 'disabled',
346
		'admin_notices'                               => 'enabled',
347
		'cache'                                       => 'enabled',
348
		'uninstall_on_delete'                         => 'disabled',
349
		'the_content_filter'                          => 'enabled',
350
		'scripts_footer'                              => 'disabled',
351
		'agree_to_terms_label'                        => __( 'Agree to Terms?', 'give' ),
352
		'agreement_text'                              => give_get_default_agreement_text(),
353
354
		// Paypal IPN verification.
355
		'paypal_verification'                         => 'enabled',
356
357
		// Default is manual gateway.
358
		'gateways'                                    => array( 'manual' => 1, 'offline' => 1 ),
359
		'default_gateway'                             => 'manual',
360
361
		// Offline gateway setup.
362
		'global_offline_donation_content'             => give_get_default_offline_donation_content(),
363
		'global_offline_donation_email'               => give_get_default_offline_donation_content(),
364
365
		// Billing address.
366
		'give_offline_donation_enable_billing_fields' => 'disabled',
367
368
		// Default donation notification email.
369
		'donation_notification'                       => give_get_default_donation_notification_email(),
370
371
		// Default email receipt message.
372
		'donation_receipt'                            => give_get_default_donation_receipt_email(),
373
374
		'donor_default_user_role'                     => 'give_donor',
375
376
	);
377
378
	return $options;
379
}
380
381
/**
382
 * Default terms and conditions.
383
 */
384
function give_get_default_agreement_text() {
385
386
	$org_name = get_bloginfo( 'name' );
387
388
	$agreement = sprintf(
389
		'<p>Acceptance of any contribution, gift or grant is at the discretion of the %1$s. The  %1$s will not accept any gift unless it can be used or expended consistently with the purpose and mission of the  %1$s.</p>
390
				<p>No irrevocable gift, whether outright or life-income in character, will be accepted if under any reasonable set of circumstances the gift would jeopardize the donor’s financial security.</p>
391
				<p>The %1$s will refrain from providing advice about the tax or other treatment of gifts and will encourage donors to seek guidance from their own professional advisers to assist them in the process of making their donation.</p>
392
				<p>The %1$s will accept donations of cash or publicly traded securities. Gifts of in-kind services will be accepted at the discretion of the %1$s.</p>
393
				<p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for %1$s.</p>
394
				<p>The %1$s will provide acknowledgments to donors meeting tax requirements for property received by the charity as a gift. However, except for gifts of cash and publicly traded securities, no value shall be ascribed to any receipt or other form of substantiation of a gift received by %1$s.</p>
395
				<p>The %1$s will respect the intent of the donor relating to gifts for restricted purposes and those relating to the desire to remain anonymous. With respect to anonymous gifts, the %1$s will restrict information about the donor to only those staff members with a need to know.</p>
396
				<p>The %1$s will not compensate, whether through commissions, finders\' fees, or other means, any third party for directing a gift or a donor to the %1$s.</p>',
397
		$org_name
398
	);
399
400
	return apply_filters( 'give_get_default_agreement_text', $agreement, $org_name );
401
}
402
403
404
/**
405
 * This function will install give related page which is not created already.
406
 *
407
 * @since 1.8.11
408
 *
409
 * @return void
410
 */
411
function give_create_pages() {
412
413
	// Bailout if pages already created.
414
	if ( get_option( 'give_install_pages_created' ) ) {
415
		return false;
416
	}
417
418
	$options = array();
419
420
	// Checks if the Success Page option exists AND that the page exists.
421 View Code Duplication
	if ( ! get_post( give_get_option( 'success_page' ) ) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
422
423
		// Donation Confirmation (Success) Page
424
		$success = wp_insert_post(
425
			array(
426
				'post_title'     => esc_html__( 'Donation Confirmation', 'give' ),
427
				'post_content'   => '[give_receipt]',
428
				'post_status'    => 'publish',
429
				'post_author'    => 1,
430
				'post_type'      => 'page',
431
				'comment_status' => 'closed'
432
			)
433
		);
434
435
		// Store our page IDs
436
		$options['success_page'] = $success;
437
	}
438
439
	// Checks if the Failure Page option exists AND that the page exists.
440 View Code Duplication
	if ( ! get_post( give_get_option( 'failure_page' ) ) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
441
442
		// Failed Donation Page
443
		$failed = wp_insert_post(
444
			array(
445
				'post_title'     => esc_html__( 'Donation Failed', 'give' ),
446
				'post_content'   => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ),
447
				'post_status'    => 'publish',
448
				'post_author'    => 1,
449
				'post_type'      => 'page',
450
				'comment_status' => 'closed'
451
			)
452
		);
453
454
		$options['failure_page'] = $failed;
455
	}
456
457
	// Checks if the History Page option exists AND that the page exists.
458 View Code Duplication
	if ( ! get_post( give_get_option( 'history_page' ) ) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
459
		// Donation History Page
460
		$history = wp_insert_post(
461
			array(
462
				'post_title'     => esc_html__( 'Donation History', 'give' ),
463
				'post_content'   => '[donation_history]',
464
				'post_status'    => 'publish',
465
				'post_author'    => 1,
466
				'post_type'      => 'page',
467
				'comment_status' => 'closed'
468
			)
469
		);
470
471
		$options['history_page'] = $history;
472
	}
473
474
	if ( ! empty( $options ) ) {
475
		update_option( 'give_settings', array_merge( give_get_settings(), $options ), false );
476
	}
477
478
	add_option( 'give_install_pages_created', 1, '', false );
479
}
480
481
add_action( 'admin_init', 'give_create_pages', - 1 );
482