Test Failed
Push — backup/issues/1132 ( b1d18b )
by Ravinder
05:29
created

actions.php ➔ give_admin_quick_css()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 42
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 0
dl 0
loc 42
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 * Front-end Actions
4
 *
5
 * @package     Give
6
 * @subpackage  Functions
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
 * Hooks Give actions, when present in the $_GET superglobal. Every give_action
19
 * present in $_GET is called using WordPress's do_action function. These
20
 * functions are called on init.
21
 *
22
 * @since  1.0
23
 *
24
 * @return void
25
 */
26 View Code Duplication
function give_get_actions() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
27
28
	$_get_action = ! empty( $_GET['give_action'] ) ? $_GET['give_action'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
29
30
	// Add backward compatibility to give-action param ( $_GET )
31
	if(  empty( $_get_action ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
32
		$_get_action = ! empty( $_GET['give-action'] ) ? $_GET['give-action'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
33
	}
34
35
	if ( isset( $_get_action ) ) {
36
		/**
37
		 * Fires in WordPress init or admin init, when give_action is present in $_GET.
38
		 *
39
		 * @since 1.0
40
		 *
41
		 * @param array $_GET Array of HTTP GET variables.
42
		 */
43
		do_action( "give_{$_get_action}", $_GET );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
44
	}
45
46
}
47
48
add_action( 'init', 'give_get_actions' );
49
50
/**
51
 * Hooks Give actions, when present in the $_POST super global. Every give_action
52
 * present in $_POST is called using WordPress's do_action function. These
53
 * functions are called on init.
54
 *
55
 * @since  1.0
56
 *
57
 * @return void
58
 */
59 View Code Duplication
function give_post_actions() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
60
61
	$_post_action = ! empty( $_POST['give_action'] ) ? $_POST['give_action'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
62
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
63
64
	// Add backward compatibility to give-action param ( $_POST ).
65
	if(  empty( $_post_action ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
66
		$_post_action = ! empty( $_POST['give-action'] ) ? $_POST['give-action'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
67
	}
68
69
	if ( isset( $_post_action ) ) {
70
		/**
71
		 * Fires in WordPress init or admin init, when give_action is present in $_POST.
72
		 *
73
		 * @since 1.0
74
		 *
75
		 * @param array $_POST Array of HTTP POST variables.
76
		 */
77
		do_action( "give_{$_post_action}", $_POST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
78
	}
79
80
}
81
82
add_action( 'init', 'give_post_actions' );
83
84
/**
85
 * Connect WordPress user with Donor.
86
 *
87
 * @since  1.7
88
 * @param  int   $user_id   User ID
89
 * @param  array $user_data User Data
90
 * @return void
91
 */
92
function give_connect_donor_to_wpuser( $user_id, $user_data ){
93
	/* @var Give_Donor $donor */
94
	$donor = new Give_Donor( $user_data['user_email'] );
95
96
	// Validate donor id and check if do not is already connect to wp user or not.
97
	if( $donor->id && ! $donor->user_id ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
98
99
		// Update donor user_id.
100
		if( $donor->update( array( 'user_id' => $user_id ) ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
101
			$donor_note = sprintf( esc_html__( 'WordPress user #%d is connected to #%d', 'give' ), $user_id, $donor->id );
102
			$donor->add_note( $donor_note );
103
104
			// Update user_id meta in payments.
105
			// if( ! empty( $donor->payment_ids ) && ( $donations = explode( ',', $donor->payment_ids ) ) ) {
106
			// 	foreach ( $donations as $donation  ) {
107
			// 		give_update_meta( $donation, '_give_payment_user_id', $user_id );
108
			// 	}
109
			// }
110
			// Do not need to update user_id in payment because we will get user id from donor id now.
111
		}
112
	}
113
}
114
add_action( 'give_insert_user', 'give_connect_donor_to_wpuser', 10, 2 );
115
116
117
/**
118
 * Setup site home url check
119
 *
120
 * Note: if location of site changes then run cron to validate licenses
121
 *
122
 * @since  1.7
123
 * @return void
124
 */
125
function give_validate_license_when_site_migrated() {
126
	// Store current site address if not already stored.
127
	$homeurl = home_url();
128
	if( ! get_option( 'give_site_address_before_migrate' ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
129
		// Update site address.
130
		update_option( 'give_site_address_before_migrate', $homeurl );
131
132
		return;
133
	}
134
135
	if( $homeurl !== get_option( 'give_site_address_before_migrate' ) ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
136
		// Immediately run cron.
137
		wp_schedule_single_event( time() , 'give_validate_license_when_site_migrated' );
138
139
		// Update site address.
140
		update_option( 'give_site_address_before_migrate', home_url() );
141
	}
142
143
}
144
add_action( 'init', 'give_validate_license_when_site_migrated' );
145
add_action( 'admin_init', 'give_validate_license_when_site_migrated' );
146
147
148
/**
149
 * Processing after donor batch export complete
150
 *
151
 * @since 1.8
152
 * @param $data
153
 */
154
function give_donor_batch_export_complete( $data ) {
155
	// Remove donor ids cache.
156
	if(
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
157
		isset( $data['class'] )
158
		&& 'Give_Batch_Donors_Export' === $data['class']
159
		&& ! empty( $data['forms'] )
160
		&& isset( $data['give_export_option']['query_id'] )
161
	) {
162
		Give_Cache::delete( Give_Cache::get_key( $data['give_export_option']['query_id'] ) );
163
	}
164
}
165
add_action('give_file_export_complete', 'give_donor_batch_export_complete' );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
166
167
/**
168
 * Print css for wordpress setting pages.
169
 *
170
 * @since 1.8.7
171
 */
172
function give_admin_quick_css() {
173
	/* @var WP_Screen $screen */
174
	$screen = get_current_screen();
175
176
	if( ! ( $screen instanceof WP_Screen ) ) {
0 ignored issues
show
Bug introduced by
The class WP_Screen does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
177
		return false;
178
	}
179
180
	switch ( true ) {
181
		case ( 'plugins' === $screen->base || 'plugins-network' === $screen->base ):
182
			?>
183
			<style>
184
				tr.active.update + tr.give-addon-notice-tr td{
185
                    box-shadow:none;
186
                    -webkit-box-shadow:none;
187
				}
188
				tr.active + tr.give-addon-notice-tr td{
189
                    position: relative;
190
				    top:-1px;
191
                }
192
				tr.active + tr.give-addon-notice-tr .notice{
193
                    margin: 5px 20px 15px 40px;
194
                }
195
196
				tr.give-addon-notice-tr .dashicons {
197
                    color: #f56e28;
198
                }
199
				tr.give-addon-notice-tr td{
200
					border-left: 4px solid #00a0d2;
201
				}
202
203
				tr.give-addon-notice-tr td{
204
					padding: 0!important;
205
				}
206
207
                tr.active.update + tr.give-addon-notice-tr .notice{
208
					margin: 5px 20px 5px 40px;
209
				}
210
			</style>
211
			<?php
212
	}
213
}
214
add_action( 'admin_head', 'give_admin_quick_css' );
215
216
217
/**
218
 * Set Donation Amount for Multi Level Donation Forms
219
 *
220
 * @param int    $form_id
221
 * @param object $form
0 ignored issues
show
Bug introduced by
There is no parameter named $form. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
222
 *
223
 * @since 1.8.9
224
 *
225
 * @return void
226
 */
227
function give_set_donation_levels_max_min_amount( $form_id ) {
228
	if (
229
		( 'set' === $_POST['_give_price_option'] ) ||
230
		( in_array( '_give_donation_levels', $_POST ) && count( $_POST['_give_donation_levels'] ) <= 0 ) ||
231
		! ( $donation_levels_amounts = wp_list_pluck( $_POST['_give_donation_levels'], '_give_amount' ) )
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
232
	) {
233
		// Delete old meta.
234
		give_delete_meta( $form_id, '_give_levels_minimum_amount' );
235
		give_delete_meta( $form_id, '_give_levels_maximum_amount' );
236
237
		return;
238
	}
239
240
	// Sanitize donation level amounts.
241
	$donation_levels_amounts = array_map( 'give_maybe_sanitize_amount', $donation_levels_amounts );
242
243
	$min_amount = min( $donation_levels_amounts );
244
	$max_amount = max( $donation_levels_amounts );
245
246
	// Set Minimum and Maximum amount for Multi Level Donation Forms
247
	give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount_for_db( $min_amount ) : 0 );
248
	give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount? give_sanitize_amount_for_db( $max_amount ) : 0 );
249
}
250
251
add_action( 'give_pre_process_give_forms_meta', 'give_set_donation_levels_max_min_amount', 30 );
252
253
254
/**
255
 * Save donor address when donation complete
256
 *
257
 * @since 2.0
258
 *
259
 * @param int $payment_id
260
 */
261
function _give_save_donor_billing_address( $payment_id ) {
262
	/* @var Give_Payment $donation */
263
	$donation = new Give_Payment( $payment_id );
264
265
	// Bailout
266
	if ( ! $donation->customer_id ) {
267
		return;
268
	}
269
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
270
271
	/* @var Give_Donor $donor */
272
	$donor = new Give_Donor( $donation->customer_id );
0 ignored issues
show
Documentation introduced by
$donation->customer_id is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
273
	
274
	// Save address.
275
	$donor->add_address( 'billing[]', $donation->address );
276
}
277
add_action( 'save_post_give_payment', '_give_save_donor_billing_address', 9999 );
278