actions.php
7 years ago
backward-compatibility.php
8 years ago
class-give-donor-stats.php
7 years ago
class-give-donor-wall.php
7 years ago
class-give-donors-query.php
7 years ago
frontend-donor-functions.php
7 years ago
actions.php
92 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Insert donor comment to donation. |
| 4 | * |
| 5 | * @since 2.2.0 |
| 6 | * |
| 7 | * @param int $donation_id |
| 8 | * @param array $donation_data |
| 9 | * |
| 10 | */ |
| 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 | |
| 16 | if ( ! empty( $_POST['give_comment'] ) ) { |
| 17 | $comment_id = give_insert_donor_donation_comment( |
| 18 | $donation_id, |
| 19 | $donation_data['user_info']['donor_id'], |
| 20 | trim( $_POST['give_comment'] ), // We are sanitizing comment in Give_comment:add |
| 21 | array( 'comment_author_email' => $donation_data['user_info']['email'] ) |
| 22 | ); |
| 23 | |
| 24 | update_comment_meta( $comment_id, '_give_anonymous_donation', $is_anonymous_donation ); |
| 25 | Give()->donor_meta->update_meta( $donation_data['user_info']['donor_id'], '_give_has_comment', '1' ); |
| 26 | } |
| 27 | |
| 28 | give_update_meta( $donation_id, '_give_anonymous_donation', $is_anonymous_donation ); |
| 29 | Give()->donor_meta->update_meta( $donation_data['user_info']['donor_id'], '_give_anonymous_donor', $is_anonymous_donation ); |
| 30 | } |
| 31 | |
| 32 | add_action( 'give_insert_payment', '__give_insert_donor_donation_comment', 10, 2 ); |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Validate donor comment |
| 37 | * |
| 38 | * @since 2.2.0 |
| 39 | */ |
| 40 | function __give_validate_donor_comment() { |
| 41 | // Check wp_check_comment_data_max_lengths for comment length validation. |
| 42 | if ( ! empty( $_POST['give_comment'] ) ) { |
| 43 | $max_lengths = wp_get_comment_fields_max_lengths(); |
| 44 | $comment = give_clean( $_POST['give_comment'] ); |
| 45 | |
| 46 | if ( mb_strlen( $comment, '8bit' ) > $max_lengths['comment_content'] ) { |
| 47 | give_set_error( 'comment_content_column_length', __( 'Your comment is too long.', 'give' ) ); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | add_action( 'give_checkout_error_checks', '__give_validate_donor_comment', 10, 1 ); |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Update donor comment status when donation status update |
| 56 | * |
| 57 | * @since 2.2.0 |
| 58 | * |
| 59 | * @param $donation_id |
| 60 | * @param $status |
| 61 | */ |
| 62 | function __give_update_donor_donation_comment_status( $donation_id, $status ) { |
| 63 | $approve = absint( 'publish' === $status ); |
| 64 | |
| 65 | /* @var WP_Comment $note */ |
| 66 | $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) ); |
| 67 | |
| 68 | if( $donor_comment instanceof WP_Comment ) { |
| 69 | wp_set_comment_status( $donor_comment->comment_ID, (string) $approve ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | add_action( 'give_update_payment_status', '__give_update_donor_donation_comment_status', 10, 2 ); |
| 74 | |
| 75 | /** |
| 76 | * Remove donor comment when donation delete |
| 77 | * |
| 78 | * @since 2.2.0 |
| 79 | * |
| 80 | * @param $donation_id |
| 81 | */ |
| 82 | function __give_remove_donor_donation_comment( $donation_id ) { |
| 83 | /* @var WP_Comment $note */ |
| 84 | $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) ); |
| 85 | |
| 86 | if( $donor_comment instanceof WP_Comment ) { |
| 87 | wp_delete_comment( $donor_comment->comment_ID ); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | add_action( 'give_payment_deleted', '__give_remove_donor_donation_comment', 10 ); |
| 92 |