Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Last active March 27, 2016 02:34
Show Gist options
  • Save vimes1984/1827a815a810e67f2137 to your computer and use it in GitHub Desktop.
Save vimes1984/1827a815a810e67f2137 to your computer and use it in GitHub Desktop.
<?php
/**
*
* add in a simple endpoint
*
***/
add_action('wp_ajax_nopriv_add_user_from_minecraft', array($this, 'add_user_from_minecraft') );
add_action( 'wp_ajax_add_user_from_minecraft', array($this, 'add_user_from_minecraft');
function add_user_from_minecraft(){
$request_body = file_get_contents( 'php://input' );
$decodeit = json_decode( $request_body ); // Decode it is now a php object available to you like so $decodeit->UUID
/// grab the user data the user is sending from script craft here either via the $_GET['uuid OR any get parameter sent']
// or via the $decodit like so : $decodeit->uuid ; Decodit is from the json body POST request went sent via ajax
// Add a user here like so:
$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
//Update the users meat after the user has been created by hooking into the user_register action :D <-- SCRAP THIS I'M TALKING OUT OF MY ASS
// USE THIS INSTEAD HERE :D https://codex.wordpress.org/Function_Reference/update_user_meta
} else {
$random_password = __('User already exists. Password inherited.');
}
echo "<pre>";
var_dump($decodeit);
echo "</pre>";
echo "<pre>";
var_dump($_GET);
echo "</pre>";
die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment