This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 Payment Actions |
||
4 | * |
||
5 | * @package Give |
||
6 | * @subpackage Admin/Payments |
||
7 | * @copyright Copyright (c) 2016, GiveWP |
||
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 | * |
||
19 | * Process the payment details edit |
||
20 | * |
||
21 | * @since 1.0 |
||
22 | * @access private |
||
23 | * |
||
24 | * @param array $data Donation data. |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | function give_update_payment_details( $data ) { |
||
29 | |||
30 | View Code Duplication | if ( ! current_user_can( 'edit_give_payments', $data['give_payment_id'] ) ) { |
|
0 ignored issues
–
show
|
|||
31 | wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
||
32 | } |
||
33 | |||
34 | check_admin_referer( 'give_update_payment_details_nonce' ); |
||
35 | |||
36 | // Retrieve the payment ID. |
||
37 | $payment_id = absint( $data['give_payment_id'] ); |
||
38 | |||
39 | /* @var Give_Payment $payment */ |
||
40 | $payment = new Give_Payment( $payment_id ); |
||
41 | |||
42 | $status = $data['give-payment-status']; |
||
43 | $hour = sanitize_text_field( $data['give-payment-time-hour'] ); |
||
44 | |||
45 | // Restrict to our high and low. |
||
46 | if ( $hour > 23 ) { |
||
47 | $hour = 23; |
||
48 | } elseif ( $hour < 0 ) { |
||
49 | $hour = 00; |
||
50 | } |
||
51 | |||
52 | $minute = sanitize_text_field( $data['give-payment-time-min'] ); |
||
53 | |||
54 | // Restrict to our high and low. |
||
55 | if ( $minute > 59 ) { |
||
56 | $minute = 59; |
||
57 | } elseif ( $minute < 0 ) { |
||
58 | $minute = 00; |
||
59 | } |
||
60 | |||
61 | $address = give_clean( $data['give-payment-address'][0] ); |
||
62 | |||
63 | $curr_total = $payment->total; |
||
64 | $new_total = give_maybe_sanitize_amount( ( ! empty( $data['give-payment-total'] ) ? $data['give-payment-total'] : 0 ) ); |
||
65 | $date = give_get_formatted_date(sanitize_text_field( $data['give-payment-date'] ), 'Y-m-d' ) . ' ' . $hour . ':' . $minute . ':00'; |
||
0 ignored issues
–
show
|
|||
66 | |||
67 | $curr_donor_id = sanitize_text_field( $data['give-current-donor'] ); |
||
68 | $new_donor_id = sanitize_text_field( $data['donor-id'] ); |
||
69 | |||
70 | /** |
||
71 | * Fires before updating edited donation. |
||
72 | * |
||
73 | * @since 1.0 |
||
74 | * @since 1.8.9 Changes hook name give_update_edited_purchase -> give_update_edited_donation |
||
75 | * |
||
76 | * @param int $payment_id The ID of the payment. |
||
77 | */ |
||
78 | do_action( 'give_update_edited_donation', $payment_id ); |
||
79 | |||
80 | $payment->date = $date; |
||
81 | $payment->anonymous = isset( $data['give_anonymous_donation'] ) ? absint( $data['give_anonymous_donation'] ) : 0; |
||
82 | |||
0 ignored issues
–
show
|
|||
83 | |||
84 | $updated = $payment->save(); |
||
85 | |||
86 | if ( 0 === $updated ) { |
||
87 | wp_die( __( 'Error Updating Donation.', 'give' ), __( 'Error', 'give' ), array( 'response' => 400 ) ); |
||
88 | } |
||
89 | |||
90 | $donor_changed = false; |
||
91 | |||
92 | if ( isset( $data['give-new-donor'] ) && $data['give-new-donor'] == '1' ) { |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | $email = ! empty( $data['give-new-donor-email'] ) ? sanitize_text_field( $data['give-new-donor-email'] ) : ''; |
||
95 | $first_name = ! empty( $data['give-new-donor-first-name'] ) ? sanitize_text_field( $data['give-new-donor-first-name'] ) : ''; |
||
96 | $last_name = ! empty( $data['give-new-donor-last-name'] ) ? sanitize_text_field( $data['give-new-donor-last-name'] ) : ''; |
||
97 | $names = strip_tags( wp_unslash( trim( "{$first_name} {$last_name}" ) ) ); |
||
98 | |||
99 | if ( empty( $email ) || empty( $first_name ) ) { |
||
100 | wp_die( __( 'New Donor requires first name and email address.', 'give' ), __( 'Error', 'give' ), array( 'response' => 400 ) ); |
||
101 | } |
||
102 | |||
103 | $donor = new Give_Donor( $email ); |
||
104 | if ( empty( $donor->id ) ) { |
||
105 | $donor_data = array( 'name' => $names, 'email' => $email ); |
||
106 | $user_id = email_exists( $email ); |
||
107 | if ( false !== $user_id ) { |
||
108 | $donor_data['user_id'] = $user_id; |
||
109 | } |
||
110 | |||
111 | if ( ! $donor->create( $donor_data ) ) { |
||
0 ignored issues
–
show
The expression
$donor->create($donor_data) of type false|integer is loosely compared to false ; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
112 | // Failed to create the new donor, assume the previous donor. |
||
113 | $donor_changed = false; |
||
0 ignored issues
–
show
$donor_changed is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
114 | $donor = new Give_Donor( $curr_donor_id ); |
||
115 | give_set_error( 'give-payment-new-donor-fail', __( 'Error creating new donor.', 'give' ) ); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | // Create and Update Donor First Name and Last Name in Meta Fields. |
||
120 | $donor->update_meta( '_give_donor_first_name', $first_name ); |
||
121 | $donor->update_meta( '_give_donor_last_name', $last_name ); |
||
122 | |||
123 | $new_donor_id = $donor->id; |
||
0 ignored issues
–
show
$new_donor_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
124 | |||
125 | $previous_donor = new Give_Donor( $curr_donor_id ); |
||
126 | |||
127 | $donor_changed = true; |
||
128 | |||
129 | } elseif ( $curr_donor_id !== $new_donor_id ) { |
||
130 | |||
131 | $donor = new Give_Donor( $new_donor_id ); |
||
132 | $email = $donor->email; |
||
0 ignored issues
–
show
$email is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
133 | $names = $donor->name; |
||
0 ignored issues
–
show
$names is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
134 | |||
135 | $previous_donor = new Give_Donor( $curr_donor_id ); |
||
136 | |||
137 | $donor_changed = true; |
||
138 | |||
139 | } else { |
||
140 | $donor = new Give_Donor( $curr_donor_id ); |
||
141 | $email = $donor->email; |
||
0 ignored issues
–
show
$email is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
142 | $names = $donor->name; |
||
0 ignored issues
–
show
$names is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
143 | } |
||
144 | |||
145 | if ( $donor_changed ) { |
||
146 | |||
147 | // Setup first and last name from input values. |
||
148 | $first_name = $donor->get_first_name(); |
||
149 | $last_name = $donor->get_last_name(); |
||
150 | |||
151 | $payment->first_name = $first_name; |
||
152 | $payment->last_name = $last_name; |
||
153 | |||
154 | // Remove the stats and payment from the previous donor and attach it to the new donor. |
||
155 | $previous_donor->remove_payment( $payment_id, false ); |
||
156 | $donor->attach_payment( $payment_id, false ); |
||
157 | |||
158 | if ( 'publish' == $status ) { |
||
159 | |||
160 | // Reduce previous user donation count and amount. |
||
161 | $previous_donor->decrease_donation_count(); |
||
162 | $previous_donor->decrease_value( $curr_total ); |
||
163 | |||
164 | // If donation was completed adjust stats of new donors. |
||
165 | $donor->increase_purchase_count(); |
||
166 | $donor->increase_value( $new_total ); |
||
167 | } |
||
168 | |||
169 | $payment->customer_id = $donor->id; |
||
170 | } else { |
||
171 | |||
172 | if ( 'publish' === $status ) { |
||
173 | // Update user donation stat. |
||
174 | $donor->update_donation_value( $curr_total, $new_total ); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | // Set new meta values. |
||
179 | $payment->user_id = $donor->user_id; |
||
180 | $payment->email = $donor->email; |
||
181 | $payment->address = $address; |
||
0 ignored issues
–
show
It seems like
$address can also be of type string . However, the property $address is declared as type array . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
182 | $payment->total = $new_total; |
||
0 ignored issues
–
show
It seems like
$new_total can also be of type integer or string . However, the property $total is declared as type double . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
183 | |||
184 | // Check for payment notes. |
||
185 | if ( ! empty( $data['give-payment-note'] ) ) { |
||
186 | |||
187 | $note = wp_kses( $data['give-payment-note'], array() ); |
||
188 | give_insert_payment_note( $payment_id, $note ); |
||
189 | |||
190 | } |
||
191 | |||
192 | // Set new status. |
||
193 | $payment->status = $status; |
||
194 | |||
195 | // Adjust total store earnings if the payment total has been changed. |
||
196 | if ( $new_total !== $curr_total && 'publish' == $status ) { |
||
197 | |||
198 | if ( $new_total > $curr_total ) { |
||
199 | // Increase if our new total is higher. |
||
200 | $difference = $new_total - $curr_total; |
||
201 | give_increase_total_earnings( $difference ); |
||
202 | |||
203 | // Increase form earnings. |
||
204 | give_increase_earnings( $payment->form_id, $difference, $payment->ID ); |
||
205 | } elseif ( $curr_total > $new_total ) { |
||
206 | // Decrease if our new total is lower. |
||
207 | $difference = $curr_total - $new_total; |
||
208 | give_decrease_total_earnings( $difference ); |
||
209 | |||
210 | // Decrease form earnings. |
||
211 | give_decrease_form_earnings( $payment->form_id, $difference, $payment->ID ); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | $payment->save(); |
||
216 | |||
217 | // Get new give form ID. |
||
218 | $new_form_id = absint( $data['give-payment-form-select'] ); |
||
219 | $current_form_id = absint( $payment->get_meta( '_give_payment_form_id' ) ); |
||
220 | |||
221 | // We are adding payment transfer code in last to remove any conflict with above functionality. |
||
222 | // For example: above code will automatically handle form stat (increase/decrease) when payment status changes. |
||
223 | // Check if user want to transfer current payment to new give form id. |
||
224 | if ( $new_form_id && $new_form_id != $current_form_id ) { |
||
225 | |||
226 | // Get new give form title. |
||
227 | $new_form_title = get_the_title( $new_form_id ); |
||
228 | |||
229 | // Update payment give form meta data. |
||
230 | $payment->update_meta( '_give_payment_form_id', $new_form_id ); |
||
231 | $payment->update_meta( '_give_payment_form_title', $new_form_title ); |
||
232 | |||
233 | // Update price id payment metadata. |
||
234 | if ( ! give_has_variable_prices( $new_form_id ) ) { |
||
235 | $payment->update_meta( '_give_payment_price_id', '' ); |
||
236 | } |
||
237 | |||
238 | // If donation was completed, adjust stats of forms. |
||
239 | if ( 'publish' == $status ) { |
||
240 | |||
241 | // Decrease sale of old give form. For other payment status. |
||
242 | $current_form = new Give_Donate_Form( $current_form_id ); |
||
243 | $current_form->decrease_sales(); |
||
244 | $current_form->decrease_earnings( $curr_total, $payment->ID ); |
||
245 | |||
246 | // Increase sale of new give form. |
||
247 | $new_form = new Give_Donate_Form( $new_form_id ); |
||
248 | $new_form->increase_sales(); |
||
249 | $new_form->increase_earnings( $new_total, $payment->ID ); |
||
250 | } |
||
251 | |||
252 | // Re setup payment to update new meta value in object. |
||
253 | $payment->update_payment_setup( $payment->ID ); |
||
254 | |||
255 | // Update form id in payment logs. |
||
256 | Give()->async_process->data( array( |
||
257 | 'data' => array( $new_form_id, $payment_id ), |
||
258 | 'hook' => 'give_update_log_form_id', |
||
259 | ) )->dispatch(); |
||
260 | } |
||
261 | |||
262 | // Update price id if current form is variable form. |
||
263 | /* @var Give_Donate_Form $form */ |
||
264 | $form = new Give_Donate_Form( $payment->form_id ); |
||
265 | |||
266 | if ( isset( $data['give-variable-price'] ) && $form->has_variable_prices() ) { |
||
267 | |||
268 | // Get payment meta data. |
||
269 | $payment_meta = $payment->get_meta(); |
||
270 | |||
271 | $price_info = array(); |
||
272 | $price_id = ''; |
||
273 | |||
274 | // Get price info |
||
275 | if( 0 <= $data['give-variable-price'] ) { |
||
0 ignored issues
–
show
|
|||
276 | foreach ( $form->prices as $variable_price ) { |
||
277 | if( $new_total === give_maybe_sanitize_amount( $variable_price['_give_amount'] ) ) { |
||
0 ignored issues
–
show
|
|||
278 | $price_info = $variable_price; |
||
279 | break; |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | |||
284 | // Set price id. |
||
285 | if( ! empty( $price_info ) ) { |
||
0 ignored issues
–
show
|
|||
286 | $price_id = $data['give-variable-price']; |
||
287 | |||
288 | if( $data['give-variable-price'] !== $price_info['_give_id']['level_id'] ) { |
||
0 ignored issues
–
show
|
|||
289 | // Set price id to amount match. |
||
290 | $price_id = $price_info['_give_id']['level_id']; |
||
291 | } |
||
0 ignored issues
–
show
|
|||
292 | |||
293 | } elseif( $form->is_custom_price_mode() ){ |
||
0 ignored issues
–
show
|
|||
294 | $price_id = 'custom'; |
||
295 | } |
||
296 | |||
297 | // Update payment meta data. |
||
298 | $payment_meta['price_id'] = $price_id; |
||
299 | |||
300 | // Update payment give form meta data. |
||
301 | $payment->update_meta( '_give_payment_price_id', $price_id ); |
||
302 | $payment->update_meta( '_give_payment_meta', $payment_meta ); |
||
303 | |||
304 | // Re setup payment to update new meta value in object. |
||
305 | $payment->update_payment_setup( $payment->ID ); |
||
306 | } |
||
307 | |||
308 | $comment_id = isset( $data['give_comment_id'] ) ? absint( $data['give_comment_id'] ) : 0; |
||
309 | $has_anonymous_setting_field = give_is_anonymous_donation_field_enabled( $payment->form_id ); |
||
310 | |||
311 | if ( $has_anonymous_setting_field ) { |
||
312 | give_update_meta( $payment->ID, '_give_anonymous_donation', $payment->anonymous ); |
||
313 | } |
||
314 | |||
315 | // Update comment. |
||
316 | if ( give_is_donor_comment_field_enabled( $payment->form_id ) ) { |
||
317 | // We are access comment directly from $_POST because comment formatting remove because of give_clean in give_post_actions. |
||
318 | $data['give_comment'] = trim( $_POST['give_comment'] ); |
||
0 ignored issues
–
show
|
|||
319 | |||
320 | if ( empty( $data['give_comment'] ) ) { |
||
321 | // Delete comment if empty |
||
322 | Give_Comment::delete( $comment_id, $payment_id, 'payment' ); |
||
323 | $comment_id = 0; |
||
0 ignored issues
–
show
$comment_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
324 | |||
325 | } else { |
||
326 | $comment_args = array( |
||
327 | 'comment_author_email' => $payment->email |
||
328 | ); |
||
329 | |||
330 | if ( $comment_id ) { |
||
331 | $comment_args['comment_ID'] = $comment_id; |
||
332 | } |
||
333 | |||
334 | $comment_id = give_insert_donor_donation_comment( |
||
0 ignored issues
–
show
$comment_id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
335 | $payment->ID, |
||
336 | $payment->donor_id, |
||
337 | $data['give_comment'], |
||
338 | $comment_args |
||
339 | ); |
||
340 | } |
||
341 | } |
||
342 | |||
343 | // Check if payment status is not completed then update the goal progress for donation form. |
||
344 | if ( 'publish' !== $status ) { |
||
345 | give_update_goal_progress( $form->ID ); |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Fires after updating edited donation. |
||
350 | * |
||
351 | * @since 1.0 |
||
352 | * @since 1.8.9 Changes hook name give_updated_edited_purchase -> give_updated_edited_donation |
||
353 | * |
||
354 | * @param int $payment_id The ID of the payment. |
||
355 | */ |
||
356 | do_action( 'give_updated_edited_donation', $payment_id ); |
||
357 | |||
358 | wp_safe_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&give-messages[]=payment-updated&id=' . $payment_id ) ); |
||
359 | exit; |
||
360 | } |
||
361 | |||
362 | add_action( 'give_update_payment_details', 'give_update_payment_details' ); |
||
363 | |||
364 | /** |
||
365 | * Trigger a Donation Deletion. |
||
366 | * |
||
367 | * @since 1.0 |
||
368 | * |
||
369 | * @param array $data Arguments passed. |
||
370 | * |
||
371 | * @return void |
||
372 | */ |
||
373 | function give_trigger_donation_delete( $data ) { |
||
374 | if ( wp_verify_nonce( $data['_wpnonce'], 'give_donation_nonce' ) ) { |
||
375 | |||
376 | $payment_id = absint( $data['purchase_id'] ); |
||
377 | |||
378 | if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
||
379 | wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
||
380 | } |
||
381 | |||
382 | give_delete_donation( $payment_id ); |
||
383 | wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&give-messages[]=donation-deleted' ) ); |
||
384 | give_die(); |
||
385 | } |
||
386 | } |
||
387 | |||
388 | add_action( 'give_delete_payment', 'give_trigger_donation_delete' ); |
||
389 | |||
390 | /** |
||
391 | * AJAX Store Donation Note |
||
392 | */ |
||
393 | function give_ajax_store_payment_note() { |
||
394 | $payment_id = absint( $_POST['payment_id'] ); |
||
0 ignored issues
–
show
|
|||
395 | $note = wp_kses( $_POST['note'], array() ); |
||
0 ignored issues
–
show
|
|||
396 | $note_type = give_clean( $_POST['type'] ); |
||
0 ignored issues
–
show
|
|||
397 | |||
398 | if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
||
399 | wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
||
400 | } |
||
401 | |||
402 | if ( empty( $payment_id ) || empty( $note ) ) { |
||
403 | die( '-1' ); |
||
404 | } |
||
405 | |||
406 | if ( ! give_has_upgrade_completed( 'v230_move_donor_note' ) ) { |
||
407 | // Backward compatibility. |
||
408 | $note_id = give_insert_payment_note( $payment_id, $note ); |
||
409 | View Code Duplication | } else { |
|
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. ![]() |
|||
410 | $note_id = Give()->comment->db->add( |
||
411 | array( |
||
412 | 'comment_parent' => $payment_id, |
||
413 | 'user_id' => get_current_user_id(), |
||
414 | 'comment_content' => $note, |
||
415 | 'comment_type' => 'donation', |
||
416 | ) |
||
417 | ); |
||
418 | } |
||
419 | |||
420 | if( $note_id && $note_type ) { |
||
0 ignored issues
–
show
|
|||
421 | |||
422 | if( ! give_has_upgrade_completed('v230_move_donor_note' ) ) { |
||
0 ignored issues
–
show
|
|||
423 | add_comment_meta( $note_id, 'note_type', $note_type, true ); |
||
424 | } else{ |
||
0 ignored issues
–
show
|
|||
425 | Give()->comment->db_meta->update_meta( $note_id, 'note_type', $note_type ); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Fire the action |
||
430 | * |
||
431 | * @since 2.3.0 |
||
432 | */ |
||
433 | do_action( 'give_donor-note_email_notification', $note_id, $payment_id ); |
||
434 | } |
||
435 | |||
436 | die( give_get_payment_note_html( $note_id ) ); |
||
437 | } |
||
438 | |||
439 | add_action( 'wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note' ); |
||
440 | |||
441 | /** |
||
442 | * Triggers a donation note deletion without ajax |
||
443 | * |
||
444 | * @since 1.0 |
||
445 | * |
||
446 | * @param array $data Arguments passed |
||
447 | * |
||
448 | * @return void |
||
449 | */ |
||
450 | function give_trigger_payment_note_deletion( $data ) { |
||
451 | |||
452 | if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_delete_payment_note_' . $data['note_id'] ) ) { |
||
453 | return; |
||
454 | } |
||
455 | |||
456 | View Code Duplication | if ( ! current_user_can( 'edit_give_payments', $data['payment_id'] ) ) { |
|
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. ![]() |
|||
457 | wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
||
458 | } |
||
459 | |||
460 | $edit_order_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&give-messages[]=donation-note-deleted&id=' . absint( $data['payment_id'] ) ); |
||
461 | |||
462 | give_delete_payment_note( $data['note_id'], $data['payment_id'] ); |
||
463 | |||
464 | wp_redirect( $edit_order_url ); |
||
465 | } |
||
466 | |||
467 | add_action( 'give_delete_payment_note', 'give_trigger_payment_note_deletion' ); |
||
468 | |||
469 | /** |
||
470 | * Delete a payment note deletion with ajax |
||
471 | * |
||
472 | * @since 1.0 |
||
473 | * |
||
474 | * @return void |
||
475 | */ |
||
476 | function give_ajax_delete_payment_note() { |
||
477 | |||
478 | View Code Duplication | if ( ! current_user_can( 'edit_give_payments', $_POST['payment_id'] ) ) { |
|
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. ![]() |
|||
479 | wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
||
480 | } |
||
481 | |||
482 | if ( give_delete_payment_note( $_POST['note_id'], $_POST['payment_id'] ) ) { |
||
0 ignored issues
–
show
|
|||
483 | die( '1' ); |
||
484 | } else { |
||
485 | die( '-1' ); |
||
486 | } |
||
487 | |||
488 | } |
||
489 | |||
490 | add_action( 'wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note' ); |
||
491 |
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.