Created
March 1, 2019 12:45
-
-
Save ipokkel/b8a05e9d7b25c4f03f830972ef34dd3a to your computer and use it in GitHub Desktop.
Use unique membership key as username with PMPro checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Do not copy this tag | |
// Use unique membership key 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_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; | |
if(!empty($_POST['bemail'])) | |
$_POST['username'] = $unique_member_key; | |
if(!empty($_GET['bemail'])) | |
$_GET['username'] = $unique_member_key; | |
} | |
add_action('init', 'my_init_unique_key_as_username'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment