PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.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 2.3.2 All 256 releases
← All changes | includes/admin/emails/abstract-email-notification.php +100 -77 2.3.0 → 4.17.0 View file →
@@ -5,9 +5,9 @@
5 5 * This class handles all email notification settings.
6 6 *
7 7 * @package Give
8 8 * @subpackage Classes/Emails
9 - * @copyright Copyright (c) 2016, WordImpress
9 + * @copyright Copyright (c) 2016, GiveWP
10 10 * @license https://opensource.org/licenses/gpl-license GNU Public License
11 11 * @since 2.0
12 12 */
13 13
@@ -131,12 +131,15 @@
131 131 // Set email preview header status.
132 132 $this->config['has_preview_header'] = $this->config['has_preview'] && $this->config['has_preview_header'] ? true : false;
133 133
134 134 // Set email content type
135 - $this->config['content_type'] = empty( $this->config['content_type'] ) || ! in_array( $this->config['content_type'], array(
136 - 'text/html',
137 - 'text/plain',
138 - ) )
135 + $this->config['content_type'] = empty( $this->config['content_type'] ) || ! in_array(
136 + $this->config['content_type'],
137 + array(
138 + 'text/html',
139 + 'text/plain',
140 + )
141 + )
139 142 ? Give()->emails->get_content_type()
140 143 : $this->config['content_type'];
141 144 $this->config['content_type'] = give_get_option( Give_Email_Setting_Field::get_prefix( $this ) . 'email_content_type', $this->config['content_type'] );
142 145
@@ -176,10 +179,15 @@
176 179 * @since 2.0
177 180 * @access public
178 181 */
179 182 private function setup_filters() {
183 + // Do not setup filters if not admin.
184 + if ( ! is_admin() ) {
185 + return;
186 + }
187 +
180 188 // Apply filter only for current email notification section.
181 - if ( give_get_current_setting_section() === $this->config['id'] ) {
189 + if ( isset( $_GET['section'] ) && give_get_current_setting_section() === $this->config['id'] ) {
182 190 // Initialize email context for email notification.
183 191 $this->config['email_tag_context'] = apply_filters(
184 192 "give_{$this->config['id']}_email_tag_context",
185 193 $this->config['email_tag_context'],
@@ -187,9 +195,9 @@
187 195 );
188 196 }
189 197
190 198 // Setup setting fields.
191 - if( $this->config['show_on_emails_setting_page'] ) {
199 + if ( $this->config['show_on_emails_setting_page'] ) {
192 200 add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
193 201 }
194 202
195 203 if ( $this->config['form_metabox_setting'] && ! empty( $this->config['form_metabox_id'] ) ) {
@@ -200,14 +208,14 @@
200 208 2
201 209 );
202 210 }
203 211
204 - if( $this->config['has_recipient_field'] ) {
212 + if ( $this->config['has_recipient_field'] ) {
205 213 add_action(
206 - "give_save__give_{$this->config['id']}_recipient",
207 - array( $this, 'validate_form_recipient_field_value' ),
208 - 10,
209 - 3
214 + "give_save__give_{$this->config['id']}_recipient",
215 + array( $this, 'validate_form_recipient_field_value' ),
216 + 10,
217 + 3
210 218 );
211 219 }
212 220
213 221 /**
@@ -320,9 +328,9 @@
320 328 * @return array
321 329 */
322 330 public function add_metabox_setting_field( $settings, $form_id ) {
323 331
324 - if( Give_Email_Notification_Util::is_email_notification_active( $this ) ) {
332 + if ( Give_Email_Notification_Util::is_email_notification_active( $this ) ) {
325 333 $settings[] = array(
326 334 'id' => $this->config['id'],
327 335 'title' => $this->config['label'],
328 336 'fields' => $this->get_setting_fields( $form_id ),
@@ -362,14 +370,13 @@
362 370 */
363 371 public function get_recipient( $form_id = null ) {
364 372 if ( empty( $this->recipient_email ) && $this->config['has_recipient_field'] ) {
365 373 $this->recipient_email = Give_Email_Notification_Util::get_value(
366 - $this,
367 - Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'recipient',
368 - $form_id
374 + $this,
375 + Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'recipient',
376 + $form_id
369 377 );
370 378
371 -
372 379 /**
373 380 * Filter the admin notice emails.
374 381 *
375 382 * @since 1.0
@@ -561,9 +568,9 @@
561 568 public function get_email_template( $form_id ) {
562 569 $email_template = give_get_meta( $form_id, '_give_email_template', true );
563 570 $email_template = Give_Email_Notification_Util::get_value(
564 571 $this,
565 - Give_Email_Setting_Field::get_prefix( $this, $form_id ) .'email_template',
572 + Give_Email_Setting_Field::get_prefix( $this, $form_id ) . 'email_template',
566 573 $form_id,
567 574 ! empty( $email_template ) && Give_Email_Notification_Util::can_use_form_email_options( $this, $form_id ) ?
568 575 $email_template :
569 576 $this->config['email_template']
@@ -621,9 +628,10 @@
621 628 }
622 629 }
623 630 }
624 631
625 - if ( count( $email_tags ) && $formatted ) : ob_start() ?>
632 + if ( count( $email_tags ) && $formatted ) :
633 + ob_start() ?>
626 634 <ul class="give-email-tags-wrap">
627 635 <?php foreach ( $email_tags as $email_tag ) : ?>
628 636 <li class="give_<?php echo $email_tag['tag']; ?>_tag">
629 637 <code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['desc']; ?>
@@ -686,8 +694,9 @@
686 694 /**
687 695 * Send preview email.
688 696 *
689 697 * @since 2.0
698 + * @since 2.15.0 Preview email recipient is now the current user.
690 699 * @access public
691 700 *
692 701 * @param bool $send Flag to check if send email or not.
693 702 *
@@ -727,11 +736,13 @@
727 736 Give()->emails->from_name = give_get_meta( $form_id, '_give_from_name', true );
728 737 Give()->emails->from_address = give_get_meta( $form_id, '_give_from_email', true );
729 738 }
730 739
731 - return $send
732 - ? Give()->emails->send( $this->get_preview_email_recipient( $form_id ), $subject, $message, $attachments )
733 - : false;
740 + if( $send ) {
741 + Give()->emails->send( wp_get_current_user()->user_email, $subject, $message, $attachments );
742 + }
743 +
744 + return false;
734 745 }
735 746
736 747
737 748 /**
@@ -775,10 +786,9 @@
775 786 $form_id = ! empty( $email_tag_args['form_id'] )
776 787 ? absint( $email_tag_args['form_id'] )
777 788 : ( ! empty( $email_tag_args['payment_id'] ) ? give_get_payment_form_id( $email_tag_args['payment_id'] ) : null );
778 789
779 -
780 - // Do not send email if notification is disable.
790 + // Do not send email if notification is disabled.
781 791 if ( ! Give_Email_Notification_Util::is_email_notification_active( $this, $form_id ) ) {
782 792 return false;
783 793 }
784 794
@@ -832,81 +842,92 @@
832 842
833 843 /**
834 844 * Decode preview email template tags.
835 845 *
846 + * @since 2.14.0 display payment sequential number as id
836 847 * @since 2.0
837 848 *
838 - * @param string $message
849 + * @param string $message Email Template Message.
839 850 *
840 851 * @return string
841 852 */
842 853 public function preview_email_template_tags( $message ) {
854 +
855 + $get_data = give_clean( filter_input_array( INPUT_GET ) );
856 +
843 857 // Set Payment.
844 - $payment_id = give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'preview_id' );
858 + $payment_id = give_check_variable( $get_data, 'isset_empty', 0, 'preview_id' );
845 859 $payment = $payment_id ? new Give_Payment( $payment_id ) : new stdClass();
846 860
847 861 // Set donor.
848 862 $user_id = $payment_id
849 863 ? $payment->user_id
850 - : give_check_variable( give_clean( $_GET ), 'isset_empty', 0, 'user_id' );
864 + : give_check_variable( $get_data, 'isset_empty', 0, 'user_id' );
851 865 $user_id = $user_id ? $user_id : wp_get_current_user()->ID;
852 866
853 - // Set receipt.
854 - $receipt_id = strtolower( md5( uniqid() ) );
867 + $receipt_link_url = give_get_receipt_url( $payment_id );
868 + $receipt_link = give_get_receipt_link( $payment_id );
855 869
856 - $receipt_link_url = esc_url( add_query_arg( array(
857 - 'payment_key' => $receipt_id,
858 - ), give_get_history_page_uri() ) );
859 -
860 - $receipt_link = sprintf(
861 - '<a href="%1$s">%2$s</a>',
862 - $receipt_link_url,
863 - esc_html__( 'View the receipt in your browser &raquo;', 'give' )
864 - );
865 -
866 870 // Set default values for tags.
867 871 $this->config['preview_email_tags_values'] = wp_parse_args(
868 872 $this->config['preview_email_tags_values'],
869 873 array(
870 - 'name' => give_email_tag_first_name( array(
871 - 'payment_id' => $payment_id,
872 - 'user_id' => $user_id,
873 - ) ),
874 - 'fullname' => give_email_tag_fullname( array(
875 - 'payment_id' => $payment_id,
876 - 'user_id' => $user_id,
877 - ) ),
878 - 'username' => give_email_tag_username( array(
879 - 'payment_id' => $payment_id,
880 - 'user_id' => $user_id,
881 - ) ),
882 - 'user_email' => give_email_tag_user_email( array(
883 - 'payment_id' => $payment_id,
884 - 'user_id' => $user_id,
885 - ) ),
886 - 'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
887 - 'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
888 - 'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
889 - 'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
890 - 'receipt_id' => $receipt_id,
891 - 'payment_id' => $payment_id ? $payment_id : rand( 2000, 2050 ),
892 - 'receipt_link_url' => $receipt_link_url,
893 - 'receipt_link' => $receipt_link,
894 - 'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
895 - 'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
896 - 'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
897 - 'sitename' => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
874 + 'name' => give_email_tag_first_name(
875 + array(
876 + 'payment_id' => $payment_id,
877 + 'user_id' => $user_id,
878 + )
879 + ),
880 + 'fullname' => give_email_tag_fullname(
881 + array(
882 + 'payment_id' => $payment_id,
883 + 'user_id' => $user_id,
884 + )
885 + ),
886 + 'username' => give_email_tag_username(
887 + array(
888 + 'payment_id' => $payment_id,
889 + 'user_id' => $user_id,
890 + )
891 + ),
892 + 'user_email' => give_email_tag_user_email(
893 + array(
894 + 'payment_id' => $payment_id,
895 + 'user_id' => $user_id,
896 + )
897 + ),
898 + 'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
899 + 'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
900 + 'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
901 + 'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
902 + 'payment_id' => $payment_id ? $payment->number : rand( 2000, 2050 ),
903 + 'receipt_link_url' => $receipt_link_url,
904 + 'receipt_link' => $receipt_link,
905 + 'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
906 + 'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
907 + 'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
908 + 'sitename' => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
898 909 'billing_address' => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
899 910 'email_access_link' => sprintf(
900 911 '<a href="%1$s">%2$s</a>',
901 - add_query_arg(
912 + esc_url( add_query_arg(
902 913 array(
903 914 'give_nl' => uniqid(),
904 915 ),
905 916 give_get_history_page_uri()
906 - ),
917 + ) ),
907 918 __( 'View your donation history &raquo;', 'give' )
908 919 ),
920 + 'donation_history_link' => sprintf(
921 + '<a href="%1$s">%2$s</a>',
922 + esc_url( add_query_arg(
923 + array(
924 + 'give_nl' => uniqid(),
925 + ),
926 + give_get_history_page_uri()
927 + ) ),
928 + __( 'View your donation history &raquo;', 'give' )
929 + ),
909 930 'reset_password_link' => $user_id ? give_email_tag_reset_password_link( array( 'user_id' => $user_id ), $payment_id ) : '',
910 931 'site_url' => sprintf(
911 932 '<a href="%1$s">%2$s</a>',
912 933 get_bloginfo( 'url' ),
@@ -947,21 +968,23 @@
947 968 *
948 969 * @param $form_meta_key
949 970 * @param $form_meta_value
950 971 * @param $post_id
951 - *
952 972 */
953 973 public function validate_form_recipient_field_value( $form_meta_key, $form_meta_value, $post_id ) {
954 974 // Get valid emails.
955 - $new_form_meta_value = array_filter( $form_meta_value, function ( $value ) {
956 - return ! empty( $value['email'] ) && is_email( $value['email'] );
957 - } );
975 + $new_form_meta_value = array_filter(
976 + $form_meta_value,
977 + function ( $value ) {
978 + return ! empty( $value['email'] ) && is_email( $value['email'] );
979 + }
980 + );
958 981
959 982 // Remove duplicate emails from array.
960 983 $email_arr = array();
961 984 foreach ( $new_form_meta_value as $index => $email ) {
962 - if( in_array( $email['email'], $email_arr ) ) {
963 - unset( $new_form_meta_value[$index] );
985 + if ( in_array( $email['email'], $email_arr ) ) {
986 + unset( $new_form_meta_value[ $index ] );
964 987 continue;
965 988 }
966 989
967 990 $email_arr[] = $email['email'];
@@ -972,9 +995,9 @@
972 995 if ( empty( $new_form_meta_value ) ) {
973 996 // Set default recipient.
974 997 $form_meta_value = array(
975 998 array(
976 - 'email' => get_bloginfo( 'admin_email' )
999 + 'email' => get_bloginfo( 'admin_email' ),
977 1000 ),
978 1001 );
979 1002
980 1003 $update = true;
@@ -985,9 +1008,9 @@
985 1008
986 1009 $update = true;
987 1010 }
988 1011
989 - if( $update ) {
1012 + if ( $update ) {
990 1013 give_update_meta( $post_id, $form_meta_key, $form_meta_value );
991 1014 }
992 1015 }
993 1016 }