Skip to content

Commit

Permalink
Email access link working nicely for donation receipts now as well
Browse files Browse the repository at this point in the history
Improved emails so they go through Give's email templates #496
  • Loading branch information
Devin Walker committed Mar 25, 2016
1 parent b144cee commit 474d6bb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
30 changes: 24 additions & 6 deletions includes/class-give-no-logins.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,31 @@ function send_email( $customer_id, $email ) {
$this->set_verify_key( $customer_id, $email, $verify_key );

// Get the purchase history URL
$page_id = give_get_option( 'purchase_history_page' );
$page_url = get_permalink( $page_id );
$page_id = give_get_option( 'purchase_history_page' );

$access_url = add_query_arg( array(
'give_nl' => $verify_key,
), get_permalink( $page_id ) );

//Nice subject and message
$subject = apply_filters( 'give_email_access_token_subject', sprintf( __( 'Your Access Link to %1$s', 'give' ), get_bloginfo( 'name' ) ) );

$message = __( 'You or someone in your organization requested an access link be sent to this email address. This is a temporary access link for you to view your donation information. Click on the link below to view:', 'give' ) . "\n\n";

$message .= '<a href="' . esc_url( $access_url ) . '" target="_blank">' . __( 'Access My Donation Details', 'give' ) . ' &raquo;</a>';

$message .= "\n\n";
$message .= "\n\n";
$message .= __( 'Sincerely,', 'give' );
$message .= "\n" . get_bloginfo( 'name' ) . "\n";

$message = apply_filters( 'give_email_access_token_message', $message );


// Send the email
$subject = __( 'Your access token', 'give' );
$message = "$page_url?give_nl=$verify_key";
wp_mail( $email, $subject, $message );
Give()->emails->__set( 'heading', apply_filters( 'give_email_access_token_heading', __( 'Your Access Link', 'give' ) ) );
Give()->emails->send( $email, $subject, $message );

}


Expand Down Expand Up @@ -166,7 +184,7 @@ function is_valid_token( $token ) {
}

//Set error only if email access form isn't being submitted
if ( ! isset( $_POST['give_email'] ) && ! isset( $_POST['_wpnonce'] ) ) {
if ( ! isset( $_POST['give_email'] ) && ! isset( $_POST['_wpnonce'] ) ) {
give_set_error( 'give_email_token_expired', apply_filters( 'give_email_token_expired_message', 'Sorry, your access token has expired. Please request a new one below:', 'give' ) );
}

Expand Down
34 changes: 25 additions & 9 deletions includes/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
* @return string
*/
function give_donation_history() {
$email_based = give_get_option( 'email_access' );

$email_access = give_get_option( 'email_access' );

//Is user logged in? Does an email-access token exist?
if ( is_user_logged_in() || ( $email_based == 'on' && Give()->email_login->token_exists ) ) {
if ( is_user_logged_in() || ( $email_access == 'on' && Give()->email_login->token_exists ) ) {
ob_start();
give_get_template_part( 'history', 'donations' );

return ob_get_clean();
} //Is Email-based access enabled?
elseif ( $email_based == 'on' ) {
elseif ( $email_access == 'on' ) {

ob_start();
give_get_template_part( 'email', 'login-form' );
Expand Down Expand Up @@ -217,7 +218,7 @@ function give_receipt_shortcode( $atts, $content = null ) {
global $give_receipt_args, $payment;

$give_receipt_args = shortcode_atts( array(
'error' => esc_html__( 'Sorry, it appears the viewing window for this donation receipt has expired or you do not have the permission to view this donation receipt.', 'give' ),
'error' => esc_html__( 'Sorry, you are missing the payment key to view this donation receipt.', 'give' ),
'price' => true,
'date' => true,
'payment_key' => false,
Expand All @@ -237,21 +238,36 @@ function give_receipt_shortcode( $atts, $content = null ) {
$payment_key = $give_receipt_args['payment_key'];
}

// No key found
if ( ! isset( $payment_key ) ) {
$email_access = give_get_option( 'email_access' );

// No payment_key found & Email Access is Turned on:
if ( ! isset( $payment_key ) && $email_access == 'on' && ! Give()->email_login->token_exists ) {

ob_start();
give_output_error( $give_receipt_args['error'], true, 'warning' );
echo apply_filters( 'give_send_new_receipt_message', esc_html__( 'Enter the email address you used when making your donation below to be sent a new receipt', 'give' ) . ':' );

give_get_template_part( 'email-login-form' );

return ob_get_clean();

} elseif ( ! isset( $payment_key ) ) {

return give_output_error( $give_receipt_args['error'], false, 'error' );

}

$payment_id = give_get_purchase_id_by_key( $payment_key );
$user_can_view = give_can_view_receipt( $payment_key );

// Key was provided, but user is logged out. Offer them the ability to login and view the receipt
if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! give_is_guest_payment( $payment_id ) ) {
if ( ! $user_can_view && $email_access == 'on' && ! Give()->email_login->token_exists ) {

ob_start();

give_get_template_part( 'email-login-form' );

return ob_get_clean();

} elseif ( ! $user_can_view ) {

global $give_login_redirect;

Expand Down
2 changes: 1 addition & 1 deletion templates/email-login-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

<?php
if ( ! give_get_errors() ) {
give_output_error( __( 'Please enter the email address you used when donating. A verification email containing an access link will be sent to you.', 'give' ), true );
give_output_error( __( 'Please enter the email address you used for your donation. A verification email containing an access link will be sent to you.', 'give' ), true );
} ?>

<form method="post" action="" id="give-email-access-form">
Expand Down

0 comments on commit 474d6bb

Please sign in to comment.