ravinderk /
Give
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Email Template |
||
| 4 | * |
||
| 5 | * @package Give |
||
| 6 | * @subpackage Emails |
||
| 7 | * @copyright Copyright (c) 2016, WordImpress |
||
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
||
| 9 | * @since 1.0 |
||
| 10 | */ |
||
| 11 | |||
| 12 | // Exit if accessed directly. |
||
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
||
| 14 | exit; |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Gets all the email templates that have been registered. The list is extendable |
||
| 19 | * and more templates can be added. |
||
| 20 | * |
||
| 21 | * This is simply a wrapper to Give_Email_Templates->get_templates() |
||
| 22 | * |
||
| 23 | * @since 1.0 |
||
| 24 | * @return array $templates All the registered email templates. |
||
| 25 | */ |
||
| 26 | function give_get_email_templates() { |
||
| 27 | $templates = new Give_Emails; |
||
| 28 | |||
| 29 | return $templates->get_templates(); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Email Template Tags. |
||
| 34 | * |
||
| 35 | * @since 1.0 |
||
| 36 | * |
||
| 37 | * @param string $message Message with the template tags. |
||
| 38 | * @param array $payment_data Payment Data. |
||
| 39 | * @param int $payment_id Payment ID. |
||
| 40 | * @param bool $admin_notice Whether or not this is a notification email. |
||
| 41 | * |
||
| 42 | * @return string $message Fully formatted message |
||
| 43 | */ |
||
| 44 | function give_email_template_tags( $message, $payment_data, $payment_id, $admin_notice = false ) { |
||
| 45 | return give_do_email_tags( $message, $payment_id ); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Email Preview Template Tags. |
||
| 50 | * |
||
| 51 | * Provides sample content for the preview email functionality within settings > email. |
||
| 52 | * |
||
| 53 | * @since 1.0 |
||
| 54 | * |
||
| 55 | * @param string $message Email message with template tags |
||
| 56 | * |
||
| 57 | * @return string $message Fully formatted message |
||
| 58 | */ |
||
| 59 | function give_email_preview_template_tags( $message ) { |
||
| 60 | |||
| 61 | $price = give_currency_filter( give_format_amount( 10.50, array( 'sanitize' => false ) ) ); |
||
| 62 | |||
| 63 | $gateway = 'PayPal'; |
||
| 64 | |||
| 65 | $receipt_id = strtolower( md5( uniqid() ) ); |
||
| 66 | |||
| 67 | $payment_id = rand( 1, 100 ); |
||
| 68 | |||
| 69 | $receipt_link_url = esc_url( add_query_arg( array( 'payment_key' => $receipt_id, 'give_action' => 'view_receipt' ), home_url() ) ); |
||
| 70 | $receipt_link = sprintf( |
||
| 71 | '<a href="%1$s">%2$s</a>', |
||
| 72 | $receipt_link_url, |
||
| 73 | esc_html__( 'View the receipt in your browser »', 'give' ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | // Set user. |
||
| 77 | $user = wp_get_current_user(); |
||
| 78 | |||
| 79 | $message = str_replace( '{name}', $user->display_name, $message ); |
||
| 80 | $message = str_replace( '{fullname}', $user->display_name, $message ); |
||
| 81 | $message = str_replace( '{username}', $user->user_login, $message ); |
||
| 82 | $message = str_replace( '{user_email}', $user->user_email, $message ); |
||
| 83 | $message = str_replace( '{billing_address}', "123 Test Street, Unit 222\nSomewhere Town, CA, 92101", $message ); |
||
| 84 | $message = str_replace( '{date}', date( give_date_format(), current_time( 'timestamp' ) ), $message ); |
||
| 85 | $message = str_replace( '{amount}', $price, $message ); |
||
| 86 | $message = str_replace( '{price}', $price, $message ); |
||
| 87 | $message = str_replace( '{donation}', esc_html__( 'Sample Donation Form Title', 'give' ), $message ); |
||
| 88 | $message = str_replace( '{form_title}', esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ), $message ); |
||
| 89 | $message = str_replace( '{receipt_id}', $receipt_id, $message ); |
||
| 90 | $message = str_replace( '{payment_method}', $gateway, $message ); |
||
| 91 | $message = str_replace( '{sitename}', get_bloginfo( 'name' ), $message ); |
||
| 92 | $message = str_replace( '{payment_id}', $payment_id, $message ); |
||
| 93 | $message = str_replace( '{receipt_link}', $receipt_link, $message ); |
||
| 94 | $message = str_replace( '{receipt_link_url}', $receipt_link_url, $message ); |
||
| 95 | $message = str_replace( '{pdf_receipt}', '<a href="#">Download Receipt</a>', $message ); |
||
| 96 | |||
| 97 | return wpautop( apply_filters( 'give_email_preview_template_tags', $message ) ); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Filter for Email Template Preview Buttons. |
||
| 102 | * |
||
| 103 | * @param array $array |
||
| 104 | * |
||
| 105 | * @access private |
||
| 106 | * @since 1.0 |
||
| 107 | * @return array|bool |
||
| 108 | */ |
||
| 109 | function give_email_template_preview( $array ) { |
||
| 110 | |||
| 111 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | $custom_field = array( |
||
| 115 | 'name' => esc_html__( 'Preview Email', 'give' ), |
||
| 116 | 'desc' => esc_html__( 'Click the buttons to preview or send test emails.', 'give' ), |
||
| 117 | 'id' => 'give_email_preview_buttons', |
||
| 118 | 'type' => 'email_preview_buttons' |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 119 | ); |
||
| 120 | |||
| 121 | return give_settings_array_insert( $array, 'donation_subject', array( $custom_field ) ); |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | add_filter( 'give_settings_emails', 'give_email_template_preview' ); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Output Email Template Preview Buttons. |
||
| 129 | * |
||
| 130 | * @access private |
||
| 131 | * @since 1.0 |
||
| 132 | * @return array |
||
| 133 | */ |
||
| 134 | function give_email_preview_buttons_callback() { |
||
| 135 | ob_start(); |
||
| 136 | ?> |
||
| 137 | <a href="<?php echo esc_url( add_query_arg( array( 'give_action' => 'preview_email' ), home_url() ) ); ?>" class="button-secondary" target="_blank"><?php esc_html_e( 'Preview Donation Receipt', 'give' ); ?></a> |
||
| 138 | <a href="<?php echo wp_nonce_url( add_query_arg( array( |
||
|
0 ignored issues
–
show
|
|||
| 139 | 'give_action' => 'send_test_email', |
||
| 140 | 'give-message' => 'sent-test-email', |
||
| 141 | 'tag' => 'emails' |
||
|
0 ignored issues
–
show
|
|||
| 142 | ) ), 'give-test-email' ); ?>" aria-label="<?php esc_attr_e( 'Send demo donation receipt to the emails listed below.', 'give' ); ?>" class="button-secondary"><?php esc_html_e( 'Send Test Email', 'give' ); ?></a> |
||
| 143 | <?php |
||
| 144 | echo ob_get_clean(); |
||
|
0 ignored issues
–
show
|
|||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Displays the email preview |
||
| 149 | * |
||
| 150 | * @since 1.0 |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | function give_display_email_template_preview() { |
||
| 154 | |||
| 155 | if ( empty( $_GET['give_action'] ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | if ( 'preview_email' !== $_GET['give_action'] ) { |
||
|
0 ignored issues
–
show
|
|||
| 160 | return; |
||
| 161 | } |
||
| 162 | |||
| 163 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
||
| 164 | return; |
||
| 165 | } |
||
| 166 | |||
|
0 ignored issues
–
show
|
|||
| 167 | |||
| 168 | Give()->emails->heading = esc_html__( 'Donation Receipt', 'give' ); |
||
| 169 | |||
| 170 | $payment_id = (int) isset( $_GET['preview_id'] ) ? $_GET['preview_id'] : ''; |
||
|
0 ignored issues
–
show
|
|||
| 171 | |||
| 172 | echo give_get_preview_email_header(); |
||
|
0 ignored issues
–
show
|
|||
| 173 | |||
| 174 | //Are we previewing an actual payment? |
||
| 175 | if ( ! empty( $payment_id ) ) { |
||
| 176 | |||
| 177 | $content = give_get_email_body_content( $payment_id ); |
||
| 178 | |||
| 179 | $preview_content = give_do_email_tags( $content, $payment_id ); |
||
| 180 | |||
| 181 | } else { |
||
| 182 | |||
| 183 | 42 | //No payment ID, use sample preview content |
|
| 184 | $preview_content = give_email_preview_template_tags( give_get_email_body_content( 0, array() ) ); |
||
| 185 | 42 | } |
|
| 186 | |||
|
0 ignored issues
–
show
|
|||
| 187 | 42 | ||
| 188 | echo Give()->emails->build_email( $preview_content ); |
||
|
0 ignored issues
–
show
|
|||
| 189 | 42 | ||
| 190 | exit; |
||
| 191 | 42 | ||
| 192 | } |
||
| 193 | 42 | ||
| 194 | add_action( 'init', 'give_display_email_template_preview' ); |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Email Template Body. |
||
| 198 | * |
||
| 199 | * @since 1.0 |
||
| 200 | * |
||
| 201 | * @param int $payment_id Payment ID |
||
| 202 | * @param array $payment_data Payment Data |
||
| 203 | * |
||
| 204 | * @return string $email_body Body of the email |
||
| 205 | */ |
||
| 206 | function give_get_email_body_content( $payment_id = 0, $payment_data = array() ) { |
||
| 207 | |||
| 208 | $default_email_body = give_get_default_donation_receipt_email(); |
||
| 209 | |||
| 210 | 42 | $email_content = give_get_option( 'donation_receipt' ); |
|
| 211 | $email_content = ( $email_content ) ? stripslashes( $email_content ) : $default_email_body; |
||
| 212 | 42 | ||
| 213 | 42 | $email_body = wpautop( $email_content ); |
|
| 214 | |||
| 215 | 42 | $email_body = apply_filters( 'give_donation_receipt_' . Give()->emails->get_template(), $email_body, $payment_id, $payment_data ); |
|
| 216 | 41 | ||
| 217 | 41 | return apply_filters( 'give_donation_receipt', $email_body, $payment_id, $payment_data ); |
|
| 218 | 42 | } |
|
| 219 | 1 | ||
| 220 | 1 | /** |
|
| 221 | * Donation Notification Template Body. |
||
| 222 | * |
||
| 223 | * @since 1.0 |
||
| 224 | 42 | * |
|
| 225 | * @param int $payment_id Payment ID |
||
| 226 | 42 | * @param array $payment_data Payment Data |
|
| 227 | 42 | * |
|
| 228 | * @return string $email_body Body of the email |
||
| 229 | 42 | */ |
|
| 230 | 42 | function give_get_donation_notification_body_content( $payment_id = 0, $payment_data = array() ) { |
|
| 231 | 42 | ||
| 232 | $user_info = maybe_unserialize( $payment_data['user_info'] ); |
||
| 233 | 42 | $email = give_get_payment_user_email( $payment_id ); |
|
| 234 | 42 | ||
| 235 | 42 | View Code Duplication | if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 236 | $user_data = get_userdata( $user_info['id'] ); |
||
| 237 | 42 | $name = $user_data->display_name; |
|
| 238 | } elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) { |
||
| 239 | 42 | $name = $user_info['first_name'] . ' ' . $user_info['last_name']; |
|
| 240 | } else { |
||
| 241 | 42 | $name = $email; |
|
| 242 | } |
||
| 243 | 42 | ||
| 244 | $gateway = give_get_gateway_admin_label( give_get_meta( $payment_id, '_give_payment_gateway', true ) ); |
||
| 245 | |||
| 246 | $default_email_body = esc_html__( 'Hello', 'give' ) . "\n\n"; |
||
| 247 | $default_email_body .= esc_html__( 'A donation has been made.', 'give' ) . "\n\n"; |
||
| 248 | $default_email_body .= esc_html__( 'Donation:', 'give' ) . "\n\n"; |
||
| 249 | $default_email_body .= esc_html__( 'Donor:', 'give' ) . ' ' . html_entity_decode( $name, ENT_COMPAT, 'UTF-8' ) . "\n"; |
||
| 250 | $default_email_body .= esc_html__( 'Amount:', 'give' ) . ' ' . html_entity_decode( give_currency_filter( give_format_amount( give_get_payment_amount( $payment_id ), array( 'sanitize' => false ) ) ), ENT_COMPAT, 'UTF-8' ) . "\n"; |
||
| 251 | $default_email_body .= esc_html__( 'Payment Method:', 'give' ) . ' ' . $gateway . "\n\n"; |
||
| 252 | $default_email_body .= esc_html__( 'Thank you', 'give' ); |
||
| 253 | |||
| 254 | $email = give_get_option( 'donation_notification' ); |
||
| 255 | $email = isset( $email ) ? stripslashes( $email ) : $default_email_body; |
||
| 256 | |||
| 257 | $email_body = give_do_email_tags( $email, $payment_id ); |
||
| 258 | |||
| 259 | return apply_filters( 'give_donation_notification', wpautop( $email_body ), $payment_id, $payment_data ); |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Render Receipt in the Browser. |
||
| 264 | * |
||
| 265 | * A link is added to the Donation Receipt to view the email in the browser and |
||
| 266 | * this function renders the Donation Receipt in the browser. It overrides the |
||
| 267 | * Donation Receipt template and provides its only styling. |
||
| 268 | * |
||
| 269 | * @since 1.0 |
||
| 270 | */ |
||
| 271 | function give_render_receipt_in_browser() { |
||
| 272 | View Code Duplication | if ( ! isset( $_GET['payment_key'] ) ) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 273 | wp_die( esc_html__( 'Missing donation payment key.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 400 ) ); |
||
| 274 | } |
||
| 275 | |||
| 276 | $key = urlencode( $_GET['payment_key'] ); |
||
|
0 ignored issues
–
show
|
|||
| 277 | |||
| 278 | ob_start(); |
||
| 279 | //Disallows caching of the page |
||
| 280 | header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" ); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Last-Modified: does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
D, d M Y H:i:s does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
GMT does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 281 | header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Cache-Control: no-store, no-cache, must-revalidate does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 282 | header( "Cache-Control: post-check=0, pre-check=0", false ); |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Cache-Control: post-check=0, pre-check=0 does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 283 | header( "Pragma: no-cache" ); // HTTP/1.0 |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Pragma: no-cache does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 284 | header( "Expires: Sat, 23 Oct 1977 05:00:00 PST" ); // Date in the past |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Expires: Sat, 23 Oct 1977 05:00:00 PST does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 285 | ?> |
||
| 286 | <!DOCTYPE html> |
||
| 287 | <html lang="en"> |
||
| 288 | <head> |
||
| 289 | <?php |
||
| 290 | /** |
||
| 291 | * Fires in the receipt HEAD. |
||
| 292 | * |
||
| 293 | * @since 1.0 |
||
| 294 | */ |
||
| 295 | do_action( 'give_receipt_head' ); |
||
| 296 | ?> |
||
| 297 | </head> |
||
| 298 | <body class="<?php echo apply_filters( 'give_receipt_page_body_class', 'give_receipt_page' ); ?>"> |
||
|
0 ignored issues
–
show
|
|||
| 299 | |||
| 300 | <div id="give_receipt_wrapper"> |
||
| 301 | <?php |
||
| 302 | /** |
||
| 303 | * Fires in the receipt template before the content. |
||
| 304 | * |
||
| 305 | * @since 1.0 |
||
| 306 | */ |
||
| 307 | do_action( 'give_render_receipt_in_browser_before' ); |
||
| 308 | |||
| 309 | echo do_shortcode( '[give_receipt payment_key=' . $key . ']' ); |
||
|
0 ignored issues
–
show
|
|||
| 310 | |||
| 311 | /** |
||
| 312 | * Fires in the receipt template after the content. |
||
| 313 | * |
||
| 314 | * @since 1.0 |
||
| 315 | */ |
||
| 316 | do_action( 'give_render_receipt_in_browser_after' ); |
||
| 317 | ?> |
||
| 318 | </div> |
||
| 319 | |||
| 320 | <?php |
||
| 321 | /** |
||
| 322 | * Fires in the receipt footer. |
||
| 323 | * |
||
| 324 | * @since 1.0 |
||
| 325 | */ |
||
| 326 | do_action( 'give_receipt_footer' ); |
||
| 327 | ?> |
||
| 328 | </body> |
||
| 329 | </html> |
||
| 330 | <?php |
||
| 331 | echo ob_get_clean(); |
||
|
0 ignored issues
–
show
|
|||
| 332 | die(); |
||
| 333 | } |
||
| 334 | |||
| 335 | add_action( 'give_view_receipt', 'give_render_receipt_in_browser' ); |
||
| 336 | |||
| 337 | |||
| 338 | /** |
||
| 339 | * Give Preview Email Header. |
||
| 340 | * |
||
| 341 | * Displays a header bar with the ability to change donations to preview actual data within the preview. Will not display if |
||
| 342 | * |
||
| 343 | * @since 1.6 |
||
| 344 | * |
||
| 345 | */ |
||
| 346 | function give_get_preview_email_header() { |
||
| 347 | |||
| 348 | //Payment receipt switcher |
||
| 349 | $payment_count = give_count_payments()->publish; |
||
| 350 | $payment_id = (int) isset( $_GET['preview_id'] ) ? $_GET['preview_id'] : ''; |
||
|
0 ignored issues
–
show
|
|||
| 351 | |||
| 352 | if ( $payment_count <= 0 ) { |
||
| 353 | return false; |
||
| 354 | } |
||
| 355 | |||
| 356 | //Get payments. |
||
| 357 | $payments = new Give_Payments_Query( array( |
||
| 358 | 'number' => 100 |
||
|
0 ignored issues
–
show
|
|||
| 359 | ) ); |
||
| 360 | $payments = $payments->get_payments(); |
||
| 361 | $options = array(); |
||
| 362 | |||
| 363 | //Provide nice human readable options. |
||
| 364 | View Code Duplication | if ( $payments ) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 365 | $options[0] = esc_html__( '- Select a donation -', 'give' ); |
||
| 366 | foreach ( $payments as $payment ) { |
||
| 367 | |||
| 368 | $options[ $payment->ID ] = esc_html( '#' . $payment->ID . ' - ' . $payment->email . ' - ' . $payment->form_title ); |
||
| 369 | |||
| 370 | } |
||
| 371 | } else { |
||
| 372 | $options[0] = esc_html__( 'No donations found.', 'give' ); |
||
| 373 | } |
||
| 374 | |||
| 375 | //Start constructing HTML output. |
||
| 376 | $transaction_header = '<div style="margin:0;padding:10px 0;width:100%;background-color:#FFF;border-bottom:1px solid #eee; text-align:center;">'; |
||
| 377 | |||
| 378 | //Inline JS function for switching donations. |
||
| 379 | $transaction_header .= '<script> |
||
| 380 | function change_preview(){ |
||
| 381 | var transactions = document.getElementById("give_preview_email_payment_id"); |
||
| 382 | var selected_trans = transactions.options[transactions.selectedIndex]; |
||
| 383 | console.log(selected_trans); |
||
| 384 | if (selected_trans){ |
||
| 385 | var url_string = "' . get_bloginfo( 'url' ) . '?give_action=preview_email&preview_id=" + selected_trans.value; |
||
| 386 | window.location = url_string; |
||
| 387 | } |
||
| 388 | } |
||
| 389 | </script>'; |
||
| 390 | |||
| 391 | $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>'; |
||
| 392 | |||
| 393 | //The select field with 100 latest transactions |
||
| 394 | $transaction_header .= Give()->html->select( array( |
||
| 395 | 'name' => 'preview_email_payment_id', |
||
| 396 | 'selected' => $payment_id, |
||
| 397 | 'id' => 'give_preview_email_payment_id', |
||
| 398 | 'class' => 'give-preview-email-payment-id', |
||
| 399 | 'options' => $options, |
||
| 400 | 'chosen' => false, |
||
| 401 | 'select_atts' => 'onchange="change_preview()">', |
||
| 402 | 'show_option_all' => false, |
||
| 403 | 'show_option_none' => false |
||
|
0 ignored issues
–
show
|
|||
| 404 | ) ); |
||
| 405 | |||
| 406 | //Closing tag |
||
| 407 | $transaction_header .= '</div>'; |
||
| 408 | |||
| 409 | return apply_filters( 'give_preview_email_receipt_header', $transaction_header ); |
||
| 410 | |||
| 411 | } |
||
| 412 | |||
| 413 | |||
| 414 | /** |
||
| 415 | * Give Receipt Head Content |
||
| 416 | * |
||
| 417 | * @since 1.6 |
||
| 418 | * @return string |
||
| 419 | */ |
||
| 420 | function give_receipt_head_content() { |
||
| 421 | |||
| 422 | //Title. |
||
| 423 | $output = '<title>' . esc_html__( 'Donation Receipt', 'give' ) . '</title>'; |
||
| 424 | |||
| 425 | //Meta. |
||
| 426 | $output .= '<meta charset="utf-8"/> |
||
| 427 | <!-- Further disallowing of caching of this page --> |
||
| 428 | <meta charset="utf-8"/> |
||
| 429 | <meta http-equiv="cache-control" content="max-age=0"/> |
||
| 430 | <meta http-equiv="cache-control" content="no-cache"/> |
||
| 431 | <meta http-equiv="expires" content="0"/> |
||
| 432 | <meta http-equiv="expires" content="Tue, 23 Oct 1977 05:00:00 PST"/> |
||
| 433 | <meta http-equiv="pragma" content="no-cache"/> |
||
| 434 | <meta name="robots" content="noindex, nofollow"/>'; |
||
| 435 | |||
| 436 | //CSS |
||
| 437 | $output .= '<link rel="stylesheet" href="' . give_get_stylesheet_uri() . '?ver=' . GIVE_VERSION . '">'; |
||
|
0 ignored issues
–
show
|
|||
| 438 | |||
| 439 | echo apply_filters( 'give_receipt_head_content', $output ); |
||
|
0 ignored issues
–
show
|
|||
| 440 | |||
| 441 | } |
||
| 442 | |||
| 443 | add_action( 'give_receipt_head', 'give_receipt_head_content' ); |