Last active
August 29, 2015 14:00
-
-
Save strangerstudios/11054123 to your computer and use it in GitHub Desktop.
Make sure people use their Mine Craft username when checking out with Paid Memberships Pro
This file contains 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
/* | |
Make sure people use their Minecraft username when registering. | |
*/ | |
//uses Minecraft website to test a username and returns true or false | |
function mc_isMinecraftUsername($username, $force = false) | |
{ | |
global $premium_minecraft_usernames; | |
if(!is_array($premium_minecraft_usernames)) | |
$premium_minecraft_usernames = array(); | |
if($force || !isset($premium_minecraft_usernames[$username])) | |
{ | |
$premium = wp_remote_retrieve_body(wp_remote_get("https://minecraft.net/haspaid.jsp?user=" . $username)); | |
if($premium == "true") | |
$premium_minecraft_usernames[$username] = true; | |
else | |
$premium_minecraft_usernames[$username] = false; | |
} | |
return $premium_minecraft_usernames[$username]; | |
} | |
//check username at PMPro checkout | |
function mc_pmpro_registration_checks($continue) | |
{ | |
//is username even set? | |
if(isset($_REQUEST['username'])) | |
{ | |
//okay check if it's a premium minecraft username | |
if(!mc_isMinecraftUsername($_REQUEST['username'])) | |
{ | |
pmpro_setMessage("Your username must be a valid premium Mine Craft username.", "pmpro_error"); | |
return false; | |
} | |
} | |
return $continue; | |
} | |
add_filter("pmpro_registration_checks", "mc_pmpro_registration_checks"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment