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

Abstract email templates into individual classes #3234

Merged
merged 64 commits into from
Jan 30, 2025
Merged
Changes from 4 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c895c45
Created abstract PMPro_Email_Template class
dparker1005 Oct 28, 2024
73b6626
Added PMPro_Email_Template_Cancel class
dparker1005 Oct 28, 2024
368dab3
Merge pull request #3181 from dparker1005/create-email-template-class
dparker1005 Nov 4, 2024
e7801ed
* Fix for sitename variable
MaximilianoRicoTabo Nov 5, 2024
686ad9a
Merge pull request #3187 from MaximilianoRicoTabo/bugfixing/sitename
dparker1005 Nov 6, 2024
64105a4
* Add Change Membership Classes ( admin and member )
MaximilianoRicoTabo Nov 6, 2024
414c2c9
* Add the body in the send function in the abstract email template class
MaximilianoRicoTabo Nov 7, 2024
1dd5827
* Add cancel admin class
MaximilianoRicoTabo Nov 7, 2024
f28ccea
* Remove added classes from email-templates array
MaximilianoRicoTabo Nov 8, 2024
b5eb2f9
*Rename admin change classes
MaximilianoRicoTabo Nov 8, 2024
83533eb
Tweaking admin changed templates
dparker1005 Nov 11, 2024
88b4ef2
Spacing to match original email template
dparker1005 Nov 11, 2024
fb6611e
Merge pull request #3188 from MaximilianoRicoTabo/add-admin-change-class
dparker1005 Nov 11, 2024
2bef7f2
Add payment failure classes
MaximilianoRicoTabo Nov 12, 2024
749b941
* Add canceled autorenewal template / classes for member and admin
MaximilianoRicoTabo Nov 14, 2024
6d95fbb
* Add checkout templates
MaximilianoRicoTabo Nov 15, 2024
f0a511c
* Add credit card expiring email class
MaximilianoRicoTabo Dec 2, 2024
c68d73b
[ENHANCEMENT] * Add Membership expiring email class
MaximilianoRicoTabo Dec 4, 2024
6e80dae
*add expired membership email class
MaximilianoRicoTabo Dec 3, 2024
480282e
* Add refund email classes
MaximilianoRicoTabo Dec 9, 2024
d4ed471
* Add Payment Email Classes
MaximilianoRicoTabo Dec 8, 2024
5a5f813
* Add billing info updated and billing info updated admin classes
MaximilianoRicoTabo Nov 11, 2024
9d8e83e
Merge pull request #3199 from MaximilianoRicoTabo/enhancement/add-cen…
dparker1005 Dec 13, 2024
a5906d7
* Rename billing info updated and billing info updated admin classes…
MaximilianoRicoTabo Dec 13, 2024
fccf2f8
* Remove header_name variable from children class as it's already pre…
MaximilianoRicoTabo Dec 13, 2024
7b7ec9a
[BUGFIXING] Send Invoice email from edit order page takes the wrong user
MaximilianoRicoTabo Dec 17, 2024
a4e187f
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 17, 2024
a927512
Merge pull request #3197 from MaximilianoRicoTabo/enhancement/add-bil…
dparker1005 Dec 17, 2024
e7ec36b
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 17, 2024
33804e4
* Remove unnecesary header_name from templates
MaximilianoRicoTabo Dec 17, 2024
e13b0c7
* Remove unnecesary header_name variable from child template
MaximilianoRicoTabo Dec 17, 2024
3194a47
* Remove unnecesary variable header_name from child template
MaximilianoRicoTabo Dec 17, 2024
b3ff95c
* Remove unnecessary header_name variable from child template
MaximilianoRicoTabo Dec 17, 2024
fa62cb3
* Remove unnecessary header_name variable from child template
MaximilianoRicoTabo Dec 17, 2024
0049752
Merge pull request #3193 from MaximilianoRicoTabo/enhancement/add-bil…
dparker1005 Dec 18, 2024
c8a76a4
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
ac68088
Fixing file name
dparker1005 Dec 18, 2024
c99daa6
Adding missing global
dparker1005 Dec 18, 2024
b72ee4d
Merge pull request #3202 from MaximilianoRicoTabo/enhancement/add-che…
dparker1005 Dec 18, 2024
bcc3d90
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
f664370
Merge pull request #3218 from MaximilianoRicoTabo/enhancement/add-cre…
dparker1005 Dec 18, 2024
b148ad7
Removing header name
dparker1005 Dec 18, 2024
9ce0d3c
Fixing missing variables
dparker1005 Dec 18, 2024
1ce3e8f
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
3637eaf
Fixing broken variables
dparker1005 Dec 18, 2024
a47146e
Make sure that we can get an enddate
dparker1005 Dec 18, 2024
12f4c97
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
8bdff4b
Merge pull request #3220 from MaximilianoRicoTabo/enhancement/members…
dparker1005 Dec 18, 2024
24dc95a
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
d0c9a62
Merge pull request #3221 from MaximilianoRicoTabo/enhancement/members…
dparker1005 Dec 18, 2024
26f54af
Fixing sending payment reminder email
dparker1005 Dec 18, 2024
89c77c5
Fixing broken variables
dparker1005 Dec 18, 2024
0f56c2d
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
85e17db
Merge pull request #3227 from MaximilianoRicoTabo/enhancement/payment…
dparker1005 Dec 18, 2024
9c74e72
Merge branch 'enhancement/email-template-abstraction' into enhancemen…
dparker1005 Dec 18, 2024
b6747f7
Merge pull request #3228 from MaximilianoRicoTabo/enhancement/add-ref…
dparker1005 Dec 18, 2024
daf9da1
Fixing payment action required email for Stripe
dparker1005 Dec 18, 2024
770ff46
Fixing incorrect variable usage and subject line that was not meant t…
kimcoleman Jan 18, 2025
1ddf06c
Merge pull request #3265 from kimcoleman/fix-admin-change-templates
dparker1005 Jan 20, 2025
a486e87
Switching to !!billing_address!! instead of individual fields
dparker1005 Jan 22, 2025
33268c1
Using global !!levels_link!!, encouraging _url instead of _link vars
dparker1005 Jan 28, 2025
fd4da01
Removing duplicate template variable
dparker1005 Jan 29, 2025
57ca669
Escaping
dparker1005 Jan 30, 2025
fc230b7
Merge branch 'v3.4' into enhancement/email-template-abstraction
dparker1005 Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 9 additions & 96 deletions classes/class.pmproemail.php
Original file line number Diff line number Diff line change
@@ -900,62 +900,14 @@ function sendBillingFailureEmail( $user = NULL, $order = NULL ) {
global $current_user;
if(!$user)
$user = $current_user;

if(!$user || !$order)
return false;

//get Level from constructor
$membership_level = new PMPro_Membership_Level( $order->membership_id );

// Try to get the subscription ID.
$subscription = $order->get_subscription();
$subscription_id = ! empty( $subscription ) ? $subscription->get_id() : null;

$this->email = $user->user_email;
$this->subject = sprintf( __("Membership payment for level %s failed at %s", "paid-memberships-pro"),
$membership_level->name, get_option("blogname") );

$this->data = array(
'subject' => $this->subject,
'header_name' => $user->display_name,
'name' => $user->display_name,
'user_login' => $user->user_login,
'sitename' => get_option( 'blogname' ),
'siteemail' => get_option( 'pmpro_from_email' ),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'billing_name' => $order->billing->name,
'billing_street' => $order->billing->street,
'billing_street2' => $order->billing->street2,
'billing_city' => $order->billing->city,
'billing_state' => $order->billing->state,
'billing_zip' => $order->billing->zip,
'billing_country' => $order->billing->country,
'billing_phone' => $order->billing->phone,
'cardtype' => $order->cardtype,
'accountnumber' => hideCardNumber($order->accountnumber),
'expirationmonth' => $order->expirationmonth,
'expirationyear' => $order->expirationyear,
'login_link' => pmpro_login_url( pmpro_url( 'billing', empty( $subscription_id ) ? '' : '?subscription_id=' . $subscription_id ) ),
'login_url' => pmpro_login_url( pmpro_url( 'billing', empty( $subscription_id ) ? '' : '?subscription_id=' . $subscription_id ) ),
'levels_url' => pmpro_url( 'levels' )
);
$this->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

$this->template = apply_filters("pmpro_email_template", "billing_failure", $this);
$email = new PMPro_Email_Template_Billing_Failure( $user, $order );
$email->send();
}

