Skip to content

Commit

Permalink
Merge pull request #3984 from impress-org/recurring/issue/779
Browse files Browse the repository at this point in the history
feat: add template tag that takes donors to their subscriptions #779
  • Loading branch information
Devin Walker committed Feb 6, 2019
2 parents e256397 + cebdbb0 commit f9b73fb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
5 changes: 5 additions & 0 deletions assets/src/css/admin/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,8 @@ h2.give-nav-tab-wrapper {
border: 4px solid white;
}
}


.give_email_access_link_tag {
display: none;
}
10 changes: 10 additions & 0 deletions includes/admin/emails/abstract-email-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,16 @@ public function preview_email_template_tags( $message ) {
),
__( 'View your donation history »', 'give' )
),
'donation_history_link' => sprintf(
'<a href="%1$s">%2$s</a>',
add_query_arg(
array(
'give_nl' => uniqid(),
),
give_get_history_page_uri()
),
__( 'View your donation history &raquo;', 'give' )
),
'reset_password_link' => $user_id ? give_email_tag_reset_password_link( array( 'user_id' => $user_id ), $payment_id ) : '',
'site_url' => sprintf(
'<a href="%1$s">%2$s</a>',
Expand Down
32 changes: 22 additions & 10 deletions includes/emails/class-give-email-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function give_get_emails_tags_list() {
<span class="give_<?php echo $email_tag['tag']; ?>_tag">
<code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['desc']; ?>
</span>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
<?php
endif;
Expand Down Expand Up @@ -456,7 +456,13 @@ function give_setup_email_tags() {
array(
'tag' => 'email_access_link',
'desc' => esc_html__( 'The donor\'s email access link.', 'give' ),
'func' => 'give_email_tag_email_access_link',
'func' => 'give_email_tag_donation_history_link',
'context' => 'donor',
),
array(
'tag' => 'donation_history_link',
'desc' => esc_html__( 'The donor\'s email access link for donation history.', 'give' ),
'func' => 'give_email_tag_donation_history_link',
'context' => 'donor',
),

Expand Down Expand Up @@ -1187,15 +1193,15 @@ function give_email_tag_receipt_link_url( $tag_args ) {
}

/**
* Email template tag: {email_access_link}
* Email template tag: {donation_history_link}
*
* @since 2.0
*
* @param array $tag_args Email Tag Arguments.
*
* @return string
*/
function give_email_tag_email_access_link( $tag_args ) {
function give_email_tag_donation_history_link( $tag_args ) {
$donor_id = 0;
$donor = array();
$email_access_link = '';
Expand All @@ -1204,6 +1210,12 @@ function give_email_tag_email_access_link( $tag_args ) {
$tag_args = __give_20_bc_str_type_email_tag_param( $tag_args );

switch ( true ) {

case ! empty( $tag_args['payment_id'] ):
$donor_id = Give()->payment_meta->get_meta( $tag_args['payment_id'], '_give_payment_donor_id', true );
$donor = Give()->donors->get_by( 'id', $donor_id );
break;

case ! empty( $tag_args['donor_id'] ):
$donor_id = $tag_args['donor_id'];
$donor = Give()->donors->get_by( 'id', $tag_args['donor_id'] );
Expand Down Expand Up @@ -1232,11 +1244,11 @@ function give_email_tag_email_access_link( $tag_args ) {
$tag_args['donor_id'] = $donor_id;

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

// Add donation id to email access url, if it exists.
$donation_id = give_clean( filter_input( INPUT_GET, 'donation_id' ) );
Expand Down Expand Up @@ -1267,7 +1279,7 @@ function give_email_tag_email_access_link( $tag_args ) {
} // End if().

/**
* Filter the {email_access_link} email template tag output.
* Filter the {donation_history_link} email template tag output.
*
* @since 2.0
*
Expand Down
10 changes: 5 additions & 5 deletions tests/unit-tests/tests-email-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ function test_give_email_tag_receipt_link() {


/**
* Test function give_email_tag_email_access_link
* Test function give_email_tag_donation_history_link
*
* @since 2.0
* @cover give_email_tag_email_access_link
* @cover give_email_tag_donation_history_link
*/
function test_give_email_tag_email_access_link() {
function test_give_email_tag_donation_history_link() {
// Create new table columns manually.
// Are db columns setup?
if( ! Give()->donors->does_column_exist( 'token' ) ) {
Expand All @@ -696,7 +696,7 @@ function test_give_email_tag_email_access_link() {

Give_Helper_Payment::create_simple_payment();

$link = give_email_tag_email_access_link( array( 'user_id' => 1 ) );
$link = give_email_tag_donation_history_link( array( 'user_id' => 1 ) );

$this->assertRegExp(
'/target="_blank">View your donation history &raquo;<\/a>/',
Expand All @@ -708,7 +708,7 @@ function test_give_email_tag_email_access_link() {
$link
);

$link = give_email_tag_email_access_link( array( 'user_id' => 1, 'email_content_type' => 'text/plain' ) );
$link = give_email_tag_donation_history_link( array( 'user_id' => 1, 'email_content_type' => 'text/plain' ) );

$this->assertRegExp(
'/View your donation history: .+?\?give_nl=/',
Expand Down

0 comments on commit f9b73fb

Please sign in to comment.