Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin-email): improve management of contact info in emails #3070 #3378

Merged
merged 5 commits into from Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 28 additions & 20 deletions includes/admin/emails/abstract-email-notification.php
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
6 changes: 1 addition & 5 deletions includes/admin/emails/class-email-access-email.php
Expand Up @@ -174,11 +174,7 @@ public function get_email_attachments( $form_id = null ) {
* @return string
*/
public function get_default_email_message() {
$message = sprintf(
__( 'Please click the link to access your donation history on <a target="_blank" href="%1$s">%1$s</a>. If you did not request this email, please contact <a href="mailto:%2$s">%2$s</a>.', 'give' ),
get_bloginfo( 'url' ),
get_bloginfo( 'admin_email' )
) . "\n\n";
$message = __( 'Please click the link to access your donation history on {site_url}. If you did not request this email, please contact {admin_email}.', 'give' ) . "\n\n";
$message .= '{email_access_link}' . "\n\n";
$message .= "\n\n";
$message .= __( 'Sincerely,', 'give' ) . "\n";
Expand Down
31 changes: 31 additions & 0 deletions includes/admin/settings/class-settings-email.php
Expand Up @@ -111,6 +111,36 @@ public function get_settings() {
),
);
break;

case 'contact':
$settings = array(

array(
'id' => 'give_title_general_settings_5',
'type' => 'title'
),
array(
'name' => __( 'Admin Email Address', 'give' ),
'id' => "contact_admin_email",
'desc' => sprintf( '%1$s <code>{admin_email}</code> %2$s', __( 'By default, the', 'give' ), __( 'tag will use your WordPress admin email. If you would like to customize this address you can do so in the field above.', 'give' ) ),
'type' => 'text',
'default' => give_email_admin_email(),

),
array(
'name' => __( 'Offline Mailing Address', 'give' ),
'id' => "contact_offline_mailing_address",
'desc' => sprintf( '%1$s <code>{offline_mailing_address}</code> %2$s', __( 'Set the mailing address to where you would like your donors to send their offline donations. This will customize the', 'give' ), __( 'email tag for the Offline Donations payment gateway.', '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'
)
);

break;
}// End switch().

/**
Expand Down Expand Up @@ -141,6 +171,7 @@ public function get_settings() {
public function get_sections() {
$sections = array(
'email-settings' => esc_html__( 'Email Settings', 'give' ),
'contact' => esc_html__( 'Contact Information', 'give' ),
);

return apply_filters( 'give_get_sections_' . $this->id, $sections );
Expand Down
1 change: 1 addition & 0 deletions includes/admin/settings/class-settings-general.php
Expand Up @@ -443,6 +443,7 @@ public function get_sections() {
'currency-settings' => __( 'Currency', 'give' ),
'access-control' => __( 'Access Control', 'give' ),
'sequential-ordering' => __( 'Sequential Ordering', 'give' ),
'contact' => __( 'Contact Information', 'give' ),
);

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

array(
'tag' => 'admin_email',
'description' => esc_html__( 'The custom admin email which is set inside Emails > Contact Information. By default this tag will use your WordPress 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__( 'The Offline Mailing Address which is used for the Offline Donations Payment Gateway.', 'give' ),
'function' => 'give_email_offline_mailing_address',
'context' => 'general',
),

);

// Apply give_email_tags filter
Expand Down Expand Up @@ -1401,6 +1422,54 @@ 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() {

$admin_email = give_get_option( 'contact_admin_email' );

if ( empty( $admin_email ) ) {
give_delete_option( 'contact_admin_email' );
}

return ( ! 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 sprintf( '&nbsp;&nbsp;&nbsp;&nbsp;<em>%s</em></em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>111 Not A Real St.</em><br>&nbsp;&nbsp;&nbsp;&nbsp;<em>Anytown, CA 12345 </em><br>', get_bloginfo( 'sitename' ) );
}

return $offline_address;
}

/**
* This function helps to render meta data with from dynamic meta data email tag.
Expand Down
2 changes: 1 addition & 1 deletion includes/emails/functions.php
Expand Up @@ -85,7 +85,7 @@ function give_admin_email_notice( $payment_id ) {
function give_get_default_donation_notification_email() {

$default_email_body = __( 'Hi there,', 'give' ) . "\n\n";
$default_email_body .= __( 'This email is to inform you that a new donation has been made on your website:', 'give' ) . ' <a href="' . get_bloginfo( 'url' ) . '" target="_blank">' . get_bloginfo( 'url' ) . '</a>' . ".\n\n";
$default_email_body .= __( 'This email is to inform you that a new donation has been made on your website:', 'give' ) . ' {site_url}' . ".\n\n";
$default_email_body .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {name}' . "\n";
$default_email_body .= '<strong>' . __( 'Donation:', 'give' ) . '</strong> {donation}' . "\n";
$default_email_body .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n";
Expand Down
29 changes: 9 additions & 20 deletions includes/gateways/offline-donations.php
Expand Up @@ -361,24 +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 "%s"', 'give' ),
$sitename
);
__( '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 "%s"', 'give' ),
$sitename
);
__( '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;<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 All @@ -401,25 +395,20 @@ function give_get_default_offline_donation_email_content() {
$default_text .= '<li>';
$default_text .= sprintf(
/* translators: %s: site name */
__( 'Make a check payable to "%s"', 'give' ),
$sitename
__( 'Make a check payable to "{sitename}"', 'give' )
);
$default_text .= '</li>';
$default_text .= '<li>';
$default_text .= sprintf(
/* translators: %s: site name */
__( 'On the memo line of the check, please indicate that the donation is for "%s"', 'give' ),
$sitename
__( 'On the memo line of the check, please indicate that the donation is for "{sitename}"', 'give' )
);
$default_text .= '</li>';
$default_text .= '<li>' . __( 'Please mail your check to:', 'give' ) . '</li>';
$default_text .= '</ol>';
$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>';
$default_text .= '<p>{sitename}</p>';

return apply_filters( 'give_default_offline_donation_content', $default_text );

Expand Down