| @@ -879,9 +879,14 @@ | ||
| 879 | 879 | // FixIn: 8.7.2.5. |
| 880 | 880 | $replace[ 'check_in_only_date' ] = $my_check_in_onlydate; |
| 881 | 881 | $replace[ 'check_out_only_date' ] = $my_check_out_onlydate; |
| 882 | 882 | $replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // FixIn: 6.0.1.11. |
| 883 | - $replace[ 'dates_count' ] = count( $my_dates4emeil_check_in_out ); | |
| 883 | + | |
| 884 | + $replace['dates_count'] = count( $my_dates4emeil_check_in_out ); | |
| 885 | + $replace['days_count'] = intval( $replace['dates_count'] ); // FixIn: 10.15.1.3. | |
| 886 | + $replace['nights_count'] = ( $replace['days_count'] > 1 ) ? intval( $replace['days_count'] - 1 ) : 1; | |
| 887 | + $replace['days_count_plus1day'] = intval( $replace['days_count'] + 1 ); | |
| 888 | + | |
| 884 | 889 | $replace['cost'] = $booking_cost; |
| 885 | 890 | $replace['cost_digits_only'] = $booking_cost_digits_only; |
| 886 | 891 | $replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . esc_url( home_url() ) . '">' . home_url() . '</a>' ); |
| 887 | 892 | $replace[ 'resource_title'] = wpbc_lang( $bk_title ); |
| @@ -1033,43 +1038,165 @@ | ||
| 1033 | 1038 | |
| 1034 | 1039 | $mail_api->set_replace( $replace ); |
| 1035 | 1040 | $mail_api->fields_values['from_name'] = $mail_api->replace_shortcodes( $mail_api->fields_values['from_name'] ); // FixIn: 7.0.1.29. |
| 1036 | 1041 | |
| 1037 | - if ( ( strpos( $mail_api->fields_values['to'], ',') === false ) && ( strpos( $mail_api->fields_values['to'], ';') === false ) ) { | |
| 1038 | - | |
| 1039 | - $valid_email = sanitize_email( $mail_api->fields_values['to'] ); | |
| 1040 | - if ( ! empty( $valid_email ) ) | |
| 1041 | - $to = trim( wp_specialchars_decode( esc_html( stripslashes( $mail_api->fields_values['to_name'] ) ), ENT_QUOTES ) ) | |
| 1042 | - . ' <' . $valid_email . '> '; | |
| 1042 | + $email_result = false; | |
| 1043 | + | |
| 1044 | + // ------------------------------------------------------------------------------------------------------------- | |
| 1045 | + // Case #1. Semicolon => send SEPARATE emails. | |
| 1046 | + // Example: | |
| 1047 | + // to = admin1@example.com;admin2@example.com | |
| 1048 | + // to_name = Admin One;Admin Two | |
| 1049 | + // | |
| 1050 | + // Also supported: | |
| 1051 | + // to = admin1@example.com,sales@example.com;support@example.com | |
| 1052 | + // to_name = Admin One,Sales Team;Support Team | |
| 1053 | + // => first email sent to 2 recipients, second email sent separately. | |
| 1054 | + // ------------------------------------------------------------------------------------------------------------- | |
| 1055 | + if ( strpos( $mail_api->fields_values['to'], ';' ) !== false ) { | |
| 1056 | + | |
| 1057 | + $to_groups = explode( ';', $mail_api->fields_values['to'] ); | |
| 1058 | + $to_name_groups = explode( ';', $mail_api->fields_values['to_name'] ); | |
| 1059 | + | |
| 1060 | + $email_result = true; | |
| 1061 | + $sent_emails = 0; | |
| 1062 | + | |
| 1063 | + foreach ( $to_groups as $group_ind => $to_group ) { | |
| 1064 | + | |
| 1065 | + $to_group = trim( $to_group ); | |
| 1066 | + if ( '' === $to_group ) { | |
| 1067 | + continue; | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + $to_name_group = ''; | |
| 1071 | + if ( ! empty( $to_name_groups ) ) { | |
| 1072 | + $to_name_group = $to_name_groups[ count( $to_name_groups ) - 1 ]; | |
| 1073 | + if ( isset( $to_name_groups[ $group_ind ] ) ) { | |
| 1074 | + $to_name_group = $to_name_groups[ $group_ind ]; | |
| 1075 | + } | |
| 1076 | + } | |
| 1077 | + | |
| 1078 | + // One recipient in this group. | |
| 1079 | + if ( strpos( $to_group, ',' ) === false ) { | |
| 1080 | + | |
| 1081 | + $valid_email = sanitize_email( $to_group ); | |
| 1082 | + | |
| 1083 | + if ( empty( $valid_email ) ) { | |
| 1084 | + continue; | |
| 1085 | + } | |
| 1086 | + | |
| 1087 | + $to = trim( | |
| 1088 | + wp_specialchars_decode( | |
| 1089 | + esc_html( stripslashes( $to_name_group ) ), | |
| 1090 | + ENT_QUOTES | |
| 1091 | + ) | |
| 1092 | + ) . ' <' . $valid_email . '> '; | |
| 1093 | + | |
| 1094 | + // Several recipients in this group => send one email to this comma-separated group. | |
| 1095 | + } else { | |
| 1096 | + | |
| 1097 | + $to_array = explode( ',', $to_group ); | |
| 1098 | + $to_name = explode( ',', $to_name_group ); | |
| 1099 | + | |
| 1100 | + $to = array(); | |
| 1101 | + | |
| 1102 | + foreach ( $to_array as $to_ind => $to_email ) { | |
| 1103 | + | |
| 1104 | + $to_name_str = ''; | |
| 1105 | + if ( ! empty( $to_name ) ) { | |
| 1106 | + $to_name_str = $to_name[ count( $to_name ) - 1 ]; | |
| 1107 | + if ( isset( $to_name[ $to_ind ] ) ) { | |
| 1108 | + $to_name_str = $to_name[ $to_ind ]; | |
| 1109 | + } | |
| 1110 | + } | |
| 1111 | + | |
| 1112 | + $valid_email = sanitize_email( $to_email ); | |
| 1113 | + if ( ! empty( $valid_email ) ) { | |
| 1114 | + $to[] = trim( | |
| 1115 | + wp_specialchars_decode( | |
| 1116 | + esc_html( stripslashes( $to_name_str ) ), | |
| 1117 | + ENT_QUOTES | |
| 1118 | + ) | |
| 1119 | + ) . ' <' . $valid_email . '> '; | |
| 1120 | + } | |
| 1121 | + } | |
| 1122 | + | |
| 1123 | + $to = implode( ',', $to ); | |
| 1124 | + } | |
| 1125 | + | |
| 1126 | + if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { | |
| 1127 | + $single_result = $mail_api->send( $to, $replace ); | |
| 1128 | + $email_result = ( $email_result && (bool) $single_result ); | |
| 1129 | + $sent_emails++; | |
| 1130 | + } | |
| 1131 | + } | |
| 1132 | + | |
| 1133 | + if ( 0 === $sent_emails ) { | |
| 1134 | + $email_result = false; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + // ------------------------------------------------------------------------------------------------------------- | |
| 1138 | + // Case #2. No semicolon => keep old behavior. | |
| 1139 | + // Single email OR one email to several comma-separated recipients. | |
| 1140 | + // ------------------------------------------------------------------------------------------------------------- | |
| 1043 | 1141 | } else { |
| 1044 | - | |
| 1045 | - // Comma separated several emails - validate all these emails in Email API class | |
| 1046 | - $to_array = $mail_api->fields_values['to']; | |
| 1047 | - | |
| 1048 | - $to_array = str_replace(';', ',', $to_array); | |
| 1049 | - if ( !is_array( $to_array ) ) $to_array = explode( ',', $to_array ); | |
| 1050 | 1142 | |
| 1051 | - $to_name = str_replace(';', ',', $mail_api->fields_values['to_name']); | |
| 1052 | - if ( !is_array( $to_name ) ) $to_name = explode( ',', $to_name ); | |
| 1143 | + if ( strpos( $mail_api->fields_values['to'], ',' ) === false ) { | |
| 1053 | 1144 | |
| 1054 | - $to = array(); | |
| 1055 | - foreach ( $to_array as $to_ind => $to_email) { | |
| 1056 | - | |
| 1057 | - $to_name_str = $to_name[ ( count( $to_name ) - 1 ) ]; | |
| 1058 | - | |
| 1059 | - if ( isset( $to_name[ $to_ind ] ) ) | |
| 1060 | - $to_name_str = $to_name[ $to_ind ]; | |
| 1145 | + $valid_email = sanitize_email( $mail_api->fields_values['to'] ); | |
| 1061 | 1146 | |
| 1062 | - $valid_email = sanitize_email( $to_email ); | |
| 1063 | - if ( ! empty( $valid_email ) ) | |
| 1064 | - $to[] = trim( wp_specialchars_decode( esc_html( stripslashes( $to_name_str ) ), ENT_QUOTES ) ) . ' <' . $valid_email . '> '; | |
| 1147 | + if ( ! empty( $valid_email ) ) { | |
| 1148 | + $to = trim( | |
| 1149 | + wp_specialchars_decode( | |
| 1150 | + esc_html( stripslashes( $mail_api->fields_values['to_name'] ) ), | |
| 1151 | + ENT_QUOTES | |
| 1152 | + ) | |
| 1153 | + ) . ' <' . $valid_email . '> '; | |
| 1154 | + } else { | |
| 1155 | + $to = ''; | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + } else { | |
| 1159 | + | |
| 1160 | + $to_array = $mail_api->fields_values['to']; | |
| 1161 | + if ( ! is_array( $to_array ) ) { | |
| 1162 | + $to_array = explode( ',', $to_array ); | |
| 1163 | + } | |
| 1164 | + | |
| 1165 | + $to_name = $mail_api->fields_values['to_name']; | |
| 1166 | + if ( ! is_array( $to_name ) ) { | |
| 1167 | + $to_name = explode( ',', $to_name ); | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + $to = array(); | |
| 1171 | + | |
| 1172 | + foreach ( $to_array as $to_ind => $to_email ) { | |
| 1173 | + | |
| 1174 | + $to_name_str = ''; | |
| 1175 | + if ( ! empty( $to_name ) ) { | |
| 1176 | + $to_name_str = $to_name[ count( $to_name ) - 1 ]; | |
| 1177 | + if ( isset( $to_name[ $to_ind ] ) ) { | |
| 1178 | + $to_name_str = $to_name[ $to_ind ]; | |
| 1179 | + } | |
| 1180 | + } | |
| 1181 | + | |
| 1182 | + $valid_email = sanitize_email( $to_email ); | |
| 1183 | + if ( ! empty( $valid_email ) ) { | |
| 1184 | + $to[] = trim( | |
| 1185 | + wp_specialchars_decode( | |
| 1186 | + esc_html( stripslashes( $to_name_str ) ), | |
| 1187 | + ENT_QUOTES | |
| 1188 | + ) | |
| 1189 | + ) . ' <' . $valid_email . '> '; | |
| 1190 | + } | |
| 1191 | + } | |
| 1192 | + | |
| 1193 | + $to = implode( ',', $to ); | |
| 1065 | 1194 | } |
| 1066 | - $to = implode(',', $to); | |
| 1067 | - | |
| 1068 | - } | |
| 1069 | 1195 | |
| 1070 | - if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { | |
| 1071 | - $email_result = $mail_api->send( $to , $replace ); | |
| 1196 | + if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { | |
| 1197 | + $email_result = $mail_api->send( $to, $replace ); | |
| 1198 | + } | |
| 1072 | 1199 | } |
| 1073 | 1200 | |
| 1074 | 1201 | make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user ); // MU |
| 1075 | 1202 | |