Skip to content

Commit

Permalink
feat(admin-email): Register custom email tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Jun 16, 2018
1 parent 3fe24c5 commit 578b7c5
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 32 deletions.
14 changes: 14 additions & 0 deletions assets/src/js/admin/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,20 @@ var give_setting_edit = false;
$('input', $parent).not( 'input[name="sequential-ordering_status"]' ).parents('tr').hide();
}
}).change();

/**
* Toggle custom email address
*/
var offline_contact = $('input[name="contact_custom_admin_email"]');
offline_contact.on('change', function () {
var field_value = $('input[name="contact_custom_admin_email"]:checked').val(),
$parent = $(this).closest('tr');
if ('enabled' === field_value) {
$parent.next('tr').show();
} else {
$parent.next('tr').hide();
}
}).change();
},

main_setting_update_notice: function () {
Expand Down
48 changes: 28 additions & 20 deletions includes/admin/emails/abstract-email-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,40 +848,40 @@ public function preview_email_template_tags( $message ) {
$this->config['preview_email_tags_values'] = wp_parse_args(
$this->config['preview_email_tags_values'],
array(
'name' => give_email_tag_first_name( array(
'name' => give_email_tag_first_name( array(
'payment_id' => $payment_id,
'user_id' => $user_id,
) ),
'fullname' => give_email_tag_fullname( array(
'fullname' => give_email_tag_fullname( array(
'payment_id' => $payment_id,
'user_id' => $user_id,
) ),
'username' => give_email_tag_username( array(
'username' => give_email_tag_username( array(
'payment_id' => $payment_id,
'user_id' => $user_id,
) ),
'user_email' => give_email_tag_user_email( array(
'user_email' => give_email_tag_user_email( array(
'payment_id' => $payment_id,
'user_id' => $user_id,
) ),
'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
'receipt_id' => $receipt_id,
'payment_id' => $payment_id ? $payment_id : rand( 2000, 2050 ),
'receipt_link_url' => $receipt_link_url,
'receipt_link' => $receipt_link,
'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
'sitename' => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
'pdf_receipt' => sprintf(
'payment_total' => $payment_id ? give_email_tag_payment_total( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'amount' => $payment_id ? give_email_tag_amount( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'price' => $payment_id ? give_email_tag_price( array( 'payment_id' => $payment_id ) ) : give_currency_filter( '10.50' ),
'payment_method' => $payment_id ? give_email_tag_payment_method( array( 'payment_id' => $payment_id ) ) : __( 'PayPal', 'give' ),
'receipt_id' => $receipt_id,
'payment_id' => $payment_id ? $payment_id : rand( 2000, 2050 ),
'receipt_link_url' => $receipt_link_url,
'receipt_link' => $receipt_link,
'date' => $payment_id ? date( give_date_format(), strtotime( $payment->date ) ) : date( give_date_format(), current_time( 'timestamp' ) ),
'donation' => $payment_id ? give_email_tag_donation( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title', 'give' ),
'form_title' => $payment_id ? give_email_tag_form_title( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donation Form Title - Sample Donation Level', 'give' ),
'sitename' => $payment_id ? give_email_tag_sitename( array( 'payment_id' => $payment_id ) ) : get_bloginfo( 'name' ),
'pdf_receipt' => sprintf(
'<a href="#">%s</a>',
__( 'Download Receipt', 'give' )
),
'billing_address' => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
'email_access_link' => sprintf(
'billing_address' => $payment_id ? give_email_tag_billing_address( array( 'payment_id' => $payment_id ) ) : '',
'email_access_link' => sprintf(
'<a href="%1$s">%2$s</a>',
add_query_arg(
array(
Expand All @@ -891,7 +891,15 @@ public function preview_email_template_tags( $message ) {
),
__( 'View your donation history &raquo;', 'give' )
),
'reset_password_link' => $user_id ? give_email_tag_reset_password_link( array( 'user_id' => $user_id ), $payment_id ) : '',
'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>',
get_bloginfo( 'url' ),
get_bloginfo( 'url' )
),
'admin_email' => give_email_admin_email(),
'site_url' => give_email_site_url(),
'offline_mailing_address' => give_email_offline_mailing_address(),
)
);

Expand Down
40 changes: 40 additions & 0 deletions includes/admin/settings/class-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,45 @@ public function get_settings() {
'type' => 'sectionend'
)
);

case 'contact':
$settings = array(

// Section 5: Contact

array(
'id' => 'give_title_general_settings_5',
'type' => 'title'
),
array(
'name' => __( 'Custom Admin Email', 'give' ),
'id' => "contact_custom_admin_email",
'desc' => __( "The 'disabled' mode uses the admin email address set in WordPress Settings > General. Enable this to set custom admin email address.", 'give' ),
'type' => 'radio_inline',
'default' => 'disabled',
'options' => array(
'enabled' => __( 'Enabled', 'give' ),
'disabled' => __( 'Disabled', 'give' ),
),
),
array(
'name' => __( 'Admin Email Address', 'give' ),
'id' => "contact_admin_email",
'desc' => __( 'Use the {admin_email} tag to use this custom admin email address in the email templates.', 'give' ),
'type' => 'text',
),
array(
'name' => __( 'Offline Mailing Address', 'give' ),
'id' => "contact_offline_mailing_address",
'desc' => __( 'Set the Offline Mailing Address. Use the {offline_mailing_address} tag to use this in the email templates.', 'give' ),
'type' => 'wysiwyg',
'default' => '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . get_bloginfo( 'sitename' ) . '</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>',
),
array(
'id' => 'give_title_general_settings_4',
'type' => 'sectionend'
)
);
}

/**
Expand Down Expand Up @@ -443,6 +482,7 @@ public function get_sections() {
'currency-settings' => __( 'Currency', 'give' ),
'access-control' => __( 'Access Control', 'give' ),
'sequential-ordering' => __( 'Sequential Ordering', 'give' ),
'contact' => __( 'Contact', 'give' ),
);

return apply_filters( 'give_get_sections_' . $this->id, $sections );
Expand Down
65 changes: 65 additions & 0 deletions includes/emails/class-give-email-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,27 @@ function give_setup_email_tags() {
'context' => 'general',
),

array(
'tag' => 'admin_email',
'description' => esc_html__( 'The admin email.', 'give' ),
'function' => 'give_email_admin_email',
'context' => 'general',
),

array(
'tag' => 'site_url',
'description' => esc_html__( 'The website URL.', 'give' ),
'function' => 'give_email_site_url',
'context' => 'general',
),

array(
'tag' => 'offline_mailing_address',
'description' => esc_html__( 'Offline Mailing Address.', 'give' ),
'function' => 'give_email_offline_mailing_address',
'context' => 'general',
),

);

// Apply give_email_tags filter
Expand Down Expand Up @@ -1401,6 +1422,50 @@ function give_get_reset_password_url( $user_id ) {
return $reset_password_url;
}

/**
* Get custom admin email.
*
* @since 2.2
*
* @return string
*/
function give_email_admin_email() {
$custom_admin_email = give_is_setting_enabled( give_get_option( 'contact_custom_admin_email' ) );
$admin_email = give_get_option( 'contact_admin_email' );

return ( true === $custom_admin_email && ! empty( $admin_email ) )
? $admin_email
: get_bloginfo( 'admin_email' );
}

/**
* Get site URL.
*
* @since 2.2
*
* @return string
*/
function give_email_site_url() {
return get_bloginfo( 'url' );
}


/**
* Get custom offline mailing address.
*
* @since 2.2
*
* @return string
*/
function give_email_offline_mailing_address() {
$offline_address = give_get_option( 'contact_offline_mailing_address' );

if ( false === $offline_address ) {
return '<em>' . get_bloginfo( 'sitename' ) . '</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
}

return $offline_address;
}

/**
* This function helps to render meta data with from dynamic meta data email tag.
Expand Down
18 changes: 6 additions & 12 deletions includes/gateways/offline-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,18 @@ function give_get_default_offline_donation_content() {
$default_text = '<p>' . __( 'In order to make an offline donation we ask that you please follow these instructions', 'give' ) . ': </p>';
$default_text .= '<ol>';
$default_text .= '<li>';
$default_text .= sprintf(
$default_text .= give_do_email_tags( sprintf(
/* translators: %s: site name */
__( 'Make a check payable to "{sitename}"', 'give' ) );
__( 'Make a check payable to "{sitename}"', 'give' ) ), null );
$default_text .= '</li>';
$default_text .= '<li>';
$default_text .= sprintf(
$default_text .= give_do_email_tags( sprintf(
/* translators: %s: site name */
__( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' ) );
__( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' ) ), null );
$default_text .= '</li>';
$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
$default_text .= '</ol>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;{offline_mailing_address}<br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
$default_text .= give_do_email_tags( '{offline_mailing_address}<br>', null );
$default_text .= '<p>' . __( 'All contributions will be gratefully acknowledged and are tax deductible.', 'give' ) . '</p>';

return apply_filters( 'give_default_offline_donation_content', $default_text );
Expand Down Expand Up @@ -408,10 +405,7 @@ function give_get_default_offline_donation_email_content() {
$default_text .= '</li>';
$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
$default_text .= '</ol>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;{offline_mailing_address}<br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>' . $sitename . '</em><br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>';
$default_text .= '&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>';
$default_text .= '{offline_mailing_address}<br>';
$default_text .= '<p>' . __( 'Once your donation has been received we will mark it as complete and you will receive an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>';
$default_text .= '<p>' . __( 'Sincerely,', 'give' ) . '</p>';
$default_text .= '<p>{sitename}</p>';
Expand Down

0 comments on commit 578b7c5

Please sign in to comment.