PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
← All changes | includes/donors/actions.php +49 -33 2.3.0 → 4.18.0 View file →
@@ -1,47 +1,37 @@
1 1 <?php
2 +
3 +use Give\Framework\PaymentGateways\PaymentGatewayRegister;
4 +
2 5 /**
3 6 * Insert donor comment to donation.
4 7 *
8 + * @since 4.9.0 rename function - PHP 8 compatibility
9 + * @since 2.21.0 remove anonymous
5 10 * @since 2.2.0
6 11 *
7 - * @param int $donation_id
8 - * @param array $donation_data
9 - *
12 + * @param int $donation_id
13 + * @param array $donation_data
10 14 */
11 -function __give_insert_donor_donation_comment( $donation_id, $donation_data ) {
12 - $is_anonymous_donation = isset( $_POST['give_anonymous_donation'] )
13 - ? absint( $_POST['give_anonymous_donation'] )
14 - : 0;
15 -
15 +function _give_insert_donor_donation_comment( $donation_id, $donation_data ) {
16 16 if ( ! empty( $_POST['give_comment'] ) ) {
17 - $comment_meta = array( 'author_email' => $donation_data['user_info']['email'] );
17 + $donation = give()->donations->getById($donation_id);
18 + $donation->comment = sanitize_textarea_field(trim($_POST['give_comment']));
19 + $donation->save();
20 + }
21 +}
18 22
19 - if( ! give_has_upgrade_completed('v230_move_donation_note' ) ) {
20 - // Backward compatibility.
21 - $comment_meta = array( 'comment_author_email' => $donation_data['user_info']['email'] );
22 - }
23 +add_action( 'give_insert_payment', '_give_insert_donor_donation_comment', 10, 2 );
23 24
24 - $comment_id = give_insert_donor_donation_comment(
25 - $donation_id,
26 - $donation_data['user_info']['donor_id'],
27 - trim( $_POST['give_comment'] ), // We are sanitizing comment in Give_comment:add
28 - $comment_meta
29 - );
30 - }
31 25
32 - give_update_meta( $donation_id, '_give_anonymous_donation', $is_anonymous_donation );
33 -}
34 26
35 -add_action( 'give_insert_payment', '__give_insert_donor_donation_comment', 10, 2 );
36 -
37 -
38 27 /**
39 28 * Validate donor comment
40 29 *
30 + * @since 4.9.0 rename function - PHP 8 compatibility
41 31 * @since 2.2.0
42 32 */
43 -function __give_validate_donor_comment() {
33 +function give_validate_donor_comment() {
44 34 // Check wp_check_comment_data_max_lengths for comment length validation.
45 35 if ( ! empty( $_POST['give_comment'] ) ) {
46 36 $max_lengths = wp_get_comment_fields_max_lengths();
47 37 $comment = give_clean( $_POST['give_comment'] );
@@ -50,45 +40,71 @@
50 40 give_set_error( 'comment_content_column_length', __( 'Your comment is too long.', 'give' ) );
51 41 }
52 42 }
53 43 }
54 -add_action( 'give_checkout_error_checks', '__give_validate_donor_comment', 10, 1 );
44 +add_action( 'give_checkout_error_checks', 'give_validate_donor_comment', 10, 1 );
55 45
56 46
57 47 /**
58 48 * Update donor comment status when donation status update
59 49 *
50 + * @since 4.9.0 rename function - PHP 8 compatibility
60 51 * @since 2.2.0
61 52 *
62 53 * @param $donation_id
63 54 * @param $status
64 55 */
65 -function __give_update_donor_donation_comment_status( $donation_id, $status ) {
56 +function give_update_donor_donation_comment_status( $donation_id, $status ) {
66 57 $approve = absint( 'publish' === $status );
67 58
68 59 /* @var WP_Comment $note */
69 60 $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) );
70 61
71 - if( $donor_comment instanceof WP_Comment ) {
62 + if ( $donor_comment instanceof WP_Comment ) {
72 63 wp_set_comment_status( $donor_comment->comment_ID, (string) $approve );
73 64 }
74 65 }
75 66
76 -add_action( 'give_update_payment_status', '__give_update_donor_donation_comment_status', 10, 2 );
67 +add_action( 'give_update_payment_status', 'give_update_donor_donation_comment_status', 10, 2 );
77 68
78 69 /**
79 70 * Remove donor comment when donation delete
80 71 *
72 + * @since 4.9.0 rename function - PHP 8 compatibility
81 73 * @since 2.2.0
82 74 *
83 75 * @param $donation_id
84 76 */
85 -function __give_remove_donor_donation_comment( $donation_id ) {
77 +function give_remove_donor_donation_comment( $donation_id ) {
86 78 /* @var WP_Comment $note */
87 79 $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) );
88 80
89 - if( $donor_comment instanceof WP_Comment ) {
81 + if ( $donor_comment instanceof WP_Comment ) {
90 82 wp_delete_comment( $donor_comment->comment_ID );
91 83 }
92 84 }
93 85
94 -add_action( 'give_payment_deleted', '__give_remove_donor_donation_comment', 10 );
86 +add_action( 'give_payment_deleted', 'give_remove_donor_donation_comment', 10 );
87 +
88 +
89 +/**
90 + * Update anonymous donation for legacy gateways
91 + *
92 + * @since 2.21.3
93 + *
94 + * @retrun void
95 + */
96 +function giveUpdateAnonymousDonationForLegacyGateways(int $donationId)
97 +{
98 + $gatewayId = give_get_meta($donationId,'_give_payment_gateway', true);
99 +
100 + /** @var PaymentGatewayRegister $registrar */
101 + $registrar = give(PaymentGatewayRegister::class);
102 +
103 + if (!$registrar->hasPaymentGateway($gatewayId)){
104 + $isAnonymousDonation = isset( $_POST['give_anonymous_donation'] ) ? absint( give_clean($_POST['give_anonymous_donation']) ) : 0;
105 +
106 + give_update_meta( $donationId, '_give_anonymous_donation', $isAnonymousDonation );
107 + }
108 +}
109 +
110 +add_action('give_insert_payment', 'giveUpdateAnonymousDonationForLegacyGateways');