actions.php
7 years ago
backward-compatibility.php
7 years ago
class-give-donor-stats.php
7 years ago
class-give-donor-wall.php
6 years ago
class-give-donors-query.php
6 years ago
frontend-donor-functions.php
7 years ago
actions.php
95 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_meta = array( 'author_email' => $donation_data['user_info']['email'] ); |
| 18 | |
| 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 | |
| 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 | |
| 32 | give_update_meta( $donation_id, '_give_anonymous_donation', $is_anonymous_donation ); |
| 33 | } |
| 34 | |
| 35 | add_action( 'give_insert_payment', '__give_insert_donor_donation_comment', 10, 2 ); |
| 36 | |
| 37 | |
| 38 | /** |
| 39 | * Validate donor comment |
| 40 | * |
| 41 | * @since 2.2.0 |
| 42 | */ |
| 43 | function __give_validate_donor_comment() { |
| 44 | // Check wp_check_comment_data_max_lengths for comment length validation. |
| 45 | if ( ! empty( $_POST['give_comment'] ) ) { |
| 46 | $max_lengths = wp_get_comment_fields_max_lengths(); |
| 47 | $comment = give_clean( $_POST['give_comment'] ); |
| 48 | |
| 49 | if ( mb_strlen( $comment, '8bit' ) > $max_lengths['comment_content'] ) { |
| 50 | give_set_error( 'comment_content_column_length', __( 'Your comment is too long.', 'give' ) ); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | add_action( 'give_checkout_error_checks', '__give_validate_donor_comment', 10, 1 ); |
| 55 | |
| 56 | |
| 57 | /** |
| 58 | * Update donor comment status when donation status update |
| 59 | * |
| 60 | * @since 2.2.0 |
| 61 | * |
| 62 | * @param $donation_id |
| 63 | * @param $status |
| 64 | */ |
| 65 | function __give_update_donor_donation_comment_status( $donation_id, $status ) { |
| 66 | $approve = absint( 'publish' === $status ); |
| 67 | |
| 68 | /* @var WP_Comment $note */ |
| 69 | $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) ); |
| 70 | |
| 71 | if( $donor_comment instanceof WP_Comment ) { |
| 72 | wp_set_comment_status( $donor_comment->comment_ID, (string) $approve ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | add_action( 'give_update_payment_status', '__give_update_donor_donation_comment_status', 10, 2 ); |
| 77 | |
| 78 | /** |
| 79 | * Remove donor comment when donation delete |
| 80 | * |
| 81 | * @since 2.2.0 |
| 82 | * |
| 83 | * @param $donation_id |
| 84 | */ |
| 85 | function __give_remove_donor_donation_comment( $donation_id ) { |
| 86 | /* @var WP_Comment $note */ |
| 87 | $donor_comment = give_get_donor_donation_comment( $donation_id, give_get_payment_donor_id( $donation_id ) ); |
| 88 | |
| 89 | if( $donor_comment instanceof WP_Comment ) { |
| 90 | wp_delete_comment( $donor_comment->comment_ID ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | add_action( 'give_payment_deleted', '__give_remove_donor_donation_comment', 10 ); |
| 95 |