Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active June 18, 2019 18:11
Show Gist options
  • Save cartpauj/4141563c14b6ff4fa1a6 to your computer and use it in GitHub Desktop.
Save cartpauj/4141563c14b6ff4fa1a6 to your computer and use it in GitHub Desktop.
Using the New User Approve Plugin + MemberPress to allow filtered domains through
<?php
/*
Plugin Name: MemberPress + New User Approve
Version: 1.0.0
Author: Caseproof, LLC
Author URI: http://caseproof.com
Description: Helps the flow of signups from approved/unapproved domains between the MemberPress and New User Approve plugins
*/
function mepr_get_approved_domains() {
//EDIT this array to match currently allowed domains
return array( 'aarp.com',
'abbvie.com',
'adp.com',
'amazon.com',
'astrazeneca.com',
'averydennison.com'
);
}
function mepr_ends_with($haystack, $needle) {
return (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
}
//Where the bulk of this addon happens
function mepr_check_email_domain($errors) {
$email = stripslashes($_POST['user_email']);
$approved_domains = mepr_get_approved_domains();
$was_approved = false
foreach($approved_domains as $ad) {
if(mepr_ends_with($email, $ad)) {
$was_approved = true;
$_REQUEST['action'] = 'createuser'; //Set this so "New User Approve" plugin will not limit the subscriber
break;
}
}
if(!$was_approved) {
mepr_send_awaiting_approval_email($email);
}
return $errors;
}
add_filter('mepr-validate-signup', 'mepr_check_email_domain');
function mepr_send_awaiting_approval_email($email) {
//EDIT $message if you wish
$message = "<h4>Thank you for registering for xxxxx!</h4> <p>Your account is pending while we review it. We will send you another email within 48 hours if your account is approved.</p><p>Sincerely,<br/>the AWESOME SITE team</p>";
@wp_mail($email, 'Your account is pending', $message, array("Content-Type: text/html"));
}
//USER APPROVED EMAIL TO USER
function mepr_override_nua_approved_email_message($message, $user) {
//EDIT $message if you wish
$message = "<h4>Congratulations, your account has been approved!</h4> <p>Your account at THE AWEOMSE SITE has been approved. <a href=\"http://somesite.com/login/\">Click here to login</a>.</p><p>Sincerely,<br/>the AWESOME SITE team</p>";
return $message;
}
add_filter('new_user_approve_approve_user_message', 'mepr_override_nua_approved_email_message', 11, 2);
function mepr_override_nua_approved_email_subject($subject) {
//EDIT $subject if you wish
$subject = "Your account has been approved";
return $subject;
}
add_filter('new_user_approve_approve_user_subject', 'mepr_override_nua_approved_email_subject', 11);
//USER DENIED EMAIL TO USER
function mepr_override_nua_denied_email_message($message, $user) {
//EDIT $message if you wish
$message = "<h4>Sorry, your account has been denied</h4> <p>Your account has been denied becuase of xyz. If you feel this was in error <a href=\"http://somesite.com/contact/\">please contact us for further assistance</a>.</p><p>Sincerely,<br/>the AWESOME SITE team</p>";
return $message;
}
add_filter('new_user_approve_deny_user_message', 'mepr_override_nua_denied_email_message', 11, 2);
function mepr_override_nua_denied_email($subject) {
//EDIT $subject if you wish
$subject = "Your account has been denied";
return $subject;
}
add_filter('new_user_approve_deny_user_subject', 'mepr_override_nua_denied_email', 11);
//EMAIL HEADERS OVERRIDE
function mepr_nua_email_headers_override($headers) {
unset($headers[1]);
$headers[] = "Content-Type: text/html";
return $headers;
}
add_filter('new_user_approve_email_header', 'mepr_nua_email_headers_override', 3);
//WE DON'T WANT TO OVERRIDE THE PW THE USER SET WHEN SIGNING UP VIA MEMBERPRESS
function mepr_ignore_new_user_autopass() {
return true;
}
add_filter('new_user_approve_bypass_password_reset', 'mepr_ignore_new_user_autopass');
@cartpauj
Copy link
Author

If you're just looking to modify the emails that are sent out. You can copy these lines into a plugin like My Custom Functions: https://gist.github.com/cartpauj/4141563c14b6ff4fa1a6#file-mepr-nua-approve-by-email-domain-php-L54-L95 and make edits there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment