← All changes
|
includes/admin/emails/abstract-email-notification.php
+91
-60
2.3.2
→
4.17.0
View file →
| @@ -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,8 +842,9 @@ | ||
| 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 | 849 | * @param string $message Email Template Message. |
| 839 | 850 | * |
| @@ -859,46 +870,64 @@ | ||
| 859 | 870 | // Set default values for tags. |
| 860 | 871 | $this->config['preview_email_tags_values'] = wp_parse_args( |
| 861 | 872 | $this->config['preview_email_tags_values'], |
| 862 | 873 | array( |
| 863 | - 'name' => give_email_tag_first_name( array( | |
| 864 | - 'payment_id' => $payment_id, | |
| 865 | - 'user_id' => $user_id, | |
| 866 | - ) ), | |
| 867 | - 'fullname' => give_email_tag_fullname( array( | |
| 868 | - 'payment_id' => $payment_id, | |
| 869 | - 'user_id' => $user_id, | |
| 870 | - ) ), | |
| 871 | - 'username' => give_email_tag_username( array( | |
| 872 | - 'payment_id' => $payment_id, | |
| 873 | - 'user_id' => $user_id, | |
| 874 | - ) ), | |
| 875 | - 'user_email' => give_email_tag_user_email( array( | |
| 876 | - 'payment_id' => $payment_id, | |
| 877 | - 'user_id' => $user_id, | |
| 878 | - ) ), | |
| 879 | - 'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ), | |
| 880 | - 'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ), | |
| 881 | - 'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ), | |
| 882 | - 'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ), | |
| 883 | - 'payment_id' => $payment_id ? $payment_id : rand( 2000, 2050 ), | |
| 884 | - 'receipt_link_url' => $receipt_link_url, | |
| 885 | - 'receipt_link' => $receipt_link, | |
| 886 | - 'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ), | |
| 887 | - 'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ), | |
| 888 | - 'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ), | |
| 889 | - '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' ), | |
| 890 | 909 | 'billing_address' => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '', |
| 891 | 910 | 'email_access_link' => sprintf( |
| 892 | 911 | '<a href="%1$s">%2$s</a>', |
| 893 | - add_query_arg( | |
| 912 | + esc_url( add_query_arg( | |
| 894 | 913 | array( |
| 895 | 914 | 'give_nl' => uniqid(), |
| 896 | 915 | ), |
| 897 | 916 | give_get_history_page_uri() |
| 898 | - ), | |
| 917 | + ) ), | |
| 899 | 918 | __( 'View your donation history »', 'give' ) |
| 900 | 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 »', 'give' ) | |
| 929 | + ), | |
| 901 | 930 | 'reset_password_link' => $user_id ? give_email_tag_reset_password_link( array( 'user_id' => $user_id ), $payment_id ) : '', |
| 902 | 931 | 'site_url' => sprintf( |
| 903 | 932 | '<a href="%1$s">%2$s</a>', |
| 904 | 933 | get_bloginfo( 'url' ), |
| @@ -939,21 +968,23 @@ | ||
| 939 | 968 | * |
| 940 | 969 | * @param $form_meta_key |
| 941 | 970 | * @param $form_meta_value |
| 942 | 971 | * @param $post_id |
| 943 | - * | |
| 944 | 972 | */ |
| 945 | 973 | public function validate_form_recipient_field_value( $form_meta_key, $form_meta_value, $post_id ) { |
| 946 | 974 | // Get valid emails. |
| 947 | - $new_form_meta_value = array_filter( $form_meta_value, function ( $value ) { | |
| 948 | - return ! empty( $value['email'] ) && is_email( $value['email'] ); | |
| 949 | - } ); | |
| 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 | + ); | |
| 950 | 981 | |
| 951 | 982 | // Remove duplicate emails from array. |
| 952 | 983 | $email_arr = array(); |
| 953 | 984 | foreach ( $new_form_meta_value as $index => $email ) { |
| 954 | - if( in_array( $email['email'], $email_arr ) ) { | |
| 955 | - unset( $new_form_meta_value[$index] ); | |
| 985 | + if ( in_array( $email['email'], $email_arr ) ) { | |
| 986 | + unset( $new_form_meta_value[ $index ] ); | |
| 956 | 987 | continue; |
| 957 | 988 | } |
| 958 | 989 | |
| 959 | 990 | $email_arr[] = $email['email']; |
| @@ -964,9 +995,9 @@ | ||
| 964 | 995 | if ( empty( $new_form_meta_value ) ) { |
| 965 | 996 | // Set default recipient. |
| 966 | 997 | $form_meta_value = array( |
| 967 | 998 | array( |
| 968 | - 'email' => get_bloginfo( 'admin_email' ) | |
| 999 | + 'email' => get_bloginfo( 'admin_email' ), | |
| 969 | 1000 | ), |
| 970 | 1001 | ); |
| 971 | 1002 | |
| 972 | 1003 | $update = true; |
| @@ -977,9 +1008,9 @@ | ||
| 977 | 1008 | |
| 978 | 1009 | $update = true; |
| 979 | 1010 | } |
| 980 | 1011 | |
| 981 | - if( $update ) { | |
| 1012 | + if ( $update ) { | |
| 982 | 1013 | give_update_meta( $post_id, $form_meta_key, $form_meta_value ); |
| 983 | 1014 | } |
| 984 | 1015 | } |
| 985 | 1016 | } |