Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JarrydLong/1293f857e8415b8f04ab3a683b4944b9 to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/1293f857e8415b8f04ab3a683b4944b9 to your computer and use it in GitHub Desktop.
<?php //do not copy
//Remove the current text we add to PMPro no access message
function mypmpro_remove_original_ec_text(){
remove_filter( 'pmpro_no_access_message_body', 'pmproec_pmpro_text_filter' ); // PMPro 3.1+
remove_filter( 'pmpro_non_member_text_filter', 'pmproec_pmpro_text_filter' ); // Pre-PMPro 3.1
remove_filter( 'pmpro_not_logged_in_text_filter', 'pmproec_pmpro_text_filter' ); // Pre-PMPro 3.1
}
add_action( 'init' ,'mypmpro_remove_original_ec_text' );
//Add this back with custom text + link to resend confirmation email
function my_pmproec_pmpro_text_filter( $text ){
global $current_user;
// User doesn't have access. To check whether it is because their email is not validated,
// we can unhook our pmpro_has_membership_access_filter and check if the user would then have access.
remove_filter('pmpro_has_membership_access_filter', 'pmproec_pmpro_has_membership_access_filter', 10);
$hasaccess = pmpro_has_membership_access();
add_filter('pmpro_has_membership_access_filter', 'pmproec_pmpro_has_membership_access_filter', 10, 4);
if ( ! $hasaccess ) {
// User still does not have access. Email confirmations is not the preventing factor. Return the original text.
return $text;
}
// User does not have access because their email is not validated.
// Let's just double check that they are not validated.
$validated = $current_user->pmpro_email_confirmation_key;
if ( empty( $validated ) || $validated == 'validated' ) {
// User is validated. Return the original text.
return $text;
}
$resend_link = '';
$user = get_user_by( 'ID', $current_user->ID );
$validated = $user->pmpro_email_confirmation_key;
// var_dump($current_user);
$level_id = ! empty( $current_user->membership_levels ) ? $current_user->membership_levels[0]->id : null;
// If none of the user's levels require confirmation, bail.
$requires_confirmation = false;
if ( pmproec_isEmailConfirmationLevel( $level_id ) ) {
$requires_confirmation = true;
}
if ( ! $requires_confirmation ) {
return $action_links;
}
// If user is already validated, bail.
if ( empty( $validated ) || $validated == 'validated' ){
return $action_links;
}
// Add a nonce here.
$url = add_query_arg(
array(
'resendconfirmation' => 1,
)
);
// Add the "Resend Confirmation Email" action link.
$resend_link = '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Resend Confirmation Email', 'pmpro-email-confirmation' ) . '</a>';
// User is not validated. Let's show them a message.
$return_string = '<p>' . esc_html__('Your membership will be activated as soon as you confirm your email address.', 'pmpro-email-confirmation') . '.<strong> ' . sprintf( esc_html__('Important! You must click on the confirmation URL sent to %s before you gain full access to your membership.', 'pmpro-email-confirmation'), $current_user->user_email) . '</strong>.</p>';
if( ! empty( $_REQUEST['resendconfirmation'] ) ) {
$return_string .= "<strong>Confirmation Email Resent.</strong>";
} else {
$return_string .= "<p>Click Resend Confirmation Button below to resend the confirmation email.</p>";
$return_string .= '<p>' . $resend_link . '</p>';
}
return $return_string;
}
add_filter( 'pmpro_no_access_message_body', 'my_pmproec_pmpro_text_filter' ); // PMPro 3.1+
// add_filter( 'pmpro_non_member_text_filter', 'my_pmproec_pmpro_text_filter' ); // Pre-PMPro 3.1
add_filter( 'pmpro_not_logged_in_text_filter', 'my_pmproec_pmpro_text_filter' ); // Pre-PMPro 3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment