Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/518397771326cc64c1421bdeab7f6a20 to your computer and use it in GitHub Desktop.
Save ipokkel/518397771326cc64c1421bdeab7f6a20 to your computer and use it in GitHub Desktop.
<?php // Do not copy this tag
// Use unique membership key combined with the email address as username with PMPro checkout. You'll also have to hide the username fields at checkout using CSS or a custom checkout page template.
// Paste the code below into a PMPro Customization Plugin: https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function my_init_unique_key_and_email_as_username()
{
$args = array(
'role' => 'author', // authors only
'orderby' => 'registered', // registered date
'order' => 'DESC', // last registered goes first
'number' => 1 // limit to the last one, not required
);
$users = get_users( $args );
$last_user_registered = $users[0]; // the first user from the list
$new_user_id = $last_user_registered->ID;
$scramble = md5(AUTH_KEY . current_time('timestamp') . ( $new_user_id + 1 ) . SECURE_AUTH_KEY);
$unique_member_key = substr($scramble, 0, 10);
//check for level as well to make sure we're on checkout page
if(empty($_REQUEST['level']))
return;
if(!empty($_REQUEST['bemail']))
$_REQUEST['username'] = $unique_member_key . '-' . $_REQUEST['bemail'];
if(!empty($_POST['bemail']))
$_POST['username'] = $unique_member_key . '-' . $_POST['bemail'];
if(!empty($_GET['bemail']))
$_GET['username'] = $unique_member_key . '-' . $_GET['bemail'];
}
add_action('init', 'my_init_unique_key_and_email_as_username');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment