Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php

class PMPro_Email_Template_Resend_Confirmation extends PMPro_Email_Template {

/**
* The parent user.

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment 'The parent user' is unclear. This should be 'The user receiving the confirmation email' or simply 'The user' to better describe the property's purpose.

Suggested change
* The parent user.
* The user receiving the confirmation email.

Copilot uses AI. Check for mistakes.
*
* @var WP_User
*/
protected $user;

/**
* The validation link.
*
* @var String
*/
protected $validation_link;

/**
* Constructor.
*
* @since TBD
*
* @param WP_User $user The user will receive the email.

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected grammar from 'The user will receive' to 'The user who will receive' for better readability.

Suggested change
* @param WP_User $user The user will receive the email.
* @param WP_User $user The user who will receive the email.

Copilot uses AI. Check for mistakes.
* @param String $validation_link The validation link.
*
*/
public function __construct( WP_User $user, String $validation_link ) {
$this->user = $user;
$this->validation_link = $validation_link;
}

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

/**
* 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__( 'Email Confirmation - Resend Confirmation', 'pmpro-email-confirmation' );
}

/**
* 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 users when they need to confirm their email address.', 'pmpro-email-confirmation' );
}

/**
* 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__( 'Confirm Your Email Address', 'pmpro-email-confirmation' );
}

/**
* 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( __( '<p>Please click the following link to confirm your email address: !!validation_link!!</p>', 'pmpro-email-confirmation' ) );
}

/**
* 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(
// '!!display_name!!' => esc_html__( 'The display name of the user need to confirm the email', 'pmpro-email-confirmation' ),
// '!!user_login!!' => esc_html__( 'The login name of the user need to confirm the email', 'pmpro-email-confirmation' ),
// '!!user_email!!' => esc_html__( 'The email address of the user need to confirm the email', 'pmpro-email-confirmation' ),
Comment on lines +97 to +99

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commented-out template variables are defined in get_email_template_variables() (lines 114-116) but not exposed in get_email_template_variables_with_description(). If these variables are not intended to be available for use in email templates, they should be removed from the method. If they should be available, uncomment and fix the grammar ('user need' should be 'user who needs').

Suggested change
// '!!display_name!!' => esc_html__( 'The display name of the user need to confirm the email', 'pmpro-email-confirmation' ),
// '!!user_login!!' => esc_html__( 'The login name of the user need to confirm the email', 'pmpro-email-confirmation' ),
// '!!user_email!!' => esc_html__( 'The email address of the user need to confirm the email', 'pmpro-email-confirmation' ),
'!!display_name!!' => esc_html__( 'The display name of the user who needs to confirm the email.', 'pmpro-email-confirmation' ),
'!!user_login!!' => esc_html__( 'The login name of the user who needs to confirm the email.', 'pmpro-email-confirmation' ),
'!!user_email!!' => esc_html__( 'The email address of the user who needs to confirm the email.', 'pmpro-email-confirmation' ),

Copilot uses AI. Check for mistakes.
'!!validation_link!!' => esc_html__( 'The link to the validation page.', 'pmpro-email-confirmation' ),
);
}

/**
* 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;
$email_template_variables = array(
'display_name' => $user->display_name,
'user_login' => $user->user_login,
'user_email' => $user->user_email,
'validation_link' => $this->validation_link,
);

return $email_template_variables;
}

/**
* 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() {

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty line with trailing whitespace before the return statement.

Suggested change

Copilot uses AI. Check for mistakes.
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_template_pmpro_email_confirmation_resend_confirmation( $email_templates ) {
$email_templates['resend_confirmation'] = 'PMPro_Email_Template_Resend_Confirmation';
return $email_templates;
}
add_filter( 'pmpro_email_templates', 'pmpro_email_template_pmpro_email_confirmation_resend_confirmation' );
84 changes: 47 additions & 37 deletions pmpro-email-confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
*/

function pmproec_load_plugin_text_domain() {
load_plugin_textdomain( 'pmpro-email-confirmation', false, basename( dirname( __FILE__ ) ) . '/languages' );
load_plugin_textdomain( 'pmpro-email-confirmation', false, basename( dirname( __FILE__ ) ) . '/languages' );
if ( class_exists( 'PMPro_Email_Template' ) ) {
include_once( dirname( __FILE__ ) . '/classes/email-templates/class-pmpro-email-template-pmpro-email-confirmation-resend-confirmation.php' );
} else {
add_filter( 'pmproet_templates', 'pmproec_email_templates', 10, 1 );
}
}
add_action( 'init', 'pmproec_load_plugin_text_domain' );
add_action( 'init', 'pmproec_load_plugin_text_domain', 8 );

/*
Add checkbox to edit level page to set if level requires email confirmation.
Expand Down Expand Up @@ -412,50 +417,56 @@ function pmproec_resend_confirmation_email( $user_id = NULL ) {
return;
}

$body = file_get_contents( dirname( __FILE__ ) . "/email/resend_confirmation.html" );
$url = home_url( "?ui=" . $user->ID . "&validate=" . $validated );

//filter to allow additional query arguments.
$pmpro_query_args = apply_filters( 'pmproec_query_args', array() );

$url = home_url( "?ui=" . $user->ID . "&validate=" . $validated );

//add query arguments to the URL (on top of existing args)
$url = ( add_query_arg(
$pmpro_query_args,
$url
));
$url = ( add_query_arg( $pmpro_query_args, $url ) );

if ( empty( $validated ) || $validated != "validated" ) {
//This is a flag to check if the email was sent successfully or not to show the success message.
$mail_sent_successfully = false;

//use validation_link substitute?
if ( false === stripos( $body, "!!validation_link!!" ) ) {
$body = "<p><strong>" . esc_html__("IMPORTANT! You must follow this link to confirm your email address before your membership is fully activated", "pmpro-email-confirmation") . ":<br /><a href='" . esc_url( $url ) . "'>" . esc_url( $url ) . "</a></strong></p><hr />" . $body;
} else {
$body = str_ireplace( "!!validation_link!!", $url, $body );
if ( class_exists( 'PMPro_Email_Template' ) ) {
$send_resend_confirmation_email = new PMPro_Email_Template_Resend_Confirmation( $user, $url );
$mail_sent_successfully = $send_resend_confirmation_email->send();

Copilot AI Oct 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using the new PMPro_Email_Template system (lines 431-433), the success message is never set. The $pmproec_msg and $pmproec_msgt globals are only set within the else block (lines 465-468). This means users won't see a confirmation message when the email is sent using the new template system. Add the success message logic after line 433.

Suggested change
$mail_sent_successfully = $send_resend_confirmation_email->send();
$mail_sent_successfully = $send_resend_confirmation_email->send();
if ( $mail_sent_successfully ) {
$pmproec_msg = esc_html__( 'A confirmation email has been sent to', 'pmpro-email-confirmation' ) . ' ' . $user->user_email;
$pmproec_msgt = 'updated';
}

Copilot uses AI. Check for mistakes.
} else {
$body = file_get_contents( dirname( __FILE__ ) . "/email/resend_confirmation.html" );

if ( empty( $validated ) || $validated != "validated" ) {

//use validation_link substitute?
if ( false === stripos( $body, "!!validation_link!!" ) ) {
$body = "<p><strong>" . esc_html__("IMPORTANT! You must follow this link to confirm your email address before your membership is fully activated", "pmpro-email-confirmation") . ":<br /><a href='" . esc_url( $url ) . "'>" . esc_url( $url ) . "</a></strong></p><hr />" . $body;
} else {
$body = str_ireplace( "!!validation_link!!", $url, $body );
}

//Setup the new email.
$pmpro_email = new PMProEmail();
//Setup the email data
$pmpro_email->body = $body;
$pmpro_email->subject = esc_html__( 'Confirm Your Email Address', 'pmpro-email-confirmation' );
$pmpro_email->email = $user->user_email;
$pmpro_email->data = array(
"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" => wp_login_url(),
"validation_link" => $url
);
$pmpro_email->template = 'resend_confirmation';
$mail_sent_successfully = $pmpro_email->sendEmail();
}

//Setup the new email.
$pmpro_email = new PMProEmail();
//Setup the email data
$pmpro_email->body = $body;
$pmpro_email->subject = esc_html__( 'Confirm Your Email Address', 'pmpro-email-confirmation' );
$pmpro_email->email = $user->user_email;
$pmpro_email->data = array(
"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" => wp_login_url(),
"validation_link" => $url
);
$pmpro_email->template = 'resend_confirmation';
$pmpro_email->sendEmail();

$pmproec_msg = esc_html__( 'A confirmation email has been sent to', 'pmpro-email-confirmation' ) . ' ' . $user->user_email;
$pmproec_msgt = 'updated';
if ( $mail_sent_successfully ) {
$pmproec_msg = esc_html__( 'A confirmation email has been sent to', 'pmpro-email-confirmation' ) . ' ' . $user->user_email;
$pmproec_msgt = 'updated';
}
}

}

/**
Expand Down Expand Up @@ -746,7 +757,6 @@ function pmproec_email_templates( $templates ) {
return $templates;

}
add_filter( 'pmproet_templates', 'pmproec_email_templates', 10, 1 );

function pmproec_add_email_template( $templates, $page_name, $type = 'emails', $where = 'local', $ext = 'html' ) {
$templates[] = dirname(__FILE__) . "/email/resend_confirmation.html";
Expand Down