diff --git a/classes/class.pmproemail.php b/classes/class.pmproemail.php index 8816f189c..a56279a44 100644 --- a/classes/class.pmproemail.php +++ b/classes/class.pmproemail.php @@ -1278,7 +1278,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; } @@ -1287,51 +1287,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" ) ); + $email = new PMPro_Email_Template_Membership_Expired( $user, $membership_id ); - $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' ) . ']', - ); - - $this->template = apply_filters("pmpro_email_template", "membership_expired", $this); - - return $this->sendEmail(); + $email->send(); } /** diff --git a/classes/email-templates/class-pmpro-email-template-membership-expired.php b/classes/email-templates/class-pmpro-email-template-membership-expired.php new file mode 100644 index 000000000..638284ad2 --- /dev/null +++ b/classes/email-templates/class-pmpro-email-template-membership-expired.php @@ -0,0 +1,193 @@ +user = $user; + $this->membership_level_id = $membership_level_id; + } + + /** + * Get the email template slug. + * + * @since TBD + * + * @return string The email template slug. + */ + public static function get_template_slug() { + return 'membership_expired'; + } + + /** + * 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 __( 'Membership Expired', '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 __( 'This email is sent to the member when their membership expires.', '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 __( 'Your membership at !!sitename!! has ended', '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 __( '
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!!' => __( 'The default subject for the email. This will be removed in a future version.', 'paid-memberships-pro' ), + '!!header_name!!' => __( 'The name of the email recipient.', 'paid-memberships-pro' ), + '!!name!!' => __( 'The display name of the user.', 'paid-memberships-pro' ), + '!!membership_id!!' => __( 'The ID of the membership level.', 'paid-memberships-pro' ), + '!!membership_level_name!!' => __( 'The name of the membership level.', 'paid-memberships-pro' ), + '!!user_login!!' => __( 'The username of the user.', 'paid-memberships-pro' ), + '!!user_email!!' => __( 'The email address of the user.', 'paid-memberships-pro' ), + '!!display_name!!' => __( 'The display name of the user.', 'paid-memberships-pro' ), + '!!levels_link!!' => __( 'The URL of the page where users can view available membership levels.', '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", + $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->subject, + "name" => $user->display_name, + "user_login" => $user->user_login, + "header_name" => $user->display_name, + "display_name" => $user->display_name, + "user_email" => $user->user_email, + "levels_link" => pmpro_url("levels"), + "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/includes/email-templates.php b/includes/email-templates.php index e0d2734a2..cd76d258d 100644 --- a/includes/email-templates.php +++ b/includes/email-templates.php @@ -274,18 +274,6 @@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'), diff --git a/includes/email.php b/includes/email.php index c716176a6..d017a0128 100644 --- a/includes/email.php +++ b/includes/email.php @@ -365,7 +365,7 @@ 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'; diff --git a/paid-memberships-pro.php b/paid-memberships-pro.php index fc919808d..e72d7f39f 100644 --- a/paid-memberships-pro.php +++ b/paid-memberships-pro.php @@ -55,6 +55,7 @@ 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-membership-expired.php' ); // change 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)