return $this->sendEmail();
}

/**
* Send the admin an email when their recurring payment has failed.
*
@@ -965,52 +917,13 @@ function sendBillingFailureEmail( $user = NULL, $order = NULL ) {
function sendBillingFailureAdminEmail($email, $order = NULL) {
if(!$order)
return false;

$user = get_userdata($order->user_id);
$membership_level = new PMPro_Membership_Level( $order->membership_id );

$this->email = $email;
$this->subject = sprintf(__("Membership payment failed For %s at %s", "paid-memberships-pro"), $user->display_name, get_option("blogname"));

$this->data = array(
'subject' => $this->subject,
'header_name' => $this->get_admin_name( $email ),
'name' => 'Admin',
'user_login' => $user->user_login,
'sitename' => get_option( 'blogname' ),
'siteemail' => get_option( 'pmpro_from_email' ),
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'billing_name' => $order->billing->name,
'billing_street' => $order->billing->street,
'billing_street2' => $order->billing->street2,
'billing_city' => $order->billing->city,
'billing_state' => $order->billing->state,
'billing_zip' => $order->billing->zip,
'billing_country' => $order->billing->country,
'billing_phone' => $order->billing->phone,
'cardtype' => $order->cardtype,
'accountnumber' => hideCardNumber($order->accountnumber),
'expirationmonth' => $order->expirationmonth,
'expirationyear' => $order->expirationyear,
'login_link' => pmpro_login_url( get_edit_user_link( $user->ID ) ),
'login_url' => pmpro_login_url( get_edit_user_link( $user->ID ) ),
'levels_url' => pmpro_url( 'levels' ),
);
$this->data["billing_address"] = pmpro_formatAddress($order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone);

$this->template = apply_filters("pmpro_email_template", "billing_failure_admin", $this);
$user = get_userdata( $order->user_id );
if(!$user)
return false;

return $this->sendEmail();
$email = new PMPro_Email_Template_Billing_Failure_Admin( $user, $order );
$email->send();
}

/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?php

class PMPro_Email_Template_Billing_Failure_Admin extends PMPro_Email_Template {

/**
* The user object of the user to send the email to.
*
* @var WP_User
*/
protected $user;

