diff --git a/adminpages/emailtemplates-edit.php b/adminpages/emailtemplates-edit.php index 2fe9a2a3d..8724f8098 100644 --- a/adminpages/emailtemplates-edit.php +++ b/adminpages/emailtemplates-edit.php @@ -18,45 +18,54 @@ // Email variables. $email_variables = [ - 'general' => [ - '!!name!!' => __( 'Display Name (Profile/Edit User > Display name publicly as)', 'paid-memberships-pro' ), - '!!user_login!!' => __( 'Username', 'paid-memberships-pro' ), - '!!sitename!!' => __( 'Site Title', 'paid-memberships-pro' ), - '!!siteemail!!' => __( 'Site Email Address (General Settings > Email OR Memberships > Settings > Email Settings)', 'paid-memberships-pro' ), - '!!membership_id!!' => __( 'Membership Level ID', 'paid-memberships-pro' ), - '!!membership_level_name!!' => __( 'Membership Level Name', 'paid-memberships-pro' ), - '!!membership_change!!' => __( 'Membership Level Change', 'paid-memberships-pro' ), - '!!membership_expiration!!' => __( 'Membership Level Expiration', 'paid-memberships-pro' ), - '!!startdate!!' => __( 'Membership Start Date', 'paid-memberships-pro' ), - '!!enddate!!' => __( 'Membership End Date', 'paid-memberships-pro' ), - '!!display_name!!' => __( 'Display Name (Profile/Edit User > Display name publicly as)', 'paid-memberships-pro' ), - '!!user_email!!' => __( 'User Email', 'paid-memberships-pro' ), - '!!login_url!!' => __( 'Login URL', 'paid-memberships-pro' ), - '!!levels_url!!' => __( 'Membership Levels Page URL', 'paid-memberships-pro' ), + esc_html__( 'General Settings / Membership Info', 'paid-memberships-pro' ) => [ + '!!name!!' => esc_html__( 'Display Name (Profile/Edit User > Display name publicly as)', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'Username', 'paid-memberships-pro' ), + '!!sitename!!' => esc_html__( 'Site Title', 'paid-memberships-pro' ), + '!!siteemail!!' => esc_html__( 'Site Email Address (General Settings > Email OR Memberships > Settings > Email Settings)', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'Membership Level ID', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'Membership Level Name', 'paid-memberships-pro' ), + '!!membership_change!!' => esc_html__( 'Membership Level Change', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'Membership Level Expiration', 'paid-memberships-pro' ), + '!!startdate!!' => esc_html__( 'Membership Start Date', 'paid-memberships-pro' ), + '!!enddate!!' => esc_html__( 'Membership End Date', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'Display Name (Profile/Edit User > Display name publicly as)', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'User Email', 'paid-memberships-pro' ), + '!!login_url!!' => esc_html__( 'Login URL', 'paid-memberships-pro' ), + '!!levels_url!!' => esc_html__( 'Membership Levels Page URL', 'paid-memberships-pro' ), ], - 'billing' => [ - '!!billing_address!!' => __( 'Billing Info Complete Address', 'paid-memberships-pro' ), - '!!billing_name!!' => __( 'Billing Info Name', 'paid-memberships-pro' ), - '!!billing_street!!' => __( 'Billing Info Street Address', 'paid-memberships-pro' ), - '!!billing_city!!' => __( 'Billing Info City', 'paid-memberships-pro' ), - '!!billing_state!!' => __( 'Billing Info State', 'paid-memberships-pro' ), - '!!billing_zip!!' => __( 'Billing Info ZIP Code', 'paid-memberships-pro' ), - '!!billing_country!!' => __( 'Billing Info Country', 'paid-memberships-pro' ), - '!!billing_phone!!' => __( 'Billing Info Phone #', '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' ), - '!!membership_cost!!' => __( 'Membership Level Cost Text', 'paid-memberships-pro' ), - '!!instructions!!' => __( 'Payment Instructions (used in Checkout - Email Template)', 'paid-memberships-pro' ), - '!!order_id!!' => __( 'Order ID', 'paid-memberships-pro' ), - '!!order_total!!' => __( 'Order Total', 'paid-memberships-pro' ), - '!!order_date!!' => __( 'Order Date', 'paid-memberships-pro' ), - '!!order_url!!' => __( 'Order Page URL', 'paid-memberships-pro' ), - '!!discount_code!!' => __( 'Discount Code Applied', 'paid-memberships-pro' ), - '!!membership_level_confirmation_message!!' => __( 'Custom Level Confirmation Message', 'paid-memberships-pro' ), + esc_html__( 'Billing Information', 'paid-memberships-pro' ) => [ + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street Address', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info ZIP Code', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone #', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'Credit Card Expiration Year (yyyy format)', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'Membership Level Cost Text', 'paid-memberships-pro' ), + '!!instructions!!' => esc_html__( 'Payment Instructions (used in Checkout - Email Template)', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'Order ID', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'Order Total', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'Order Date', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'Order Page URL', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'Discount Code Applied', 'paid-memberships-pro' ), + '!!membership_level_confirmation_message!!' => esc_html__( 'Custom Level Confirmation Message', 'paid-memberships-pro' ), ] ]; + + // If we have a PMPro_Email_Template class for this template, use those variables instead. + $email_template_class = PMPro_Email_Template::get_email_template( $edit ); + if ( $email_template_class ) { + $email_variables = array( + esc_html__( 'Global Variables', 'paid-memberships-pro' ) => PMPro_Email_Template::get_base_email_template_variables_with_description(), + sprintf( esc_html__( '%s Variables', 'paid-memberships-pro' ), $email_template_class::get_template_name() ) => $email_template_class::get_email_template_variables_with_description(), + ); + } ?>
|
- - |
---|
-
- |
- - |
---|
|
+ + |
---|
" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; - } else { - $this->data["discount_code"] = ""; - } - } elseif( $this->template === 'checkout_free' ) { - if( ! empty( $discount_code ) ) { - $this->data["discount_code"] = "" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "
\n"; - } else { - $this->data["discount_code"] = ""; - } + //Bail if $email is null + if( $email == null ) { + return false; } - - $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); - if( $enddate ) { - $this->data["membership_expiration"] = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; - } else { - $this->data["membership_expiration"] = ""; - } - - return $this->sendEmail(); + $email->send(); } /** @@ -775,100 +492,37 @@ function sendCheckoutAdminEmail($user = NULL, $order = NULL) return false; } - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id); - - $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); - if ( ! empty( $confirmation_in_email ) ) { - $confirmation_message = $membership_level->confirmation; + $email = null; + if( !empty( $this->template ) ) { + switch( $this->template ) { + case 'checkout_check_admin': + $email = new PMPro_Email_Template_Checkout_Check_Admin( $user, $order ); + break; + case 'checkout_free_admin': + $email = new PMPro_Email_Template_Checkout_Free_Admin( $user, $order ); + break; + case 'checkout_paid': + $email = new PMPro_Email_Template_Checkout_Paid_Admin( $user, $order ); + break; + } } else { - $confirmation_message = ''; - } - - $this->email = get_bloginfo("admin_email"); - $this->subject = sprintf(__("Member checkout for %s at %s", 'paid-memberships-pro' ), $membership_level->name, get_option("blogname")); - - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $this->get_admin_name( $this->email ), - '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, - 'membership_level_confirmation_message' => $confirmation_message, - 'membership_cost' => pmpro_getLevelCost($membership_level), - 'login_link' => pmpro_login_url(), - 'login_url' => pmpro_login_url(), - 'display_name' => $user->display_name, - 'user_email' => $user->user_email, - 'levels_url' => pmpro_url( 'levels' ) - ); - - // Figure out which template to use. - if ( empty( $this->template ) ) { if( ! empty( $order ) && ! pmpro_isLevelFree( $membership_level ) ) { if( $order->gateway == "check" ) { - $this->template = "checkout_check_admin"; + $email = new PMPro_Email_Template_Checkout_Check_Admin( $user, $order ); } else { - $this->template = "checkout_paid_admin"; + $email = new PMPro_Email_Template_Checkout_Paid_Admin( $user, $order ); } } elseif( pmpro_isLevelFree( $membership_level ) ) { - $this->template = "checkout_free_admin"; + $email = new PMPro_Email_Template_Checkout_Free_Admin( $user, $order ); } } - - $this->template = apply_filters( "pmpro_email_template", $this->template, $this ); - - // Gather data depending on template being used. - if( in_array( $this->template, array( 'checkout_check_admin', 'checkout_paid_admin' ) ) ) { - $this->data["order_id"] = $order->code; - $this->data["order_total"] = $order->get_formatted_total(); - $this->data["order_date"] = date_i18n(get_option('date_format'), $order->getTimestamp()); - $this->data["billing_name"] = $order->billing->name; - $this->data["billing_street"] = $order->billing->street; - $this->data["billing_street2"] = $order->billing->street2; - $this->data["billing_city"] = $order->billing->city; - $this->data["billing_state"] = $order->billing->state; - $this->data["billing_zip"] = $order->billing->zip; - $this->data["billing_country"] = $order->billing->country; - $this->data["billing_phone"] = $order->billing->phone; - $this->data["cardtype"] = $order->cardtype; - $this->data["accountnumber"] = hideCardNumber($order->accountnumber); - $this->data["expirationmonth"] = $order->expirationmonth; - $this->data["expirationyear"] = $order->expirationyear; - $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); - - if( $order->getDiscountCode() ) { - $this->data["discount_code"] = "" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; - } else { - $this->data["discount_code"] = ""; - } - } elseif( $this->template === 'checkout_free_admin' ) { - if( ! empty( $discount_code ) ) { - $this->data["discount_code"] = "" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $discount_code . "
\n"; - } else { - $this->data["discount_code"] = ""; - } - } - - $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); - if( $enddate ) { - $this->data["membership_expiration"] = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; - } else { - $this->data["membership_expiration"] = ""; + //Bail if $email is null + if( $email == null ) { + return false; } - - return $this->sendEmail(); + $email->send(); } - + /** * Send the member a confirmation email when updating their billing details * @@ -888,50 +542,8 @@ function sendBillingEmail($user = NULL, $order = NULL) return false; } - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id); - - $this->email = $user->user_email; - $this->subject = sprintf(__("Your billing information has been updated at %s", "paid-memberships-pro"), 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(), - 'login_url' => pmpro_login_url(), - '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", $this ); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Billing( $user, $order ); + $email->send(); } /** @@ -953,50 +565,8 @@ function sendBillingAdminEmail($user = NULL, $order = NULL) return false; } - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id); - - $this->email = get_bloginfo("admin_email"); - $this->subject = sprintf(__("Billing information has been updated for %s at %s", "paid-memberships-pro"), $user->user_login, get_option("blogname")); - - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $this->get_admin_name( $this->email ), - '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(), - 'login_url' => pmpro_login_url(), - '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_admin", $this ); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Billing_Admin( $user, $order ); + $email->send(); } /** @@ -1009,62 +579,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. * @@ -1074,52 +596,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); - return $this->sendEmail(); + $user = get_userdata( $order->user_id ); + if(!$user) + return false; + + $email = new PMPro_Email_Template_Billing_Failure_Admin( $user, $order ); + $email->send(); } /** @@ -1144,51 +627,8 @@ function sendCreditCardExpiringEmail($user = NULL, $order = NULL) { return false; } - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id); - - $this->email = $user->user_email; - $this->subject = sprintf(__("Credit card on file expiring soon at %s", "paid-memberships-pro"), 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' ) ), - 'login_url' => pmpro_login_url( pmpro_url( 'billing' ) ), - '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", "credit_card_expiring", $this); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Credit_Card_Expiring( $user, $order ); + return $email->send(); } /** @@ -1197,8 +637,7 @@ function sendCreditCardExpiringEmail($user = NULL, $order = NULL) { * @param object $user The WordPress user object. * @param MemberOrder $order The order object that is associated to the member. */ - function sendInvoiceEmail($user = NULL, $order = NULL) - { + function sendInvoiceEmail( $user = NULL, $order = NULL ) { global $wpdb, $current_user; if(!$user) $user = $current_user; @@ -1206,75 +645,13 @@ function sendInvoiceEmail($user = NULL, $order = NULL) if(!$user || !$order) return false; + //Bail if no membership level in the order if ( empty( $order->membership_id ) ) { return false; } - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $order->membership_id); - - $this->email = $user->user_email; - $this->subject = sprintf(__("Order for %s membership", "paid-memberships-pro"), 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, - 'order_id' => $order->code, - 'order_total' => $order->get_formatted_total(), - 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), - '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(), - 'login_url' => pmpro_login_url(), - 'order_link' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), - 'order_url' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), - '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); - - if($order->getDiscountCode()) { - if(!empty($order->discount_code->code)) - $this->data["discount_code"] = "" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; - else - $this->data["discount_code"] = "" . __("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code . "
\n"; - } else { - $this->data["discount_code"] = ""; - } - - $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); - if($enddate) - $this->data["membership_expiration"] = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; - else - $this->data["membership_expiration"] = ""; - - - $this->template = apply_filters("pmpro_email_template", "invoice", $this); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Payment_Receipt( $user, $order ); + $email->send(); } /** @@ -1341,7 +718,7 @@ function sendTrialEndingEmail( $user = NULL, $membership_id = NULL ) { * @since 3.1 */ function sendMembershipExpiredEmail( $user = NULL, $membership_id = NULL ) { - global $current_user, $wpdb; + global $current_user; if( !$user ) { $user = $current_user; } @@ -1350,51 +727,9 @@ function sendMembershipExpiredEmail( $user = NULL, $membership_id = NULL ) { return false; } - // If we don't have a level ID, query the user's most recently expired level from the database. - if ( empty( $membership_id ) ) { - $membership_id = $wpdb->get_var( - $wpdb->prepare( - "SELECT membership_id FROM $wpdb->pmpro_memberships_users - WHERE user_id = %d - AND status = 'expired' - ORDER BY enddate DESC - LIMIT 1", - $user->ID - ) - ); - - // If we still don't have a level ID, bail. - if ( empty( $membership_id ) ) { - $membership_id = 0; - } - } - - // Get the membership level object. - $membership_level = pmpro_getLevel( $membership_id ); - - $this->email = $user->user_email; - $this->subject = sprintf( __("Your membership at %s has ended", "paid-memberships-pro"), get_option( "blogname" ) ); - - $this->data = array( - "subject" => $this->subject, - "name" => $user->display_name, - "user_login" => $user->user_login, - "header_name" => $user->display_name, - "sitename" => get_option("blogname"), - "siteemail" => get_option("pmpro_from_email"), - "login_link" => pmpro_login_url(), - "login_url" => pmpro_login_url(), - "display_name" => $user->display_name, - "user_email" => $user->user_email, - "levels_link" => pmpro_url("levels"), - "levels_url" => pmpro_url("levels"), - "membership_id" => $membership_id, - "membership_level_name" => ( ! empty( $membership_level ) && ! empty( $membership_level->name ) ) ? $membership_level->name : '[' . esc_html( 'deleted', 'paid-memberships-pro' ) . ']', - ); + $email = new PMPro_Email_Template_Membership_Expired( $user, $membership_id ); - $this->template = apply_filters("pmpro_email_template", "membership_expired", $this); - - return $this->sendEmail(); + $email->send(); } /** @@ -1411,36 +746,14 @@ function sendMembershipExpiringEmail( $user = NULL, $membership_id = NULL ) if(!$user) return false; - + if ( empty( $membership_id ) ) { - $membership_level = pmpro_getMembershipLevelForUser($user->ID); - } else { - $membership_level = pmpro_getSpecificMembershipLevelForUser($user->ID, $membership_id); + $membership_level = pmpro_getMembershipLevelForUser( $user->ID ); + $membership_id = $membership_level->id; } - $this->email = $user->user_email; - $this->subject = sprintf(__("Your membership at %s will end soon", "paid-memberships-pro"), 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'), - 'membership_id' => $membership_level->id, - 'membership_level_name' => $membership_level->name, - 'siteemail' => get_option('pmpro_from_email'), - 'login_link' => pmpro_login_url(), - 'login_url' => pmpro_login_url(), - 'enddate' => date_i18n(get_option('date_format'), $membership_level->enddate), - 'display_name' => $user->display_name, - 'user_email' => $user->user_email, - 'levels_url' => pmpro_url( 'levels' ) - ); - - $this->template = apply_filters("pmpro_email_template", "membership_expiring", $this); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Membership_Expiring( $user, $membership_id ); + $email->send(); } /** @@ -1456,34 +769,9 @@ function sendAdminChangeEmail($user = NULL) if(!$user) return false; - - $this->email = $user->user_email; - $this->subject = sprintf(__("Your membership at %s has been changed", "paid-memberships-pro"), get_option("blogname")); - - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $user->display_name, - 'name' => $user->display_name, - 'display_name' => $user->display_name, - 'user_login' => $user->user_login, - 'user_email' => $user->user_email, - 'sitename' => get_option( 'blogname' ), - 'siteemail' => get_option( 'pmpro_from_email' ), - 'login_link' => pmpro_login_url(), - 'login_url' => pmpro_login_url(), - 'levels_url' => pmpro_url( 'levels' ) - ); - - // If the user no longer has a membership level, set the membership_change text to "Membership has been cancelled." - if ( ! pmpro_hasMembershipLevel( null, $user->ID ) ) { - $this->data['membership_change'] = __( 'Your membership has been cancelled.', 'paid-memberships-pro' ); - } else { - $this->data['membership_change'] = __( 'You can view your current memberships by logging in and visiting your membership account page.', 'paid-memberships-pro' ); - } - $this->template = apply_filters("pmpro_email_template", "admin_change", $this); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Admin_Change( $user ); + $email->send(); } /** @@ -1500,33 +788,8 @@ function sendAdminChangeAdminEmail($user = NULL) if(!$user) return false; - $this->email = get_bloginfo("admin_email"); - $this->subject = sprintf(__("Membership for %s at %s has been changed", "paid-memberships-pro"), $user->user_login, get_option("blogname")); - - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $this->get_admin_name( $this->email ), - 'name' =>$user->display_name, - 'display_name' => $user->display_name, - 'user_login' => $user->user_login, - 'user_email' => $user->user_email, - 'sitename' => get_option('blogname'), - 'siteemail' => $this->email, - 'login_link' => pmpro_login_url(), - 'login_url' => pmpro_login_url(), - 'levels_url' => pmpro_url( 'levels' ) - ); - - // If the user no longer has a membership level, set the membership_change text to "Membership has been cancelled." - if ( ! pmpro_hasMembershipLevel( null, $user->ID ) ) { - $this->data['membership_change'] = __( "The user's membership has been cancelled.", 'paid-memberships-pro' ); - } else { - $this->data['membership_change'] = __( "You can view the user's current memberships from their Edit Member page.", 'paid-memberships-pro' ); - } - - $this->template = apply_filters("pmpro_email_template", "admin_change_admin", $this); - - return $this->sendEmail(); + $email = new PMPro_Email_Template_Admin_Change_Admin( $user ); + $email->send(); } /** @@ -1553,44 +816,29 @@ function sendBillableInvoiceEmail( $user = NULL, $order = NULL ) { * @param string $order_url The link to the order that is generated by Stripe. * @return void */ - function sendPaymentActionRequiredEmail($user = NULL, $order = NULL, $order_url = NULL) - { + function sendPaymentActionRequiredEmail( $user = NULL, $order = NULL, $order_url = NULL ) { global $current_user; if(!$user) $user = $current_user; - if(!$user || !$order) + if( !$user || !$order ) return false; // if an order URL wasn't passed in, grab it from the order - if(empty($order_url) && isset($order->order_url)) + if( empty( $order_url ) && isset( $order->order_url ) ) $order_url = $order->order_url; + // if an order URL wasn't passed in, grab it from the order + if(empty($order_url) && isset($order->invoice_url)) + $order_url = $order->invoice_url; + // still no order URL? bail - if(empty($order_url)) + if( empty( $order_url ) ) return false; - - $this->email = $user->user_email; - $this->subject = sprintf(__("Payment action required for your %s membership", 'paid-memberships-pro' ), get_option("blogname")); - - $this->template = "payment_action"; - $this->template = apply_filters("pmpro_email_template", $this->template, $this); + $email = new PMPro_Email_Template_Payment_Action( $user, $order_url ); + $email->send(); - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $user->display_name, - 'name' => $user->display_name, - 'display_name' => $user->display_name, - 'user_login' => $user->user_login, - 'sitename' => get_option( 'blogname' ), - 'siteemail' => get_option( 'pmpro_from_email' ), - 'order_link' => $order_url, - 'order_url' => $order_url, - 'levels_url' => pmpro_url( 'levels' ) - ); - - return $this->sendEmail(); } /** @@ -1598,48 +846,43 @@ function sendPaymentActionRequiredEmail($user = NULL, $order = NULL, $order_url * * @param object $user * @param MemberOrder $order - * @param string $invoice_url The link to the invoice that is generated by Stripe. + * @param string $order_url The url to the order that is generated by Stripe. * @return void */ - function sendPaymentActionRequiredAdminEmail($user = NULL, $order = NULL, $invoice_url = NULL) - { + function sendPaymentActionRequiredAdminEmail($user = NULL, $order = NULL, $order_url = NULL) { global $current_user; - if(!$user) + if( !$user ) $user = $current_user; - if(!$user || !$order) + if( !$user || !$order ) return false; // if an invoice URL wasn't passed in, grab it from the order - if(empty($invoice_url) && isset($order->invoice_url)) - $invoice_url = $order->invoice_url; + if( empty( $order_url ) && isset( $order->invoice_url ) ) + $order_url = $order->invoice_url; // still no invoice URL? bail - if(empty($invoice_url)) + if( empty( $order_url ) ) return false; - - $this->email = get_bloginfo("admin_email"); - $this->subject = sprintf(__("Payment action required: membership for %s at %s", 'paid-memberships-pro' ), $user->user_login, get_option("blogname")); - - $this->template = "payment_action_admin"; - $this->template = apply_filters("pmpro_email_template", $this->template, $this); + $email = new PMPro_Email_Template_Payment_Action_Admin( $user, $order_url ); + $email->send(); + } - $this->data = array( - 'subject' => $this->subject, - 'header_name' => $this->get_admin_name( $this->email ), - 'name' => $user->display_name, - 'display_name' => $user->display_name, - 'user_login' => $user->user_login, - 'sitename' => get_option('blogname'), - 'siteemail' => get_option('pmpro_from_email'), - 'user_email' => $user->user_email, - 'invoice_link' => $invoice_url, - 'invoice_url' => $invoice_url, - 'levels_url' => pmpro_url( 'levels' ) - ); - - return $this->sendEmail(); + /** + * Send the payment reminder email to a member. + * + * @param object $user The WordPress user object. + * @return void + * @since TBD + */ + function send_recurring_payment_reminder( $subscription_obj = NULL ) { + // Bail if we don't have a subscription object. + if ( ! $subscription_obj ) { + return false; + } + $email = new PMPro_Email_Template_Payment_Reminder( $subscription_obj ); + $email->send(); } /** diff --git a/classes/email-templates/class-pmpro-email-template-admin-change-admin.php b/classes/email-templates/class-pmpro-email-template-admin-change-admin.php new file mode 100644 index 000000000..e00565295 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-admin-change-admin.php @@ -0,0 +1,165 @@ +user = $user; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'admin_change_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 esc_html__( 'Admin Change (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'The site administrator can manually update a user\'s membership level through the WordPress admin. This email notifies the site administrator of the level update.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Membership for !!display_name!! at !!sitename!! has been changed", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'An administrator at !!sitename!! has changed a membership level for !!display_name!!.
+ +!!membership_change!!
+ +Log in to your WordPress admin here: !!login_url!!
', '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() { + $user = $this->user; + // If the user no longer has a membership level, set the membership_change text to "Membership has been cancelled." + if ( ! pmpro_hasMembershipLevel( null, $this->user->ID ) ) { + $membership_change = esc_html__( 'The user\'s membership has been cancelled.', 'paid-memberships-pro' ); + } else { + $membership_change = esc_html__( 'You can view the user\'s current memberships from their Edit Member page.', 'paid-memberships-pro' ); + } + + $email_template_variables = array( + 'membership_change' => $membership_change, + 'subject' => $this->get_default_subject(), + 'name' => $user->display_name, + 'display_name' => $user->display_name, + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + ); + return $email_template_variables; + } + + /** + * 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( + '!!membership_change!!' => esc_html__( 'Membership Level Change', 'paid-memberships-pro' ), + '!!subject!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user whose membership was changed.', '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; + } +} + +/** + * 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_admin_change_admin( $email_templates ) { + $email_templates['admin_change_admin'] = 'PMPro_Email_Template_Admin_Change_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_admin_change_admin' ); diff --git a/classes/email-templates/class-pmpro-email-template-admin-change.php b/classes/email-templates/class-pmpro-email-template-admin-change.php new file mode 100644 index 000000000..b7d7e7f2a --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-admin-change.php @@ -0,0 +1,165 @@ +user = $user; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'admin_change'; + } + + /** + * 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 esc_html__( 'Admin Change', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'The site administrator can manually update a user\'s membership through the WordPress admin. This email notifies the member of the level update.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Your membership at !!sitename!! has been changed", "paid-memberships-pro" ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'An administrator at !!sitename!! has changed your membership level.
+ +!!membership_change!!
+ +If you did not request this membership change and would like more information please contact us at !!siteemail!!
+ +Log in to your membership account here: !!login_url!!
', '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() { + $user = $this->user; + // If the user no longer has a membership level, set the membership_change text to "Membership has been cancelled." + if ( ! pmpro_hasMembershipLevel( null, $this->user->ID ) ) { + $membership_change = esc_html__( 'Your membership has been cancelled.', 'paid-memberships-pro' ); + } else { + $membership_change = esc_html__( 'You can view your current memberships by logging in and visiting your membership account page.', 'paid-memberships-pro' ); + } + + $email_template_variables = array( + 'membership_change' => $membership_change, + 'subject' => $this->get_default_subject(), + 'name' => $user->display_name, + 'display_name' => $user->display_name, + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + ); + return $email_template_variables; + } + + /** + * 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( + '!!membership_change!!' => esc_html__( 'Membership Level Change', 'paid-memberships-pro' ), + '!!subject!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the user whose membership was changed.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user whose membership was changed.', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } +} + +/** + * 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_change( $email_templates ) { + $email_templates['admin_change'] = 'PMPro_Email_Template_Admin_Change'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_change' ); diff --git a/classes/email-templates/class-pmpro-email-template-billing-admin.php b/classes/email-templates/class-pmpro-email-template-billing-admin.php new file mode 100644 index 000000000..245121459 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-billing-admin.php @@ -0,0 +1,209 @@ +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_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 esc_html__( 'Billing Information Updated (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'Members can update the payment method associated with their recurring subscription. This email is sent to the site administrator as a confirmation of a payment method update.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Billing information has been updated for !!user_login!! at !!sitename!!', 'paid-memberships-pro' ); + } + + public static function get_default_body() { + return wp_kses_post( 'The billing information for !!display_name!! at !!sitename!! has been changed.
+Account: !!display_name!! (!!user_email!!)
+
+ Billing Information:
+ !!billing_address!!
+
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
Log in to your WordPress dashboard here: !!login_url!!
', 'paid-memberships-pro' ); + + } + + /** + * 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() { + $base_email_template_variables_with_description = array( + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!subject!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'The billing name of the user.', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'The billing street address of the user.', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'The second billing street field address of the user.', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'The billing city of the user.', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'The billing state of the user.', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'The billing ZIP code of the user.', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'The billing country of the user.', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'The billing phone number of the user.', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'The type of credit card used.', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'The last four digits of the credit card number.', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'The expiration month of the credit card.', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'The expiration year of the credit card.', 'paid-memberships-pro' ), + ); + + return $base_email_template_variables_with_description; + } + + /** + * 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. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + public function get_email_template_variables() { + $order = $this->order; + $membership_level = pmpro_getLevel( $order->membership_id ); + $user = $this->user; + $email_template_variables = array( + 'name' => $user->display_name, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'user_login' => $user->user_login, + 'subject' => $this->get_default_subject(), + 'user_email' => $user->user_email, + 'display_name' => $this->get_recipient_name(), + '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, + ); + return $email_template_variables; + } +} + +/** + * 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_admin( $email_templates ) { + $email_templates['billing_admin'] = 'PMPro_Email_Template_Billing_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_billing_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-billing-failure-admin.php b/classes/email-templates/class-pmpro-email-template-billing-failure-admin.php new file mode 100644 index 000000000..31bab6847 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-billing-failure-admin.php @@ -0,0 +1,205 @@ +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 esc_html__( '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 esc_html__( '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 esc_html__( "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 wp_kses_post( 'The subscription payment for !!user_login!! for level !!membership_level_name!! at !!sitename!! has failed.
+Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+ +Log in to your WordPress admin here: !!login_url!!
', '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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user billing failed', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user billing failed', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'Billing Info Street 2', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info Zip', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( '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' ); + + diff --git a/classes/email-templates/class-pmpro-email-template-billing-failure.php b/classes/email-templates/class-pmpro-email-template-billing-failure.php new file mode 100644 index 000000000..3fdcf231d --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-billing-failure.php @@ -0,0 +1,198 @@ +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'; + } + + /** + * 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 esc_html__( 'Payment Failure', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent out if a recurring payment has failed, usually due to an expired or cancelled credit card. This email is sent to the member to allowing them time to update payment information without a disruption in access to your site.', 'paid-memberships-pro' ); + } + + /** + * Get the email subject. + * + * @since TBD + * + * @return string The email subject. + */ + public static function get_default_subject() { + return esc_html__( "Membership payment failed at !!sitename!!", 'paid-memberships-pro' ); + } + + /** + * Get the email body. + * + * @since TBD + * + * @return string The email body. + */ + public static function get_default_body() { + return wp_kses_post( 'The current subscription payment for level !!membership_level_name!! at !!sitename!! membership has failed. Please click the following link to log in and update your billing information to avoid account suspension.
!!login_url!!
Account: !!display_name!! (!!user_email!!)
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user billing failed', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user billing failed', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'Billing Info Street 2', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info Zip', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( '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( $email_templates ) { + $email_templates['billing_failure'] = 'PMPro_Email_Template_Billing_Failure'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_billing_failure' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-billing.php b/classes/email-templates/class-pmpro-email-template-billing.php new file mode 100644 index 000000000..226a5c363 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-billing.php @@ -0,0 +1,209 @@ +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'; + } + + /** + * 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 esc_html__( 'Billing Information Updated', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'Members can update the payment method associated with their recurring subscription. This email is sent to the member as a confirmation of a payment method update', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Your billing information has been updated at !!sitename!!', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Your billing information at !!sitename!! has been changed.
Account: !!display_name!! (!!user_email!!)
+
+ Billing Information:
+ !!billing_address!!
+
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
If you did not request a billing information change please contact us at !!siteemail!!
+Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ); + } + + /** + * 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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'Billing Info Street 2', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info Zip', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'Credit Card Expiration Year (yyyy format)', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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 ); + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name'=> $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'user_email' => $user->user_email, + 'display_name' => $this->get_recipient_name(), + '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, + ); + return $email_template_variables; + } + +} + +/** + * 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( $email_templates ) { + $email_templates['billing'] = 'PMPro_Email_Template_Billing'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_billing' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-cancel-admin.php b/classes/email-templates/class-pmpro-email-template-cancel-admin.php new file mode 100644 index 000000000..f18cddc50 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-cancel-admin.php @@ -0,0 +1,220 @@ +user = $user; + $this->cancelled_level_ids = $cancelled_level_ids; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'cancel_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 esc_html__('Cancel (admin)', 'paid-memberships-pro'); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'The site administrator can manually cancel a user\'s membership through the WordPress admin or the member can cancel their own membership through your site. This email is sent to the site administrator as confirmation of a cancelled membership.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Membership for !!user_login!! at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'The membership for !!user_login!! at !!sitename!! has been cancelled.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Start Date: !!startdate!!
+End Date: !!enddate!!
+ +Log in to your WordPress admin here: !!login_url!!
', 'paid-memberships-pro' ); + } + + /** + * 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( + '!!user_email!!' => esc_html__( 'The email address of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level that was cancelled.', 'paid-memberships-pro' ), + '!!startdate!!' => esc_html__( 'The start date of the membership level that was cancelled.', 'paid-memberships-pro' ), + '!!enddate!!' => esc_html__( 'The end date of the membership level that was cancelled.', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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() { + global $wpdb; + + $email_template_variables = array( + 'user_email' => $this->user->user_email, + 'display_name' => $this->user->display_name, + 'user_login' => $this->user->user_login, + ); + + if ( empty( $this->cancelled_level_ids ) ) { + $email_template_variables['membership_level_name'] = esc_html__( 'All Levels', 'paid-memberships-pro' ); + } elseif ( is_array( $this->cancelled_level_ids ) ) { + $email_template_variables['membership_level_name'] = pmpro_implodeToEnglish( $wpdb->get_col( "SELECT name FROM $wpdb->pmpro_membership_levels WHERE id IN('" . implode( "','", $this->cancelled_level_ids ) . "')" ) ); + } else { + $email_template_variables['membership_level_name'] = pmpro_implodeToEnglish( $wpdb->get_col( "SELECT name FROM $wpdb->pmpro_membership_levels WHERE id = '" . $this->cancelled_level_ids . "'" ) ); + } + + $startdate = $this->get_start_and_end_date( 'startdate' ); + + if( !empty( $startdate ) ) { + $email_template_variables['startdate'] = date_i18n( get_option( 'date_format' ), $startdate ); + } else { + $email_template_variables['startdate'] = ""; + } + + $enddate = $this->get_start_and_end_date( 'enddate' ); + + if( !empty( $enddate ) ) { + $email_template_variables['enddate'] = date_i18n( get_option( 'date_format' ), $enddate ); + } else { + $email_template_variables['enddate'] = ""; + } + + return $email_template_variables; + } + + /** + * Get the start or end date of the membership level that was cancelled. + * + * @since TBD + * @param string $end_or_start_date Either startdate or enddate. + * @return int The start or end date of the membership level that was cancelled. + * + */ + private function get_start_and_end_date( $end_or_start_date ) { + global $wpdb; + + $old_level_id = $this->cancelled_level_ids; + // if $this->cancelled_level_ids is an array, get the first level id + if( is_array( $this->cancelled_level_ids ) ) { + $old_level_id = $this->cancelled_level_ids[0]; + } + + return $wpdb->get_var( + "SELECT UNIX_TIMESTAMP(CONVERT_TZ(" . $end_or_start_date .", '+00:00', @@global.time_zone)) as " . $end_or_start_date . " + FROM $wpdb->pmpro_memberships_users + WHERE user_id = '" . $this->user->ID . "' + AND membership_id = '" . $old_level_id . "' + AND status IN('inactive', 'cancelled', 'admin_cancelled') + ORDER BY id DESC" ); + } +} + +/** + * 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_cancel_admin( $email_templates ) { + $email_templates['cancel_admin'] = 'PMPro_Email_Template_Cancel_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_cancel_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date-admin.php b/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date-admin.php new file mode 100644 index 000000000..3b458d769 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date-admin.php @@ -0,0 +1,171 @@ +user = $user; + $this->level_id = $level_id; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'cancel_on_next_payment_date_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 esc_html__( 'Cancelled Auto-Renewals (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'When a user cancels a membership with a recurring subscription, they will still have access until when their next payment would have been taken. This email is sent to the site administrator to notify them of this change.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Payment subscription for !!user_login!! at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'The payment subscription for !!user_login!! at !!sitename!! has been cancelled.
+Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Start Date: !!startdate!!
+Expiration Date: !!enddate!!
', '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( + 'user_login' => esc_html__( 'The user\'s username.', 'paid-memberships-pro' ), + 'user_email' => esc_html__( 'The user\'s email address.', 'paid-memberships-pro' ), + 'display_name' => esc_html__( 'The user\'s display name.', 'paid-memberships-pro' ), + 'membership_id' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + 'membership_level_name' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + 'startdate' => esc_html__( 'The start date of the membership level.', 'paid-memberships-pro' ), + 'enddate' => esc_html__( 'The end date of the membership level.', '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() { + $user = $this->user; + $level = pmpro_getLevel( $this->level_id ); + + $email_template_variables = array( + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + 'display_name' => $user->display_name, + 'membership_id' => $level->id, + 'membership_level_name' => $level->name, + 'startdate' => date_i18n( get_option( 'date_format' ), $level->startdate ), + 'enddate' => date_i18n( get_option( 'date_format' ), $level->enddate ), + ); + return $email_template_variables; + } +} +// Register the email template. + +/** + * 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_cancel_on_next_payment_date_admin( $email_templates ) { + $email_templates['cancel_on_next_payment_date_admin'] = 'PMPro_Email_Template_Cancel_On_Next_Payment_Date_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_cancel_on_next_payment_date_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date.php b/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date.php new file mode 100644 index 000000000..6516c0bf5 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date.php @@ -0,0 +1,172 @@ +user = $user; + $this->level_id = $level_id; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'cancel_on_next_payment_date'; + } + + /** + * 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 esc_html__( 'Cancelled Auto-Renewals', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'When a user cancels a membership with a recurring subscription, they will still have access until when their next payment would have been taken. This email is sent to the member to notify them of this change.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Your payment subscription at !!sitename!! has been CANCELLED', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Your payment subscription at !!sitename!! has been cancelled.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Your access will expire on !!enddate!!.
', 'paid-memberships-pro' ); + } + + /** + * 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( + 'user_login' => esc_html__( 'The user\'s username.', 'paid-memberships-pro' ), + 'user_email' => esc_html__( 'The user\'s email address.', 'paid-memberships-pro' ), + 'display_name' => esc_html__( 'The user\'s display name.', 'paid-memberships-pro' ), + 'membership_id' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + 'membership_level_name' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + 'startdate' => esc_html__( 'The start date of the membership level.', 'paid-memberships-pro' ), + 'enddate' => esc_html__( 'The end date of the membership level.', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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() { + $user = $this->user; + $level = pmpro_getLevel( $this->level_id ); + + $email_template_variables = array( + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + 'display_name' => $user->display_name, + 'membership_id' => $level->id, + 'membership_level_name' => $level->name, + 'startdate' => date_i18n( get_option( 'date_format' ), $level->startdate ), + 'enddate' => date_i18n( get_option( 'date_format' ), $level->enddate ), + ); + return $email_template_variables; + } +} + + +/** + * 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_cancel_on_next_payment_date( $email_templates ) { + $email_templates['cancel_on_next_payment_date'] = 'PMPro_Email_Template_Cancel_On_Next_Payment_Date'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_cancel_on_next_payment_date' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-cancel.php b/classes/email-templates/class-pmpro-email-template-cancel.php new file mode 100644 index 000000000..5efb882ae --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-cancel.php @@ -0,0 +1,178 @@ +user = $user; + $this->cancelled_level_ids = $cancelled_level_ids; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'cancel'; + } + + /** + * 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 esc_html__( 'Cancel', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'The site administrator can manually cancel a user\'s membership through the WordPress admin or the member can cancel their own membership through your site. This email is sent to the member as confirmation of a cancelled membership.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Your membership at !!sitename!! has been CANCELLED', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Your membership at !!sitename!! has been cancelled.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+ +If you did not request this cancellation and would like more information please contact us at !!siteemail!!
', 'paid-memberships-pro' ); + } + + /** + * 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( + '!!user_email!!' => esc_html__( 'The email address of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the user who cancelled their membership.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level that was cancelled.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level that was cancelled.', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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() { + global $wpdb; + + $email_template_variables = array( + 'user_email' => $this->user->user_email, + 'display_name' => $this->user->display_name, + 'user_login' => $this->user->user_login, + ); + + if ( empty( $this->cancelled_level_ids ) ) { + $email_template_variables['membership_id'] = ''; + $email_template_variables['membership_level_name'] = esc_html__( 'All Levels', 'paid-memberships-pro' ); + } elseif ( is_array( $this->cancelled_level_ids ) ) { + $email_template_variables['membership_id'] = $this->cancelled_level_ids[0]; // Pass just the first as the level id. + $email_template_variables['membership_level_name'] = pmpro_implodeToEnglish( $wpdb->get_col( "SELECT name FROM $wpdb->pmpro_membership_levels WHERE id IN('" . implode( "','", $this->cancelled_level_ids ) . "')" ) ); + } else { + $email_template_variables['membership_id'] = $this->cancelled_level_ids; + $email_template_variables['membership_level_name'] = pmpro_implodeToEnglish( $wpdb->get_col( "SELECT name FROM $wpdb->pmpro_membership_levels WHERE id = '" . $this->cancelled_level_ids . "'" ) ); + } + + return $email_template_variables; + } +} + +/** + * 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_cancel( $email_templates ) { + $email_templates['cancel'] = 'PMPro_Email_Template_Cancel'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_cancel' ); + diff --git a/classes/email-templates/class-pmpro-email-template-checkout-check-admin.php b/classes/email-templates/class-pmpro-email-template-checkout-check-admin.php new file mode 100644 index 000000000..f00d771a6 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-check-admin.php @@ -0,0 +1,240 @@ +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 'checkout_check_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 esc_html__( 'Checkout - Pay by Check (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + $check_gateway_label = get_option( 'pmpro_check_gateway_label' ) ? get_option( 'pmpro_check_gateway_label' ) : esc_html__( 'Check', 'paid-memberships-pro' ); + return sprintf( esc_html__('This is the membership confirmation email sent to the site administrator for every membership checkout using the "%s (Pay by Check)" gateway.', 'paid-memberships-pro' ), $check_gateway_label ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Member checkout for !!membership_level_name!! at !!sitename!!', 'paid-memberships-pro' ); + } + + /** + * Get the default body for the email. + * + * @since TBD + * + * @return string The default body for the email. + */ + public static function get_default_body() { + $check_gateway_label = get_option( 'pmpro_check_gateway_label' ) ? get_option( 'pmpro_check_gateway_label' ) : esc_html__( 'Check', 'paid-memberships-pro' ); + + return sprintf( wp_kses_post( 'There was a new member checkout at !!sitename!!.
+ +They have chosen to pay by %s.
+ +Below are details about the new membership account and a receipt for the initial membership order.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Membership Fee: !!membership_cost!!
+ !!membership_expiration!! !!discount_code!! + +
+ Order #!!order_id!! on !!order_date!!
+ Total Billed: !!order_total!!
+
Log in to your membership account here: !!login_url!!
','paid-memberships-pro' ), $check_gateway_label ); + } + + /** + * 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. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + public function get_email_template_variables() { + global $wpdb; + + $order = $this->order; + $user = $this->user; + $membership_level = pmpro_getLevel( $order->membership_id ); + + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } else { + $confirmation_message = ''; + } + + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } else { + $membership_expiration = ""; + } + + if( $order->getDiscountCode() ) { + $discount_code = "" . esc_html__( "Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } else { + $discount_code = ""; + } + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost($membership_level), + 'user_email' => $user->user_email, + 'order_id' => $order->code, + 'order_total' => $order->get_formatted_total(), + 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), + '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, + 'membership_expiration' => $membership_expiration, + 'discount_code' => $discount_code + ); + + return $email_template_variables; + } + + /** + * 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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + ); + } + +} + +/** + * 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_checkout_check_admin( $email_templates ) { + $email_templates['checkout_check_admin'] = 'PMPro_Email_Template_Checkout_Check_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_check_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-checkout-check.php b/classes/email-templates/class-pmpro-email-template-checkout-check.php new file mode 100644 index 000000000..6c96c1a96 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-check.php @@ -0,0 +1,206 @@ +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 'checkout_check'; + } + + /** + * 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 esc_html__( 'Checkout - Pay by Check', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This is a membership confirmation welcome email sent to a new member or to existing members that change their level using the "Pay by Check" gateway.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Your membership confirmation for !!sitename!!', 'paid-memberships-pro' ); + } + + /** + * Get the default body for the email. + * + * @since TBD + * + * @return string The default body for the email. + */ + public static function get_default_body() { + return wp_kses_post('Thank you for your membership to !!sitename!!. Your membership account is now active.
+ + !!membership_level_confirmation_message!! + + !!instructions!! + +Below are details about your membership account and a receipt for your initial membership order.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Membership Fee: !!membership_cost!!
+ !!membership_expiration!! !!discount_code!! + +
+ Order #!!order_id!! on !!order_date!!
+ Total Billed: !!order_total!!
+
Log in to your membership account here: !!login_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the membership level.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The ID of the order.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date of the order.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total cost of the order.', '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 ); + + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } else { + $confirmation_message = ''; + } + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost($membership_level), + 'user_email' => $user->user_email, + 'order_id' => $order->code, + 'order_total' => $order->get_formatted_total(), + 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), + ); + + return $email_template_variables; + } + +} + +/** + * 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_checkout_check( $email_templates ) { + $email_templates['checkout_check'] = 'PMPro_Email_Template_Checkout_Check'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_check' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-checkout-free-admin.php b/classes/email-templates/class-pmpro-email-template-checkout-free-admin.php new file mode 100644 index 000000000..b6fa088e7 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-free-admin.php @@ -0,0 +1,209 @@ +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 'checkout_free_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 esc_html__( 'Checkout - Free (admin)', 'paid-memberships-pro' ); + } + + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This is the membership confirmation email sent to the site administrator for every membership checkout that has no charge.', 'paid-memberships-pro' ); + + } + + /** + * Get the email subject. + * + * @since TBD + * + * @return string The email subject. + */ + public static function get_default_subject() { + return esc_html__( "Member checkout for !!membership_level_name!! at !!sitename!!", 'paid-memberships-pro' ); + } + + /** + * Get the email body. + * + * @since TBD + * + * @return string The email body. + */ + public static function get_default_body() { + return wp_kses_post( 'There was a new member checkout at !!sitename!!.
+Below are details about the new membership account.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+ !!membership_expiration!! !!discount_code!! + +Log in to your membership account here: !!login_url!!
', '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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the membership level.', '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() { + global $wpdb; + $order = $this->order; + $user = $this->user; + $membership_level = pmpro_getLevel( $order->membership_id ); + + $confirmation_message = ''; + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } + + $membership_expiration = ''; + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } + + $discount_code = ''; + if( $order->getDiscountCode() ) { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } + + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'membership_level_confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost( $membership_level ), + 'user_email' => $user->user_email, + 'membership_expiration' => $membership_expiration, + 'discount_code' => $discount_code, + ); + + return $email_template_variables; + } + +} + + +/** + * 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_checkout_free_admin( $email_templates ) { + $email_templates['checkout_free_admin'] = 'PMPro_Email_Template_Checkout_Free_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_free_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-checkout-free.php b/classes/email-templates/class-pmpro-email-template-checkout-free.php new file mode 100644 index 000000000..bc4ec2afe --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-free.php @@ -0,0 +1,202 @@ +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 'checkout_free'; + } + + /** + * 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 esc_html__( 'Checkout - Free', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This is a membership confirmation welcome email sent to a new member or to existing members that change their level when the level has no charge.', 'paid-memberships-pro' ); + } + + /** + * Get the email subject. + * + * @since TBD + * + * @return string The email subject. + */ + public static function get_default_subject() { + return sprintf( esc_html__( 'Your membership confirmation for %s', 'paid-memberships-pro' ), get_option( 'blogname' ) ); + } + + /** + * Get the email body. + * + * @since TBD + * + * @return string The email body. + */ + public static function get_default_body() { + return wp_kses_post( 'Thank you for your membership to !!sitename!!. Your membership account is now active.
+ !!membership_level_confirmation_message!! +Below are details about your membership account.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+ !!membership_expiration!! !!discount_code!!', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the membership level.', '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() { + global $wpdb; + $order = $this->order; + $user = $this->user; + $membership_level = pmpro_getLevel( $order->membership_id ); + + $confirmation_message = ''; + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } + + $membership_expiration = ''; + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } + + $discount_code = ''; + if( $order->getDiscountCode() ) { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } + + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'membership_level_confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost( $membership_level ), + 'user_email' => $user->user_email, + 'membership_expiration' => $membership_expiration, + 'discount_code' => $discount_code, + ); + + return $email_template_variables; + } + +} + +/** + * 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_checkout_free( $email_templates ) { + $email_templates['checkout_free'] = 'PMPro_Email_Template_Checkout_Free'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_free' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-checkout-paid-admin.php b/classes/email-templates/class-pmpro-email-template-checkout-paid-admin.php new file mode 100644 index 000000000..e36e2dcef --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-paid-admin.php @@ -0,0 +1,259 @@ +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 'checkout_paid_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 esc_html__( 'Checkout - Paid (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This is the membership confirmation email sent to the site administrator for every paid membership checkout on the site.', 'paid-memberships-pro' ); + } + + /** + * Get the email subject. + * + * @since TBD + * + * @return string The email subject. + */ + public static function get_default_subject() { + return esc_html__( 'Member checkout for !!membership_level_name!! at !!sitename!!', 'paid-memberships-pro' ); + } + + /** + * Get the email body. + * + * @since TBD + * + * @return string The email body. + */ + public static function get_default_body() { + return wp_kses_post( 'There was a new member checkout at !!sitename!!.
+Below are details about the new membership account and a receipt for the initial membership order.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Membership Fee: !!membership_cost!!
+ !!membership_expiration!! !!discount_code!! + +
+ Order #!!order_id!! on !!order_date!!
+ Total Billed: !!order_total!!
+
+ Billing Information:
+ !!billing_address!!
+
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
Log in to your membership account here: !!login_url!!
', '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. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + public function get_email_template_variables() { + global $wpdb; + $order = $this->order; + $user = $this->user; + $membership_level = pmpro_getLevel( $order->membership_id ); + + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } else { + $confirmation_message = ''; + } + + $membership_expiration = ''; + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } + + $discount_code = ''; + if( $order->getDiscountCode() ) { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'membership_level_confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost($membership_level), + 'user_email' => $user->user_email, + 'order_id' => $order->code, + 'order_total' => $order->get_formatted_total(), + 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), + '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 ), + '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, + 'membership_expiration' => $membership_expiration, + 'discount_code' => $discount_code, + + + ); + + return $email_template_variables; + } + + /** + * 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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the membership level.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The ID of the order.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date of the order.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total cost of the order.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'Billing Info Street 2', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info Zip', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'Credit Card Expiration Year (yyyy format)', 'paid-memberships-pro' ), + ); + } +} + +/** + * 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_checkout_paid_admin( $email_templates ) { + $email_templates['checkout_paid_admin'] = 'PMPro_Email_Template_Checkout_Paid_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_paid_admin' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-checkout-paid.php b/classes/email-templates/class-pmpro-email-template-checkout-paid.php new file mode 100644 index 000000000..3f983fe3f --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-checkout-paid.php @@ -0,0 +1,263 @@ +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 'checkout_paid'; + } + + /** + * 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 esc_html__( 'Checkout - Paid', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The help text. + */ + public static function get_template_description() { + return esc_html__( 'This is a membership confirmation welcome email sent to a new member or to existing members that change their level and complete a paid checkout on the site.', 'paid-memberships-pro' ); + } + + /** + * Get the email subject. + * + * @since TBD + * + * @return string The email subject. + */ + public static function get_default_subject() { + return esc_html__( "Your membership confirmation for !!sitename!!", 'paid-memberships-pro' ); + } + + /** + * Get the email body. + * + * @since TBD + * + * @return string The email body. + */ + public static function get_default_body() { + return wp_kses_post( 'Thank you for your membership to !!sitename!!. Your membership account is now active.
+ !!membership_level_confirmation_message!! +Below are details about your membership account and a receipt for your initial membership order.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+Membership Fee: !!membership_cost!!
+ !!membership_expiration!! !!discount_code!! + +
+ Order #!!order_id!! on !!order_date!!
+ Total Billed: !!order_total!!
+
+ Billing Information:
+ !!billing_address!!
+
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
Log in to your membership account here: !!login_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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() { + global $wpdb; + $order = $this->order; + $user = $this->user; + $membership_level = pmpro_getLevel( $order->membership_id ); + + $confirmation_in_email = get_pmpro_membership_level_meta( $membership_level->id, 'confirmation_in_email', true ); + if ( ! empty( $confirmation_in_email ) ) { + $confirmation_message = $membership_level->confirmation; + } else { + $confirmation_message = ''; + } + + $membership_expiration = ''; + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } + + $discount_code = ''; + if( $order->getDiscountCode() ) { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $this->get_recipient_name(), + 'display_name' => $this->get_recipient_name(), + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'membership_level_confirmation_message' => $confirmation_message, + 'membership_cost' => pmpro_getLevelCost($membership_level), + 'user_email' => $user->user_email, + 'order_id' => $order->code, + 'order_total' => $order->get_formatted_total(), + 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), + '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 ), + '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, + 'membership_expiration' => $membership_expiration, + 'discount_code' => $discount_code, + + + ); + + return $email_template_variables; + } + + /** + * 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!!' => esc_html__( 'The subject of the email.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The login name of the email recipient.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!confirmation_message!!' => esc_html__( 'The confirmation message for the membership level.', 'paid-memberships-pro' ), + '!!membership_cost!!' => esc_html__( 'The cost of the membership level.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the email recipient.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the membership level.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The ID of the order.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date of the order.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total cost of the order.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'Billing Info Name', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'Billing Info Street', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'Billing Info Street 2', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'Billing Info City', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'Billing Info State', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'Billing Info Zip', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'Billing Info Country', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'Billing Info Phone', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'Billing Info Complete Address', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'Credit Card Type', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'Credit Card Number (last 4 digits)', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'Credit Card Expiration Month (mm format)', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'Credit Card Expiration Year (yyyy format)', 'paid-memberships-pro' ), + ); + } +} + +/** + * 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_checkout_paid( $email_templates ) { + $email_templates['checkout_paid'] = 'PMPro_Email_Template_Checkout_Paid'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_checkout_paid' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-credit-card-expiring.php b/classes/email-templates/class-pmpro-email-template-credit-card-expiring.php new file mode 100644 index 000000000..a4946d78b --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-credit-card-expiring.php @@ -0,0 +1,209 @@ +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 'credit_card_expiring'; + } + + /** + * 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 esc_html__( 'Credit Card Expiring', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This is the membership confirmation email sent to the site administrator for every paid membership checkout on the site.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Credit card on file expiring soon at !!sitename!!', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'The payment method used for your membership at !!sitename!! will expire soon. Please click the following link to log in and update your billing information to avoid account suspension. !!login_url!!
+Account: !!display_name!! (!!user_email!!)
+The most recent account information we have on file is:
+ +!!billing_name!! + !!billing_address!! +
+ +
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
Your membership at !!sitename!! has ended.
+ +Thank you for your support.
+ +View our current membership offerings here: !!levels_url!!
+ +Log in to manage your account here: !!login_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', '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() { + global $wpdb; + // If we don't have a level ID, query the user's most recently expired level from the database. + if ( empty( $this->membership_id ) ) { + $membership_id = $wpdb->get_var( + $wpdb->prepare( + "SELECT membership_id FROM $wpdb->pmpro_memberships_users + WHERE user_id = %d + AND status = 'expired' + ORDER BY enddate DESC + LIMIT 1", + $this->user->ID + ) + ); + + // If we still don't have a level ID, bail. + if ( empty( $membership_id ) ) { + $membership_id = 0; + } + } + + // Get the membership level object. + $membership_level = pmpro_getLevel( $membership_id ); + + return array( + "subject" => $this->get_default_subject(), + "name" => $this->user->display_name, + "user_login" => $this->user->user_login, + "display_name" => $this->user->display_name, + "user_email" => $this->user->user_email, + "membership_id" => ( ! empty( $membership_level ) && ! empty( $membership_level->id ) ) ? $membership_level->id : 0, + "membership_level_name" => ( ! empty( $membership_level ) && ! empty( $membership_level->name ) ) ? $membership_level->name : '[' . esc_html( 'deleted', 'paid-memberships-pro' ) . ']', + ); + } +} + +/** + * 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_membership_expired( $email_templates ) { + $email_templates['membership_expired'] = 'PMPro_Email_Template_Membership_Expired'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_membership_expired' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-membership-expiring.php b/classes/email-templates/class-pmpro-email-template-membership-expiring.php new file mode 100644 index 000000000..9b638ba07 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-membership-expiring.php @@ -0,0 +1,194 @@ +user = $user; + $this->membership_id = $membership_id; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'membership_expiring'; + } + + /** + * 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 esc_html__( 'Membership Expiring', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the member when their expiration date is approaching, at an interval based on the term of the membership.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Your membership at !!sitename!! will end soon", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Thank you for your membership to !!sitename!!. This is just a reminder that your membership will end on !!enddate!!.
+ +Account: !!display_name!! (!!user_email!!)
+Membership Level: !!membership_level_name!!
+ +Log in to your membership account here: !!login_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!enddate!!' => esc_html__( 'The expiration date of the membership level.', '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() { + global $wpdb; + // If we don't have a level ID, query the user's most recently expired level from the database. + if ( empty( $this->membership_id ) ) { + $membership_id = $wpdb->get_var( + $wpdb->prepare( + "SELECT membership_id FROM $wpdb->pmpro_memberships_users + WHERE user_id = %d + AND status = 'expired' + ORDER BY enddate DESC + LIMIT 1", + $this->user->ID + ) + ); + + // If we still don't have a level ID, bail. + if ( empty( $membership_id ) ) { + $membership_id = 0; + } + } + + // Get the membership level object. + if ( empty( $membership_id ) ) { + $membership_level = pmpro_getMembershipLevelForUser($this->user->ID); + } else { + $membership_level = pmpro_getSpecificMembershipLevelForUser($this->user->ID, $membership_id); + } + + return array( + "subject" => $this->get_default_subject(), + "name" => $this->user->display_name, + "user_login" => $this->user->user_login, + "display_name" => $this->user->display_name, + "user_email" => $this->user->user_email, + "membership_id" => ( ! empty( $membership_level ) && ! empty( $membership_level->id ) ) ? $membership_level->id : 0, + "membership_level_name" => ( ! empty( $membership_level ) && ! empty( $membership_level->name ) ) ? $membership_level->name : '[' . esc_html( 'deleted', 'paid-memberships-pro' ) . ']', + "enddate" => date_i18n( get_option('date_format'), $membership_level->enddate ), + ); + } +} + +/** + * 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_membership_expiring( $email_templates ) { + $email_templates['membership_expiring'] = 'PMPro_Email_Template_Membership_Expiring'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_membership_expiring' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-payment-action-admin.php b/classes/email-templates/class-pmpro-email-template-payment-action-admin.php new file mode 100644 index 000000000..6a20eae4d --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-payment-action-admin.php @@ -0,0 +1,171 @@ +user = $user; + $this->order_url = $order_url; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'payment_action_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 esc_html__( 'Payment Action Required (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the site administrator when an attempted membership checkout requires additional customer authentication.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Payment action required: membership for !!user_login!! at !!sitename!!", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'A payment at !!sitename!! for !!user_login!! requires additional customer authentication to complete.
+Below is a copy of the email we sent to !!user_email!! to notify them that they need to complete their payment:
+ +Customer authentication is required to finish setting up your subscription at !!sitename!!.
+ +Please complete the verification steps issued by your payment provider at the following link:
+!!order_url!!
', '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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!order_link!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!invoice_url!!' => esc_html__( 'The URL of the order. Legacy purpose', '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() { + $user = $this->user; + $order_url = $this->order_url; + return array( + "subject" => $this->get_default_subject(), + "name" => $user->display_name, + "user_login" => $user->user_login, + "display_name" => $user->display_name, + "order_link" => $order_url, + "order_url" => $order_url, + "invoice_url" => $order_url, // Legacy purpose, remove in future version + ); + } +} + +/** + * 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_payment_action_admin( $email_templates ) { + $email_templates['payment_action_admin'] = 'PMPro_Email_Template_Payment_Action_Admin'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_payment_action_admin' ); + diff --git a/classes/email-templates/class-pmpro-email-template-payment-action.php b/classes/email-templates/class-pmpro-email-template-payment-action.php new file mode 100644 index 000000000..6a31a31f4 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-payment-action.php @@ -0,0 +1,167 @@ +user = $user; + $this->order_url = $order_url; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'payment_action'; + } + + /** + * 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 esc_html__( 'Payment Action Required', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the user when an attempted membership checkout requires additional customer authentication.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Payment action required for your !!sitename!! membership", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Customer authentication is required to finish setting up your subscription at !!sitename!!.
+ +Please complete the verification steps issued by your payment provider at the following link:
+!!order_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!order_link!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!invoice_url!!' => esc_html__( 'The URL of the order. Legacy purpose', 'paid-memberships-pro' ), + '!!levels_url!!' => esc_html__( 'The URL of the membership levels page.', '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() { + $user = $this->user; + $order_url = $this->order_url; + return array( + "subject" => $this->get_default_subject(), + "name" => $user->display_name, + "user_login" => $user->user_login, + "display_name" => $user->display_name, + "order_link" => $order_url, + "order_url" => $order_url, + "invoice_url" => $order_url, // Legacy purpose, remove in future version + "levels_url" => pmpro_url( 'levels' ) + ); + } +} + +/** + * 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_payment_action( $email_templates ) { + $email_templates['payment_action'] = 'PMPro_Email_Template_Payment_Action'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_payment_action' ); diff --git a/classes/email-templates/class-pmpro-email-template-payment-receipt.php b/classes/email-templates/class-pmpro-email-template-payment-receipt.php new file mode 100644 index 000000000..2c7164bfc --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-payment-receipt.php @@ -0,0 +1,256 @@ + +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 'invoice'; + } + + /** + * 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 esc_html__( 'Recurring Payment Receipt', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the member each time a new subscription payment is made.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Recurring payment receipt for !!sitename!! membership", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Thank you for your membership to !!sitename!!. Below is a receipt for your most recent membership order.
+ +Account: !!display_name!! (!!user_email!!)
+
+ Order #!!order_id!! on !!order_date!!
+ Total Billed: !!order_total!!
+
+ Billing Information:
+ !!billing_address!!
+
+ !!cardtype!!: !!accountnumber!!
+ Expires: !!expirationmonth!!/!!expirationyear!!
+
Log in to your membership account here: !!login_url!!
+To view an online version of this order, click here: !!order_url!!
', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->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!!' => esc_html__( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!user_login!!' => esc_html__( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The order ID.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total amount of the order.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date of the order.', 'paid-memberships-pro' ), + '!!order_link!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'The URL of the order.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'The name of the billing contact.', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'The street address of the billing contact.', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'The second line of the street address of the billing contact.', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'The city of the billing contact.', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'The state of the billing contact.', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'The ZIP code of the billing contact.', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'The country of the billing contact.', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'The phone number of the billing contact.', 'paid-memberships-pro' ), + '!!billing_address!!' => esc_html__( 'The formatted billing address.', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'The type of credit card used for the order.', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'The last four digits of the credit card used for the order.', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'The expiration month of the credit card used for the order.', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'The expiration year of the credit card used for the order.', 'paid-memberships-pro' ), + '!!discount_code!!' => esc_html__( 'The discount code used for the order.', 'paid-memberships-pro' ), + '!!membership_expiration!!' => esc_html__( 'The expiration date of the membership level.', '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() { + global $wpdb; + $user = $this->user; + $order = $this->order; + //If user is not the same one from order, let's get the user from order to fill the email + if( $order->user_id != $user->ID ) { + $user = get_userdata( $order->user_id ); + } + $membership_level = pmpro_getLevel( $order->membership_id ); + + //Get discount code if it exists + $discount_code = ""; + if( $order->getDiscountCode() && !empty( $order->discount_code->code ) ) { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code->code . "
\n"; + } else { + $discount_code = "" . esc_html__("Discount Code", 'paid-memberships-pro' ) . ": " . $order->discount_code . "
\n"; + } + + //Get membership expiration date + $enddate = $wpdb->get_var("SELECT UNIX_TIMESTAMP(CONVERT_TZ(enddate, '+00:00', @@global.time_zone)) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . $user->ID . "' AND status = 'active' LIMIT 1"); + if( $enddate ) { + $membership_expiration = "" . sprintf(__("This membership will expire on %s.", 'paid-memberships-pro' ), date_i18n(get_option('date_format'), $enddate)) . "
\n"; + } else { + $membership_expiration = ""; + } + + $email_template_variables = array( + 'subject' => $this->get_default_subject(), + 'name' => $user->display_name, + 'display_name' => $user->display_name, + 'user_login' => $user->user_login, + 'membership_id' => $membership_level->id, + 'membership_level_name' => $membership_level->name, + 'user_email' => $user->user_email, + 'order_id' => $order->code, + 'order_total' => $order->get_formatted_total(), + 'order_date' => date_i18n( get_option( 'date_format' ), $order->getTimestamp() ), + 'order_link' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + 'order_url' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + '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, + 'discount_code' => $discount_code, + 'membership_expiration' => $membership_expiration + ); + + return $email_template_variables; + } +} + +/** + * 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_payment_receipt( $email_templates ) { + $email_templates['invoice'] = 'PMPro_Email_Template_Payment_Receipt'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_payment_receipt' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-payment-reminder.php b/classes/email-templates/class-pmpro-email-template-payment-reminder.php new file mode 100644 index 000000000..0584dfb3c --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-payment-reminder.php @@ -0,0 +1,161 @@ +subscription_obj = $subscription_obj; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'membership_recurring'; + } + + /** + * 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 esc_html__( 'Membership Recurring', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent when a subscription is approaching its renewal date. The additional placeholders !!renewaldate!! and !!billing_amount!! can be used to print the date that the subscription will renew and the renewal price.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( "Your membership at !!sitename!! will end soon", 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Thank you for your membership to !!sitename!!.
+ +This is just a reminder that your !!membership_level_name!! membership will automatically renew on !!renewaldate!!.
+ +Account: !!display_name!! (!!user_email!!)
+ +If for some reason you do not want to renew your membership you can cancel by clicking here: !!cancel_link!!
', '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() { + $user = get_userdata( $this->subscription_obj->get_user_id() ); + return $user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + $user = get_userdata( $this->subscription_obj->get_user_id() ); + 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( + 'membership_level_name' => esc_html__( 'The name of the membership level.', 'paid-memberships-pro' ), + 'renewaldate' => esc_html__( 'The date of the next payment date.', 'paid-memberships-pro' ), + 'display_name' => esc_html__( 'The display name of the user.', 'paid-memberships-pro' ), + 'user_email' => esc_html__( 'The email address of the user.', 'paid-memberships-pro' ), + 'cancel_link' => esc_html__( 'The link to cancel the subscription.', '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() { + $subscription_obj = $this->subscription_obj; + $membership_id = $subscription_obj->get_membership_level_id(); + $membership_level = pmpro_getLevel( $membership_id ); + $user = get_userdata( $subscription_obj->get_user_id() ); + + return array( + 'membership_level_name' => $membership_level->name, + 'renewaldate' => date_i18n( get_option( 'date_format' ), $subscription_obj->get_next_payment_date() ), + 'display_name' => $user->display_name, + 'user_email' => $user->user_email, + 'cancel_link' => wp_login_url( pmpro_url( 'cancel' ) ), + ); + } +} + +/** + * 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_membership_recurring( $email_templates ) { + $email_templates['membership_recurring'] = 'PMPro_Email_Template_Payment_Reminder'; + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_membership_recurring' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template-refund-admin.php b/classes/email-templates/class-pmpro-email-template-refund-admin.php new file mode 100644 index 000000000..8381a2945 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-refund-admin.php @@ -0,0 +1,221 @@ +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 'refund_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 esc_html__( 'Refund (admin)', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the admin as confirmation of a refunded payment. The email is sent after your + membership site receives notification of a successful payment refund through your gateway.', 'paid-memberships-pro' ); + + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Order #!!order_id!! at !!sitename!! has been REFUNDED', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Order #!!order_id!! at !!sitename!! has been refunded.
+ +Account: !!display_name!! (!!user_email!!)
+
+ Order #!!order_id!! on !!order_date!!
+ Total Refunded: !!order_total!!
+
Log in to your WordPress admin here: !!login_url!!
', 'paid-memberships-pro' ); + } + + /** + * 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( + '!!user_login!!' => esc_html__( 'The login name of the user who requested the refund.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user who requested the refund.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user who requested the refund.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level that was refunded.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level that was refunded.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The order ID of the refunded order.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total amount refunded.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date the refund was processed.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'The billing name associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'The billing street address associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'The billing street address line 2 associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'The billing city associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'The billing state associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'The billing zip code associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'The billing country associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'The billing phone number associated with the refunded order.', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'The card type used for the refunded order.', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'The last four digits of the account number used for the refunded order.', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'The expiration month of the card used for the refunded order.', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'The expiration year of the card used for the refunded order.', 'paid-memberships-pro' ), + '!!order_link!!' => esc_html__( 'The URL to the invoice for the refunded order.', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'The URL to the invoice for the refunded order.', '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. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + public function get_email_template_variables() { + + $user = $this->user; + $order = $this->order; + $level = pmpro_getLevel( $order->membership_id ); + + $email_template_variables = array( + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + 'display_name' => $user->display_name, + 'membership_id' => $order->membership_id, + 'membership_level_name' => $level->name, + 'order_id' => $order->code, + 'order_total' => $order->total, + 'order_date' => date_i18n( get_option( 'date_format' ), $order->timestamp ), + '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, + 'order_link' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + 'order_url' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + '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 + ), + ); + + return $email_template_variables; + + } +} + +/** + * 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_refund_admin( $email_templates ) { + $email_templates['refund_admin'] = 'PMPro_Email_Template_Refund_Admin'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_refund_admin' ); diff --git a/classes/email-templates/class-pmpro-email-template-refund.php b/classes/email-templates/class-pmpro-email-template-refund.php new file mode 100644 index 000000000..d0ce2b652 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-refund.php @@ -0,0 +1,220 @@ +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 'refund'; + } + + /** + * 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 esc_html__( 'Refund', 'paid-memberships-pro' ); + } + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + public static function get_template_description() { + return esc_html__( 'This email is sent to the member as confirmation of a refunded payment. The email is sent after your + membership site receives notification of a successful payment refund through your gateway.', 'paid-memberships-pro' ); + } + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + public static function get_default_subject() { + return esc_html__( 'Order #!!order_id!! at !!sitename!! has been REFUNDED', 'paid-memberships-pro' ); + } + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + public static function get_default_body() { + return wp_kses_post( 'Order #!!order_id!! at !!sitename!! has been refunded.
+ +Account: !!display_name!! (!!user_email!!)
+
+ Order #!!order_id!! on !!order_date!!
+ Total Refunded: !!order_total!!
+
Log in to your membership account here: !!login_url!!
+To view an online version of this order, click here: !!order_url!!
+ +If you did not request this refund and would like more information please contact us at !!siteemail!!
', 'paid-memberships-pro' ); + } + + /** + * 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( + '!!user_login!!' => esc_html__( 'The login name of the user who requested the refund.', 'paid-memberships-pro' ), + '!!user_email!!' => esc_html__( 'The email address of the user who requested the refund.', 'paid-memberships-pro' ), + '!!display_name!!' => esc_html__( 'The display name of the user who requested the refund.', 'paid-memberships-pro' ), + '!!membership_id!!' => esc_html__( 'The ID of the membership level that was refunded.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => esc_html__( 'The name of the membership level that was refunded.', 'paid-memberships-pro' ), + '!!order_id!!' => esc_html__( 'The order ID of the refunded order.', 'paid-memberships-pro' ), + '!!order_total!!' => esc_html__( 'The total amount refunded.', 'paid-memberships-pro' ), + '!!order_date!!' => esc_html__( 'The date the refund was processed.', 'paid-memberships-pro' ), + '!!billing_name!!' => esc_html__( 'The billing name associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_street!!' => esc_html__( 'The billing street address associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_street2!!' => esc_html__( 'The billing street address line 2 associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_city!!' => esc_html__( 'The billing city associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_state!!' => esc_html__( 'The billing state associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_zip!!' => esc_html__( 'The billing zip code associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_country!!' => esc_html__( 'The billing country associated with the refunded order.', 'paid-memberships-pro' ), + '!!billing_phone!!' => esc_html__( 'The billing phone number associated with the refunded order.', 'paid-memberships-pro' ), + '!!cardtype!!' => esc_html__( 'The card type used for the refunded order.', 'paid-memberships-pro' ), + '!!accountnumber!!' => esc_html__( 'The last four digits of the account number used for the refunded order.', 'paid-memberships-pro' ), + '!!expirationmonth!!' => esc_html__( 'The expiration month of the card used for the refunded order.', 'paid-memberships-pro' ), + '!!expirationyear!!' => esc_html__( 'The expiration year of the card used for the refunded order.', 'paid-memberships-pro' ), + '!!order_link!!' => esc_html__( 'The URL to the invoice for the refunded order.', 'paid-memberships-pro' ), + '!!order_url!!' => esc_html__( 'The URL to the invoice for the refunded order.', '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 $this->user->user_email; + } + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + public function get_recipient_name() { + return $this->user->display_name; + } + + /** + * 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() { + + $user = $this->user; + $order = $this->order; + $level = pmpro_getLevel( $order->membership_id ); + + $email_template_variables = array( + 'user_login' => $user->user_login, + 'user_email' => $user->user_email, + 'display_name' => $user->display_name, + 'membership_id' => $order->membership_id, + 'membership_level_name' => $level->name, + 'order_id' => $order->code, + 'order_total' => $order->total, + 'order_date' => date_i18n( get_option( 'date_format' ), $order->timestamp ), + '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, + 'order_link' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + 'order_url' => pmpro_login_url( pmpro_url( 'invoice', '?invoice=' . $order->code ) ), + '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 + ), + ); + + return $email_template_variables; + + } +} + +/** + * 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_refund( $email_templates ) { + $email_templates['refund'] = 'PMPro_Email_Template_Refund'; + + return $email_templates; +} +add_filter( 'pmpro_email_templates', 'pmpro_email_templates_refund' ); \ No newline at end of file diff --git a/classes/email-templates/class-pmpro-email-template.php b/classes/email-templates/class-pmpro-email-template.php new file mode 100644 index 000000000..cf73aa59d --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template.php @@ -0,0 +1,173 @@ + email template class name). + */ + final public static function get_all_email_templates() { + /** + * Allow email templates to be registered. + * + * @since TBD + * + * @param array $email_templates All email templates (template slug => email template class name). + */ + return apply_filters( 'pmpro_email_templates', array() ); + } + + /** + * Get an email template by its slug. + * + * @since TBD + * + * @param string $template_slug The email template slug. + * @return string|null The email template class name, or null if the email template is not found. + */ + final public static function get_email_template( string $template_slug ) { + $email_templates = self::get_all_email_templates(); + return isset( $email_templates[ $template_slug ] ) ? $email_templates[ $template_slug ] : null; + } + + /** + * Send the email. + * + * @since TBD + * + * @return bool Whether the email was sent successfully. + */ + final public function send() { + $pmpro_email = new PMProEmail(); + $pmpro_email->email = $this->get_recipient_email(); + $pmpro_email->subject = $this->get_default_subject(); // This will be overridden if there is a subject saved in the database. + $pmpro_email->body = $this->get_default_body(); + $pmpro_email->data = array_merge( $this->get_base_email_template_variables(), $this->get_email_template_variables() ); + $pmpro_email->template = apply_filters_deprecated( 'pmpro_email_template', array( $this->get_template_slug() ), 'TBD', 'pmpro_email_body' ); + return $pmpro_email->sendEmail(); + } + + /** + * Get the base email template variables that should be available for all emails. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + final protected function get_base_email_template_variables() { + $base_email_template_variables = array( + 'sitename' => get_option( 'blogname' ), + 'siteemail' => get_option( 'pmpro_from_email' ), + 'site_url' => home_url(), + 'levels_url' => pmpro_url( 'levels' ), + 'levels_link' => pmpro_url( 'levels' ), + 'login_link' => pmpro_login_url(), + 'login_url' => pmpro_login_url(), + 'header_name' => $this->get_recipient_name(), + ); + + return $base_email_template_variables; + } + + /** + * Get the base email template variables that should be available for all emails paired with a description of the variable. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + final public static function get_base_email_template_variables_with_description() { + $base_email_template_variables_with_description = array( + '!!sitename!!' => esc_html__( 'The name of the site.', 'paid-memberships-pro' ), + '!!siteemail!!' => esc_html__( 'The email address of the site.', 'paid-memberships-pro' ), + '!!site_url!!' => esc_html__( 'The URL of the site.', 'paid-memberships-pro' ), + '!!levels_url!!' => esc_html__( 'The URL of the page where users can view available membership levels.', 'paid-memberships-pro' ), + '!!login_url!!' => esc_html__( 'The URL of the login page.', 'paid-memberships-pro' ), + '!!header_name!!' => esc_html__( 'The name of the email recipient.', 'paid-memberships-pro' ), + ); + + return $base_email_template_variables_with_description; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + abstract public static function get_template_slug(); + + /** + * Get the "nice name" of the email template. + * + * @since TBD + * + * @return string The "nice name" of the email template. + */ + abstract public static function get_template_name(); + + /** + * Get "help text" to display to the admin when editing the email template. + * + * @since TBD + * + * @return string The "help text" to display to the admin when editing the email template. + */ + abstract public static function get_template_description(); + + /** + * Get the default subject for the email. + * + * @since TBD + * + * @return string The default subject for the email. + */ + abstract public static function get_default_subject(); + + /** + * Get the default body content for the email. + * + * @since TBD + * + * @return string The default body content for the email. + */ + abstract public static function get_default_body(); + + /** + * 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). + */ + abstract public static function get_email_template_variables_with_description(); + + /** + * Get the email address to send the email to. + * + * @since TBD + * + * @return string The email address to send the email to. + */ + abstract public function get_recipient_email(); + + /** + * Get the name of the email recipient. + * + * @since TBD + * + * @return string The name of the email recipient. + */ + abstract public function get_recipient_name(); + + /** + * Get the email template variables for the email. + * + * @since TBD + * + * @return array The email template variables for the email (key => value pairs). + */ + abstract public function get_email_template_variables(); +} diff --git a/includes/email-templates.php b/includes/email-templates.php index ac51eaf28..307e612c1 100644 --- a/includes/email-templates.php +++ b/includes/email-templates.php @@ -3,416 +3,45 @@ // File used to setup default email templates data. global $pmpro_email_templates_defaults; -$check_gateway_label = get_option( 'pmpro_check_gateway_label' ) ? get_option( 'pmpro_check_gateway_label' ) : __( 'Check', 'paid-memberships-pro' ); +$check_gateway_label = get_option( 'pmpro_check_gateway_label' ) ? get_option( 'pmpro_check_gateway_label' ) : esc_html__( 'Check', 'paid-memberships-pro' ); // Default email templates. $pmpro_email_templates_defaults = array( 'default' => array( - 'subject' => __( "An email from !!sitename!!", 'paid-memberships-pro' ), - 'description' => __( 'Default Email', 'paid-memberships-pro'), - 'body' => __( '!!body!!', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent when there is a general message that needs to be communicated to the site administrator.', 'paid-memberships-pro' ) + 'subject' => esc_html__( "An email from !!sitename!!", 'paid-memberships-pro' ), + 'description' => esc_html__( 'Default Email', 'paid-memberships-pro'), + 'body' => esc_html__( '!!body!!', 'paid-memberships-pro' ), + 'help_text' => esc_html__( 'This email is sent when there is a general message that needs to be communicated to the site administrator.', 'paid-memberships-pro' ) ), 'footer' => array( 'subject' => '', - 'description' => __( 'Email Footer', 'paid-memberships-pro'), - 'body' => __( 'Respectfully,
!!sitename!!
Respectfully,
!!sitename!!
Dear !!header_name!!,
', 'paid-memberships-pro' ), - 'help_text' => __( 'This is the opening message included in every email sent to members and the site administrator through Paid Memberships Pro.', 'paid-memberships-pro' ) - ), - 'admin_change' => array( - 'subject' => __( "Your membership at !!sitename!! has been changed", 'paid-memberships-pro' ), - 'description' => __( 'Admin Change', 'paid-memberships-pro'), - 'body' => __( 'An administrator at !!sitename!! has changed your membership level.
- -!!membership_change!!
- -If you did not request this membership change and would like more information please contact us at !!siteemail!!
- -Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'The site administrator can manually update a user\'s membership level through the WordPress admin. This email notifies the member of the level update.', 'paid-memberships-pro' ) - ), - 'admin_change_admin' => array( - 'subject' => __( "Membership for !!user_login!! at !!sitename!! has been changed", 'paid-memberships-pro' ), - 'description' => __('Admin Change (admin)', 'paid-memberships-pro'), - 'body' => __( 'An administrator at !!sitename!! has changed a membership level for !!name!!.
- -!!membership_change!!
- -Log in to your WordPress admin here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'The site administrator can manually update a user\'s membership level through the WordPress admin. This email notifies the site administrator of the level update.', 'paid-memberships-pro' ) - ), - 'billing' => array( - 'subject' => __( "Your billing information has been updated at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Billing Information Updated', 'paid-memberships-pro'), - 'body' => __( 'Your billing information at !!sitename!! has been changed.
Account: !!display_name!! (!!user_email!!)
-
- Billing Information:
- !!billing_address!!
-
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
If you did not request a billing information change please contact us at !!siteemail!!
Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'Members can update the payment method associated with their recurring subscription. This email is sent to the member as a confirmation of a payment method update.', 'paid-memberships-pro' ) - ), - 'billing_admin' => array( - 'subject' => __( "Billing information has been updated for !!user_login!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Billing Information Updated (admin)', 'paid-memberships-pro'), - 'body' => __( 'The billing information for !!display_name!! at !!sitename!! has been changed.
- -Account: !!display_name!! (!!user_email!!)
-
- Billing Information:
- !!billing_name!!
- !!billing_street!!
- !!billing_city!!, !!billing_state!! !!billing_zip!! !!billing_country!!
- !!billing_phone!!
-
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
Log in to your WordPress dashboard here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'Members can update the payment method associated with their recurring subscription. This email is sent to the site administrator as a confirmation of a payment method update.', 'paid-memberships-pro' ) - ), - 'billing_failure' => array( - 'subject' => __( "Membership payment failed at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __( 'Payment Failure', 'paid-memberships-pro' ), - 'body' => __( 'The current subscription payment for level !!membership_level_name!! at !!sitename!! membership has failed. Please click the following link to log in and update your billing information to avoid account suspension.
!!login_url!!
Account: !!display_name!! (!!user_email!!)
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent out if a recurring payment has failed, usually due to an expired or cancelled credit card. This email is sent to the member to allowing them time to update payment information without a disruption in access to your site.', 'paid-memberships-pro' ) - ), - 'billing_failure_admin' => array( - 'subject' => __( "Membership payment failed for !!display_name!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __( 'Payment Failure (admin)', 'paid-memberships-pro' ), - 'body' => __( 'The subscription payment for !!user_login!! for level !!membership_level_name!! at !!sitename!! has failed.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
- -Log in to your WordPress admin here: !!login_url!!
-', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent out if a recurring payment has failed for a member, usually due to an expired or cancelled credit card. This email is sent to the site administrator.', 'paid-memberships-pro' ) - ), - 'cancel' => array( - 'subject' => __( "Your membership at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ), - 'description' => __('Cancel', 'paid-memberships-pro'), - 'body' => __( 'Your membership at !!sitename!! has been cancelled.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
- -If you did not request this cancellation and would like more information please contact us at !!siteemail!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'The site administrator can manually cancel a user\'s membership through the WordPress admin or the member can cancel their own membership through your site. This email is sent to the member as confirmation of a cancelled membership.', 'paid-memberships-pro' ) - ), - 'cancel_admin' => array( - 'subject' => __( "Membership for !!user_login!! at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ), - 'description' => __('Cancel (admin)', 'paid-memberships-pro'), - 'body' => __( 'The membership for !!user_login!! at !!sitename!! has been cancelled.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Start Date: !!startdate!!
-End Date: !!enddate!!
- -Log in to your WordPress admin here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'The site administrator can manually cancel a user\'s membership through the WordPress admin or the member can cancel their own membership through your site. This email is sent to the site administrator as confirmation of a cancelled membership.', 'paid-memberships-pro' ) - ), - 'cancel_on_next_payment_date' => array( - 'subject' => __( "Your payment subscription at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ), - 'description' => __('Canceled Auto-Renewals', 'paid-memberships-pro'), - 'body' => __( 'Your payment subscription at !!sitename!! has been cancelled.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Your access will expire on !!enddate!!.
', 'paid-memberships-pro' ), - 'help_text' => __( 'When a user cancels a membership with a recurring subscription, they will still have access until when their next payment would have been taken. This email is sent to the member to notify them of this change.', 'paid-memberships-pro' ) - ), - 'cancel_on_next_payment_date_admin' => array( - 'subject' => __( "Payment subscription for !!user_login!! at !!sitename!! has been CANCELLED", 'paid-memberships-pro' ), - 'description' => __('Canceled Auto-Renewals (admin)', 'paid-memberships-pro'), - 'body' => __( 'The payment subscription for !!user_login!! at !!sitename!! has been cancelled.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Start Date: !!startdate!!
-Expiration Date: !!enddate!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'When a user cancels a membership with a recurring subscription, they will still have access until when their next payment would have been taken. This email is sent to the site administrator to notify them of this change.', 'paid-memberships-pro' ) - ), - 'checkout_check' => array( - 'subject' => __( "Your membership confirmation for !!sitename!!", 'paid-memberships-pro' ), - 'description' => sprintf( __('Checkout - %s', 'paid-memberships-pro' ), $check_gateway_label ), - 'body' => __( 'Thank you for your membership to !!sitename!!. Your membership account is now active.
- -!!membership_level_confirmation_message!! - -!!instructions!! - -Below are details about your membership account and a receipt for your initial membership order.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Membership Fee: !!membership_cost!!
-!!membership_expiration!! !!discount_code!! - -
- Order #!!order_id!! on !!order_date!!
- Total Billed: !!order_total!!
-
Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => sprintf( __('This is a membership confirmation welcome email sent to a new member or to existing members that change their level using the "%s (Pay by Check)" gateway.','paid-memberships-pro' ), $check_gateway_label ) - - ), - 'checkout_check_admin' => array( - 'subject' => __( "Member checkout for !!membership_level_name!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => sprintf( __('Checkout - %s (admin)', 'paid-memberships-pro') , $check_gateway_label ), - 'body' => sprintf (__( 'There was a new member checkout at !!sitename!!.
- -They have chosen to pay by %s.
- -Below are details about the new membership account and a receipt for the initial membership order.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Membership Fee: !!membership_cost!!
-!!membership_expiration!! !!discount_code!! - -
- Order #!!order_id!! on !!order_date!!
- Total Billed: !!order_total!!
-
Log in to your membership account here: !!login_url!!
','paid-memberships-pro' ), $check_gateway_label ), - 'help_text' => sprintf( __('This is the membership confirmation email sent to the site administrator for every membership checkout using the "%s (Pay by Check)" gateway.', 'paid-memberships-pro' ), $check_gateway_label ) - ), - 'checkout_free' => array( - 'subject' => __( "Your membership confirmation for !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Checkout - Free', 'paid-memberships-pro'), - 'body' => __( 'Thank you for your membership to !!sitename!!. Your membership account is now active.
-!!membership_level_confirmation_message!! -Below are details about your membership account.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-!!membership_expiration!! !!discount_code!! - -Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This is a membership confirmation welcome email sent to a new member or to existing members that change their level when the level has no charge.', 'paid-memberships-pro' ) - ), - 'checkout_free_admin' => array( - 'subject' => __( "Member checkout for !!membership_level_name!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Checkout - Free (admin)', 'paid-memberships-pro'), - 'body' => __( 'There was a new member checkout at !!sitename!!.
-Below are details about the new membership account.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-!!membership_expiration!! !!discount_code!! - -Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This is the membership confirmation email sent to the site administrator for every membership checkout that has no charge.', 'paid-memberships-pro' ) - ), - 'checkout_paid' => array( - 'subject' => __( "Your membership confirmation for !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Checkout - Paid', 'paid-memberships-pro'), - 'body' => __( 'Thank you for your membership to !!sitename!!. Your membership account is now active.
-!!membership_level_confirmation_message!! -Below are details about your membership account and a receipt for your initial membership order.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Membership Fee: !!membership_cost!!
-!!membership_expiration!! !!discount_code!! - -
- Order #!!order_id!! on !!order_date!!
- Total Billed: !!order_total!!
-
- Billing Information:
- !!billing_address!!
-
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This is a membership confirmation welcome email sent to a new member or to existing members that change their level and complete a paid checkout on the site.', 'paid-memberships-pro' ) - ), - 'checkout_paid_admin' => array( - 'subject' => __( "Member checkout for !!membership_level_name!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Checkout - Paid (admin)', 'paid-memberships-pro'), - 'body' => __( 'There was a new member checkout at !!sitename!!.
-Below are details about the new membership account and a receipt for the initial membership order.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
-Membership Fee: !!membership_cost!!
-!!membership_expiration!! !!discount_code!! - -
- Order #!!order_id!! on !!order_date!!
- Total Billed: !!order_total!!
-
- Billing Information:
- !!billing_address!!
-
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This is the membership confirmation email sent to the site administrator for every paid membership checkout on the site.', 'paid-memberships-pro' ) - ), - 'credit_card_expiring' => array( - 'subject' => __( "Credit card on file expiring soon at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Credit Card Expiring', 'paid-memberships-pro'), - 'body' => __( 'The payment method used for your membership at !!sitename!! will expire soon. Please click the following link to log in and update your billing information to avoid account suspension. !!login_url!!
- -Account: !!display_name!! (!!user_email!!)
-The most recent account information we have on file is:
- -!!billing_name!! - !!billing_address!! -
- -
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
Thank you for your membership to !!sitename!!. Below is a receipt for your most recent membership order.
- -Account: !!display_name!! (!!user_email!!)
-
- Order #!!order_id!! on !!order_date!!
- Total Billed: !!order_total!!
-
- Billing Information:
- !!billing_address!!
-
- !!cardtype!!: !!accountnumber!!
- Expires: !!expirationmonth!!/!!expirationyear!!
-
Log in to your membership account here: !!login_url!!
-To view an online version of this order, click here: !!order_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the member each time a new subscription payment is made.', 'paid-memberships-pro' ) - ), - 'membership_expired' => array( - 'subject' => __( "Your membership at !!sitename!! has ended", 'paid-memberships-pro' ), - 'description' => __('Membership Expired', 'paid-memberships-pro'), - 'body' => __( 'Your membership at !!sitename!! has ended.
- -Thank you for your support.
- -View our current membership offerings here: !!levels_url!!
- -Log in to manage your account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the member when their membership expires.', 'paid-memberships-pro' ) - ), - 'membership_expiring' => array( - 'subject' => __( "Your membership at !!sitename!! will end soon", 'paid-memberships-pro' ), - 'description' => __('Membership Expiring', 'paid-memberships-pro'), - 'body' => __( 'Thank you for your membership to !!sitename!!. This is just a reminder that your membership will end on !!enddate!!.
- -Account: !!display_name!! (!!user_email!!)
-Membership Level: !!membership_level_name!!
- -Log in to your membership account here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the member when their expiration date is approaching, at an interval based on the term of the membership.', 'paid-memberships-pro' ) - ), - 'refund' => array( - 'subject' => __( 'Order #!!order_id!! at !!sitename!! has been REFUNDED', 'paid-memberships-pro' ), - 'description' => __('Refund', 'paid-memberships-pro'), - 'body' => __( 'Order #!!order_id!! at !!sitename!! has been refunded.
- -Account: !!display_name!! (!!user_email!!)
-
- Order #!!order_id!! on !!order_date!!
- Total Refunded: !!order_total!!
-
Log in to your membership account here: !!login_url!!
-To view an online version of this order, click here: !!order_url!!
- -If you did not request this refund and would like more information please contact us at !!siteemail!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the member as confirmation of a refunded payment. The email is sent after your membership site receives notification of a successful payment refund through your gateway.', 'paid-memberships-pro' ) - ), - 'refund_admin' => array( - 'subject' => __( 'Order #!!order_id!! at !!sitename!! has been REFUNDED', 'paid-memberships-pro' ), - 'description' => __('Refund (admin)', 'paid-memberships-pro'), - 'body' => __( 'Order #!!order_id!! at !!sitename!! has been refunded.
- -Account: !!display_name!! (!!user_email!!)
-
- Order #!!order_id!! on !!order_date!!
- Total Refunded: !!order_total!!
-
Log in to your WordPress admin here: !!login_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the admin as confirmation of a refunded payment. The email is sent after your membership site receives notification of a successful payment refund through your gateway.', 'paid-memberships-pro' ) - ), - 'membership_recurring' => array( - 'subject' => __( "Your membership at !!sitename!! will renew soon", 'paid-memberships-pro' ), - 'description' => __('Recurring Payment Reminder', 'paid-memberships-pro'), - 'body' => __( 'Thank you for your membership to !!sitename!!.
- -This is just a reminder that your !!membership_level_name!! membership will automatically renew on !!renewaldate!!.
- -Account: !!display_name!! (!!user_email!!)
- -If for some reason you do not want to renew your membership you can cancel by clicking here: !!cancel_link!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent when a subscription is approaching its renewal date. The additional placeholders !!renewaldate!! and !!billing_amount!! can be used to print the date that the subscription will renew and the renewal price.', 'paid-memberships-pro' ) + 'description' => esc_html__( 'Email Header', 'paid-memberships-pro'), + 'body' => wp_kses_post( 'Dear !!header_name!!,
', 'paid-memberships-pro' ), + 'help_text' => esc_html__( 'This is the opening message included in every email sent to members and the site administrator through Paid Memberships Pro.', 'paid-memberships-pro' ) ), ); -//we can hide the payment action required emails if default gateway isn't Stripe. -$default_gateway = get_option( 'pmpro_gateway' ); -if( 'stripe' === $default_gateway ) { - $pmpro_email_templates_defaults = array_merge( $pmpro_email_templates_defaults, array( - 'payment_action' => array( - 'subject' => __( "Payment action required for your !!sitename!! membership", 'paid-memberships-pro' ), - 'description' => __('Payment Action Required', 'paid-memberships-pro' ), - 'body' => __( 'Customer authentication is required to finish setting up your subscription at !!sitename!!.
- -Please complete the verification steps issued by your payment provider at the following link:
-!!invoice_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the user when an attempted membership checkout requires additional customer authentication.', 'paid-memberships-pro' ) - ), - 'payment_action_admin' => array( - 'subject' => __( "Payment action required: membership for !!user_login!! at !!sitename!!", 'paid-memberships-pro' ), - 'description' => __('Payment Action Required (admin)', 'paid-memberships-pro'), - 'body' => __( 'A payment at !!sitename!! for !!user_login!! requires additional customer authentication to complete.
-Below is a copy of the email we sent to !!user_email!! to notify them that they need to complete their payment:
- -Customer authentication is required to finish setting up your subscription at !!sitename!!.
-Please complete the verification steps issued by your payment provider at the following link:
-!!invoice_url!!
', 'paid-memberships-pro' ), - 'help_text' => __( 'This email is sent to the site administrator when an attempted membership checkout requires additional customer authentication.', 'paid-memberships-pro' ) - ) - ) ); +// Add any templates registered via the PMPro_Email_Template class. +$registered_templates = PMPro_Email_Template::get_all_email_templates(); +$default_gateway = get_option( 'pmpro_gateway' ); +// if gateway is not stripe, remove the payment action emails +if( 'stripe' !== $default_gateway ) { + unset( $registered_templates['payment_action'] ); + unset( $registered_templates['payment_action_admin'] ); +} +foreach ( $registered_templates as $registered_template_slug => $registered_template_class ) { + $pmpro_email_templates_defaults[ $registered_template_slug ] = array( + 'subject' => $registered_template_class::get_default_subject(), + 'description' => $registered_template_class::get_template_name(), + 'body' => $registered_template_class::get_default_body(), + 'help_text' => $registered_template_class::get_template_description(), + ); } /** diff --git a/includes/email.php b/includes/email.php index c716176a6..625bc9ef6 100644 --- a/includes/email.php +++ b/includes/email.php @@ -296,6 +296,10 @@ function pmpro_email_templates_send_test() { $test_user = $current_user; + + //test subscription object + $test_subscription = new PMPro_Subscription( array( 'user_id' => $test_user->ID, 'membership_level_id' => $test_user->membership_level->id, 'next_payment_date' => date( 'Y-m-d', strtotime( '+1 month' ) ) ) ); + // Grab the first membership level defined as a "test level" to use $all_levels = pmpro_getAllLevels( true); $test_user->membership_level = array_pop( $all_levels ); @@ -365,11 +369,11 @@ function pmpro_email_templates_send_test() { break; case 'membership_expired'; $send_email = 'sendMembershipExpiredEmail'; - $params = array($test_user); + $params = array($test_user, $test_order->membership_id ); break; case 'membership_expiring'; $send_email = 'sendMembershipExpiringEmail'; - $params = array($test_user); + $params = array( $test_user, $test_order->membership_id ); break; case 'payment_action': $send_email = 'sendPaymentActionRequiredEmail'; @@ -379,6 +383,22 @@ function pmpro_email_templates_send_test() { $send_email = 'sendPaymentActionRequiredAdminEmail'; $params = array($test_user, $test_order, "http://www.example-notification-url.com/not-a-real-site"); break; + case 'refund': + $send_email = 'sendRefundedEmail'; + $params = array( $test_user, $test_order ); + break; + case 'refund_admin': + $send_email = 'sendRefundedAdminEmail'; + $params = array( $test_user, $test_order ); + break; + case 'membership_recurring': + $send_email = 'send_recurring_payment_reminder'; + $params = array( $test_subscription ); + break; + case 'credit_card_expiring': + $send_email = 'sendCreditCardExpiringEmail'; + $params = array($test_user, $test_order, "http://www.example-notification-url.com/not-a-real-site"); + break; default: $send_email = 'sendEmail'; $params = array(); @@ -401,7 +421,7 @@ function pmpro_email_templates_test_recipient($email) { //for test emails function pmpro_email_templates_test_body($body, $email = null) { - $body .= '" . sprintf( __("This membership will expire on %s.", "paid-memberships-pro"), date_i18n( get_option( 'date_format' ), $user->membership_level->enddate ) ) . "
\n"; + $new_data['membership_expiration'] = "" . sprintf( esc_html__("This membership will expire on %s.", "paid-memberships-pro"), date_i18n( get_option( 'date_format' ), $user->membership_level->enddate ) ) . "
\n"; $new_data["membership_change"] .= " " . sprintf(__("This membership will expire on %s.", "paid-memberships-pro"), date_i18n( get_option( 'date_format' ), $user->membership_level->enddate ) ); } else if ( ! empty( $email->expiration_changed ) ) { - $new_data["membership_change"] .= " " . __("This membership does not expire.", "paid-memberships-pro"); + $new_data["membership_change"] .= " " . esc_html__("This membership does not expire.", "paid-memberships-pro"); } } } diff --git a/paid-memberships-pro.php b/paid-memberships-pro.php index 9f9d99b9e..6d6533613 100644 --- a/paid-memberships-pro.php +++ b/paid-memberships-pro.php @@ -51,6 +51,33 @@ require_once( PMPRO_DIR . '/classes/class-pmpro-subscription.php' ); require_once( PMPRO_DIR . '/classes/class-pmpro-admin-activity-email.php' ); // setup the admin activity email +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template.php' ); // base class for email templates +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-cancel.php' ); // cancel email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-cancel-admin.php' ); // cancel email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-admin-change.php' ); // change email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-admin-change-admin.php' ); // change email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-refund.php' ); // refund email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-refund-admin.php' ); // refund email admin template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-payment-action.php' ); // expiration email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-payment-action-admin.php' ); // expiration email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-payment-receipt.php' ); // invoice email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-payment-reminder.php' ); // recurring payment email reminder template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-membership-expiring.php' ); // expiring email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-membership-expired.php' ); // change email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-credit-card-expiring.php' ); // credit card expiring email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-check.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-check-admin.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-free.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-free-admin.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-paid.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-checkout-paid-admin.php' ); +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-billing.php' ); // update billing email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-billing-admin.php' ); // update billing admin email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-billing-failure.php' ); // billing failure email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-billing-failure-admin.php' ); // billing failure email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date.php' ); //cancel auto renewals email template +require_once( PMPRO_DIR . '/classes/email-templates/class-pmpro-email-template-cancel-on-next-payment-date-admin.php' ); //cancel auto renewals admin email template + require_once( PMPRO_DIR . '/includes/filters.php' ); // filters, hacks, etc, moved into the plugin require_once( PMPRO_DIR . '/includes/reports.php' ); // load reports for admin (reports may also include tracking code, etc) @@ -181,19 +208,19 @@ // Returns a list of all available gateway function pmpro_gateways() { $pmpro_gateways = array( - '' => __( 'Testing Only', 'paid-memberships-pro' ), - 'check' => __( 'Pay by Check', 'paid-memberships-pro' ), - 'stripe' => __( 'Stripe', 'paid-memberships-pro' ), - 'paypalexpress' => __( 'PayPal Express', 'paid-memberships-pro' ), + '' => esc_html__( 'Testing Only', 'paid-memberships-pro' ), + 'check' => esc_html__( 'Pay by Check', 'paid-memberships-pro' ), + 'stripe' => esc_html__( 'Stripe', 'paid-memberships-pro' ), + 'paypalexpress' => esc_html__( 'PayPal Express', 'paid-memberships-pro' ), ); if ( pmpro_onlyFreeLevels() ) { - $pmpro_gateways[''] = __( 'Default', 'paid-memberships-pro' ); + $pmpro_gateways[''] = esc_html__( 'Default', 'paid-memberships-pro' ); } $check_gateway_label = get_option( 'pmpro_check_gateway_label' ); if ( ! empty( $check_gateway_label ) ) { - $pmpro_gateways['check'] = esc_html( $check_gateway_label . ' (' . __( 'Pay by Check', 'paid-memberships-pro' ) . ')' ); + $pmpro_gateways['check'] = esc_html( $check_gateway_label . ' (' . esc_html__( 'Pay by Check', 'paid-memberships-pro' ) . ')' ); } return apply_filters( 'pmpro_gateways', $pmpro_gateways ); @@ -215,7 +242,7 @@ function pmpro_gateways() { function pmpro_cron_schedules_monthly( $schedules ) { $schedules['monthly'] = array( 'interval' => 2635200, - 'display' => __( 'Once a month', 'paid-memberships-pro' ), + 'display' => esc_html__( 'Once a month', 'paid-memberships-pro' ), ); return $schedules; } diff --git a/scheduled/crons.php b/scheduled/crons.php index 6457927c6..e610696b1 100644 --- a/scheduled/crons.php +++ b/scheduled/crons.php @@ -121,7 +121,7 @@ function pmpro_cron_expiration_warnings() $pmproemail->sendMembershipExpiringEmail( $euser, $e->membership_id); if ( WP_DEBUG ) { - error_log( sprintf( __("Membership expiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email) ); + error_log( sprintf( esc_html__("Membership expiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email) ); } } } @@ -214,7 +214,7 @@ function pmpro_cron_credit_card_expiring_warnings() { $pmproemail->sendCreditCardExpiringEmail($euser,$last_order); if ( WP_DEBUG ) { - error_log( sprintf( __("Credit card expiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email) ); + error_log( sprintf( esc_html__("Credit card expiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email) ); } } @@ -340,8 +340,14 @@ function pmpro_cron_recurring_payment_reminders() { * @param MembershipOrder $lastorder - Deprecated. Now passing null. */ $send_emails = apply_filters_deprecated( 'pmprorm_send_reminder_to_user', array( $send_email, $user, null ), '3.2' ); - - if ( $send_emails ) { + + + if ( $send_emails && 'membership_recurring' == $template ) { + // This is the default email. Use the email template class. + $pmproemail = new PMPro_Email_Template_Payment_Reminder( $subscription_obj ); + $pmproemail->send(); + } else if ( $send_emails ) { + // This is not the default email. Build the email from scratch. // Get the level info. $membership_level = pmpro_getLevel( $subscription_obj->get_membership_level_id() ); @@ -355,7 +361,7 @@ function pmpro_cron_recurring_payment_reminders() { 'user_login' => $user->user_login, 'sitename' => get_option( 'blogname' ), 'membership_id' => $subscription_obj->get_membership_level_id(), - 'membership_level_name' => empty( $membership_level ) ? sprintf( __( '[Deleted level #%d]', 'pmpro-recurring-emails' ), $subscription_obj->get_membership_level_id() ) : $membership_level->name, + 'membership_level_name' => empty( $membership_level ) ? sprintf( esc_html__( '[Deleted level #%d]', 'pmpro-recurring-emails' ), $subscription_obj->get_membership_level_id() ) : $membership_level->name, 'membership_cost' => $subscription_obj->get_cost_text(), 'billing_amount' => pmpro_formatPrice( $subscription_obj->get_billing_amount() ), 'renewaldate' => date_i18n( get_option( 'date_format' ), $subscription_obj->get_next_payment_date() ),