PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
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 2.30.0 All 255 releases
← All changes | includes/emails/template.php +74 -63 2.3.04.16.9 View file →
@@ -3,9 +3,9 @@
3 3 * Email Template
4 4 *
5 5 * @package Give
6 6 * @subpackage Emails
7 - * @copyright Copyright (c) 2016, WordImpress
7 + * @copyright Copyright (c) 2016, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 1.0
10 10 */
11 11
@@ -23,9 +23,9 @@
23 23 * @since 1.0
24 24 * @return array $templates All the registered email templates.
25 25 */
26 26 function give_get_email_templates() {
27 - $templates = new Give_Emails;
27 + $templates = new Give_Emails();
28 28
29 29 return $templates->get_templates();
30 30 }
31 31
@@ -30,8 +30,9 @@
30 30 }
31 31
32 32 /**
33 33 * Email Template Tags.
34 + *
34 35 * @todo Modify this function to remove payment id dependency.
35 36 *
36 37 * @since 1.0
37 38 *
@@ -52,32 +53,28 @@
52 53 * Provides sample content for the preview email functionality within settings > email.
53 54 *
54 55 * @since 1.0
55 56 *
56 - * @param string $message Email message with template tags
57 + * @param string $message Email message with template tags.
57 58 *
58 59 * @return string $message Fully formatted message
59 60 */
60 61 function give_email_preview_template_tags( $message ) {
61 62
62 - $price = give_currency_filter( give_format_amount( 10.50, array( 'sanitize' => false ) ) );
63 -
64 - $gateway = 'PayPal';
65 -
66 - $receipt_id = strtolower( md5( uniqid() ) );
67 -
68 - $payment_id = rand( 1, 100 );
69 - $receipt_link_url = esc_url( add_query_arg( array( 'payment_key' => $receipt_id ), give_get_history_page_uri() ) );
70 -
71 - $receipt_link = sprintf(
72 - '<a href="%1$s">%2$s</a>',
73 - $receipt_link_url,
74 - esc_html__( 'View the receipt in your browser &raquo;', 'give' )
63 + $user = wp_get_current_user();
64 + $gateway = 'PayPal';
65 + $donation_id = rand( 1, 100 );
66 + $receipt_link = give_get_receipt_link( $donation_id );
67 + $receipt_link_url = give_get_receipt_url( $donation_id );
68 + $price = give_currency_filter(
69 + give_format_amount(
70 + 10.50,
71 + array(
72 + 'sanitize' => false,
73 + )
74 + )
75 75 );
76 76
77 - // Set user.
78 - $user = wp_get_current_user();
79 -
80 77 $message = str_replace( '{name}', $user->display_name, $message );
81 78 $message = str_replace( '{fullname}', $user->display_name, $message );
82 79 $message = str_replace( '{username}', $user->user_login, $message );
83 80 $message = str_replace( '{user_email}', $user->user_email, $message );
@@ -86,12 +83,11 @@
86 83 $message = str_replace( '{amount}', $price, $message );
87 84 $message = str_replace( '{price}', $price, $message );
88 85 $message = str_replace( '{donation}', esc_html__( 'Sample Donation Form Title', 'give' ), $message );
89 86 $message = str_replace( '{form_title}', esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ), $message );
90 - $message = str_replace( '{receipt_id}', $receipt_id, $message );
91 87 $message = str_replace( '{payment_method}', $gateway, $message );
92 88 $message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message );
93 - $message = str_replace( '{payment_id}', $payment_id, $message );
89 + $message = str_replace( '{payment_id}', $donation_id, $message );
94 90 $message = str_replace( '{receipt_link}', $receipt_link, $message );
95 91 $message = str_replace( '{receipt_link_url}', $receipt_link_url, $message );
96 92 $message = str_replace( '{pdf_receipt}', '<a href="#">Download Receipt</a>', $message );
97 93
@@ -117,25 +113,37 @@
117 113 ob_start();
118 114
119 115 echo sprintf(
120 116 '<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
121 - wp_nonce_url(
122 - add_query_arg(
123 - array( 'give_action' => 'preview_email', 'email_type' => $field_id ),
124 - home_url()
125 - ), 'give-preview-email'
126 - ),
117 + esc_url(
118 + wp_nonce_url(
119 + add_query_arg(
120 + array(
121 + 'give_action' => 'preview_email',
122 + 'email_type' => $field_id,
123 + ),
124 + home_url()
125 + ),
126 + 'give-preview-email'
127 + )
128 + ),
127 129 $field['name']
128 130 );
129 131
130 132 echo sprintf(
131 133 ' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
132 - wp_nonce_url(
133 - add_query_arg( array(
134 - 'give_action' => 'send_preview_email',
135 - 'email_type' => $field_id,
136 - 'give-messages[]' => 'sent-test-email',
137 - ) ), 'give-send-preview-email' ),
134 + esc_url(
135 + wp_nonce_url(
136 + add_query_arg(
137 + array(
138 + 'give_action' => 'send_preview_email',
139 + 'email_type' => $field_id,
140 + 'give-messages[]' => 'sent-test-email',
141 + )
142 + ),
143 + 'give-send-preview-email'
144 + )
145 + ),
138 146 esc_attr__( 'Send Test Email.', 'give' ),
139 147 esc_html__( 'Send Test Email', 'give' )
140 148 );
141 149
@@ -147,14 +155,14 @@
147 155 * Give Preview Email Header.
148 156 *
149 157 * Displays a header bar with the ability to change donations to preview actual data within the preview. Will not display if
150 158 *
159 + * @since 2.14.0 reduce number of queries
151 160 * @since 1.6
152 - *
153 161 */
154 162 function give_get_preview_email_header() {
155 163
156 - //Payment receipt switcher
164 + // Payment receipt switcher
157 165 $payment_count = give_count_payments()->publish;
158 166 $payment_id = give_check_variable( give_clean( $_GET ), 'isset', 0, 'preview_id' );
159 167
160 168 if ( $payment_count <= 0 ) {
@@ -160,35 +168,36 @@
160 168 if ( $payment_count <= 0 ) {
161 169 return false;
162 170 }
163 171
164 - //Get payments.
165 - $donations = new Give_Payments_Query( array(
166 - 'number' => 100,
167 - 'output' => '',
168 - 'fields' => 'ids'
169 - ) );
172 + // Get payments.
173 + $donations = new Give_Payments_Query(
174 + array(
175 + 'number' => 100,
176 + )
177 + );
170 178 $donations = $donations->get_payments();
171 - $options = array();
179 + $options = [];
172 180
173 181 // Default option.
174 182 $options[0] = esc_html__( 'No donations found.', 'give' );
175 183
176 - //Provide nice human readable options.
184 + // Provide nice human readable options.
185 + /** @var Give_Payment[] $donations */
177 186 if ( $donations ) {
178 187 $options[0] = esc_html__( '- Select a donation -', 'give' );
179 - foreach ( $donations as $donation_id ) {
188 + foreach ( $donations as $donation ) {
180 189
181 - $options[ $donation_id ] = sprintf(
190 + $options[ $donation->ID ] = sprintf(
182 191 '#%1$s - %2$s - %3$s',
183 - $donation_id,
184 - give_get_donation_donor_email( $donation_id ),
185 - get_the_title( $donation_id )
192 + $donation->ID,
193 + $donation->email,
194 + $donation->number
186 195 );
187 196 }
188 197 }
189 198
190 - //Start constructing HTML output.
199 + // Start constructing HTML output.
191 200 $transaction_header = '<div style="margin:0;padding:10px 0;width:100%;background-color:#FFF;border-bottom:1px solid #eee; text-align:center;">';
192 201
193 202 // Remove payment id query param if set from request url.
194 203 $request_url_data = wp_parse_url( $_SERVER['REQUEST_URI'] );
@@ -194,9 +203,9 @@
194 203 $request_url_data = wp_parse_url( $_SERVER['REQUEST_URI'] );
195 204 $query = $request_url_data['query'];
196 205 $query = remove_query_arg( array( 'preview_id' ), $query );
197 206
198 - $request_url = home_url( '/?' . str_replace( '', '', $query ) );
207 + $request_url = esc_url_raw( home_url( '/?' . str_replace( '', '', $query ) ) );
199 208
200 209 $transaction_header .= '<script>
201 210 function change_preview(){
202 211 var transactions = document.getElementById("give_preview_email_payment_id");
@@ -209,22 +218,24 @@
209 218 </script>';
210 219
211 220 $transaction_header .= '<label for="give_preview_email_payment_id" style="font-size:12px;color:#333;margin:0 4px 0 0;">' . esc_html__( 'Preview email with a donation:', 'give' ) . '</label>';
212 221
213 - //The select field with 100 latest transactions
214 - $transaction_header .= Give()->html->select( array(
215 - 'name' => 'preview_email_payment_id',
216 - 'selected' => $payment_id,
217 - 'id' => 'give_preview_email_payment_id',
218 - 'class' => 'give-preview-email-payment-id',
219 - 'options' => $options,
220 - 'chosen' => false,
221 - 'select_atts' => 'onchange="change_preview()"',
222 - 'show_option_all' => false,
223 - 'show_option_none' => false,
224 - ) );
222 + // The select field with 100 latest transactions
223 + $transaction_header .= Give()->html->select(
224 + array(
225 + 'name' => 'preview_email_payment_id',
226 + 'selected' => $payment_id,
227 + 'id' => 'give_preview_email_payment_id',
228 + 'class' => 'give-preview-email-payment-id',
229 + 'options' => $options,
230 + 'chosen' => false,
231 + 'select_atts' => 'onchange="change_preview()"',
232 + 'show_option_all' => false,
233 + 'show_option_none' => false,
234 + )
235 + );
225 236
226 - //Closing tag
237 + // Closing tag
227 238 $transaction_header .= '</div>';
228 239
229 240 return apply_filters( 'give_preview_email_receipt_header', $transaction_header );
230 241