/**
* The {@link MemberOrder} object of the order that was updated.
*
* @var MemberOrder
*/
protected $order;

/**
* Constructor.
*
* @since TBD
*
* @param WP_User $user The user object of the user to send the email to.
* @param MemberOrder $order The order object that is associated to the member.
*/
public function __construct( WP_User $user, MemberOrder $order ) {
$this->user = $user;
$this->order = $order;
}

/**
* Get the email template slug.
*
* @since TBD
*
* @return string The email template slug.
*/
public static function get_template_slug() {
return 'billing_failure_admin';
}

/**
* Get the "nice name" of the email template.
*
* @since TBD
*
* @return string The "nice name" of the email template.
*/
public static function get_template_name() {
return __( 'Payment Failure (admin)', 'paid-memberships-pro' );
}

/**
* Get the email template description.
*
* @since TBD
*
* @return string The email template description.
*/
public static function get_template_description() {
return __( 'This email is sent to the site admin when a member\'s payment fails.', 'paid-memberships-pro' );
}

/**
* Get the email subject.
*
* @since TBD
*
* @return string The email subject.
*/
public static function get_default_subject() {
return __( "Membership payment failed for !!display_name!! at !!sitename!!", 'paid-memberships-pro' );
}

/**
* Get the email body.
*
* @since TBD
*
* @return string The email body.
*/
public static function get_default_body() {
return __( '<p>The subscription payment for !!user_login!! for level !!membership_level_name!! at !!sitename!! has failed.</p>
<p>Account: !!display_name!! (!!user_email!!)</p>
<p>Membership Level: !!membership_level_name!!</p>

<p>Log in to your WordPress admin here: !!login_url!!</p>', 'paid-memberships-pro' );
}

/**
* Get the email address to send the email to.
*
* @since TBD
*
* @return string The email address to send the email to.
*/
public function get_recipient_email() {
return get_bloginfo( 'admin_email' );
}

/**
* Get the name of the email recipient.
*
* @since TBD
*
* @return string The name of the email recipient.
*/
public function get_recipient_name() {
//get user by email
$user = get_user_by( 'email', $this->get_recipient_email() );
return $user->display_name;
}

/**
* Get the email template variables for the email paired with a description of the variable.
*
* @since TBD
*
* @return array The email template variables for the email (key => value pairs).
*/
public static function get_email_template_variables_with_description() {
return array(
'!!subject!!' => __( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ),
'!!name!!' => __( 'The display name of the user.', 'paid-memberships-pro' ),
'!!user_login!!' => __( 'The username of the user.', 'paid-memberships-pro' ),
'!!user_email!!' => __( 'The email address of the user billing failed', 'paid-memberships-pro' ),
'!!display_name!!' => __( 'The display name of the user billing failed', 'paid-memberships-pro' ),
'!!membership_id!!' => __( 'The ID of the membership level.', 'paid-memberships-pro' ),
'!!membership_level_name!!' => __( 'The name of the membership level.', 'paid-memberships-pro' ),
'!!billing_name!!' => __( 'Billing Info Name', 'paid-memberships-pro' ),
'!!billing_street!!' => __( 'Billing Info Street', 'paid-memberships-pro' ),
'!!billing_street2!!' => __( 'Billing Info Street 2', 'paid-memberships-pro' ),
'!!billing_city!!' => __( 'Billing Info City', 'paid-memberships-pro' ),
'!!billing_state!!' => __( 'Billing Info State', 'paid-memberships-pro' ),
'!!billing_zip!!' => __( 'Billing Info Zip', 'paid-memberships-pro' ),
'!!billing_country!!' => __( 'Billing Info Country', 'paid-memberships-pro' ),
'!!billing_phone!!' => __( 'Billing Info Phone', 'paid-memberships-pro' ),
'!!billing_address!!' => __( 'Billing Info Complete Address', 'paid-memberships-pro' ),
'!!cardtype!!' => __( 'Credit Card Type', 'paid-memberships-pro' ),
'!!accountnumber!!' => __( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ),
'!!expirationmonth!!' => __( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ),
'!!expirationyear!!' => __( 'Credit Card Expiration Year (yyyy format)', 'paid-memberships-pro' ),

);
}

/**
* Get the email template variables for the email.
*
* @since TBD
*
* @return array The email template variables for the email (key => value pairs).
*/
public function get_email_template_variables() {
$order = $this->order;
$user = $this->user;
$membership_level = pmpro_getLevel( $order->membership_id );
return array(
'subject' => $this->get_default_subject(),
'name' => $user->display_name,
'user_login' => $user->user_login,
'membership_id' => $membership_level->id,
'membership_level_name' => $membership_level->name,
'display_name' => $user->display_name,
'user_email' => $user->user_email,
'billing_name' => $order->billing->name,
'billing_street' => $order->billing->street,
'billing_street2' => $order->billing->street2,
'billing_city' => $order->billing->city,
'billing_state' => $order->billing->state,
'billing_zip' => $order->billing->zip,
'billing_country' => $order->billing->country,
'billing_phone' => $order->billing->phone,
'billing_address'=> pmpro_formatAddress( $order->billing->name,
$order->billing->street,
$order->billing->street2,
$order->billing->city,
$order->billing->state,
$order->billing->zip,
$order->billing->country,
$order->billing->phone ),
'cardtype' => $order->cardtype,
'accountnumber' => hideCardNumber( $order->accountnumber ),
'expirationmonth' => $order->expirationmonth,
'expirationyear' => $order->expirationyear,
);
}
}

/**
* Register the email template.
*
* @since TBD
*
* @param array $email_templates The email templates (template slug => email template class name)
* @return array The modified email templates array.
*/
function pmpro_email_templates_billing_failure_admin( $email_templates ) {
$email_templates['billing_failure_admin'] = 'PMPro_Email_Template_Billing_Failure_Admin';
return $email_templates;
}
add_filter( 'pmpro_email_templates', 'pmpro_email_templates_billing_failure_admin' );


Loading