Skip to content

Instantly share code, notes, and snippets.

@avioli
Last active August 29, 2015 14:23
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 avioli/edc10b7eb8a6fc1c3764 to your computer and use it in GitHub Desktop.
Save avioli/edc10b7eb8a6fc1c3764 to your computer and use it in GitHub Desktop.
<?php
// define('WP_CORE_DIR_NAME', 'wp');
if ( !defined('WP_CORE_DIR_NAME') )
define('WP_CORE_DIR_NAME', getenv('WP_CORE_DIR_NAME') ? getenv('WP_CORE_DIR_NAME') : '.');
define('WP_USE_THEMES', false);
require(dirname( __FILE__ ) . '/' . WP_CORE_DIR_NAME . '/wp-blog-header.php');
if ( ! empty( $_POST['username'] )) {
$password = trim( wp_generate_password( 12, false ) );
$username = sanitize_user( $_POST['username'] );
if ( ! empty( $username ) ) {
$user_id = wp_create_user( $username, $password, $username . '@domain.com' );
if ( is_wp_error( $user_id ) ) {
die( $user_id->get_error_message() );
} else {
$new_user = new WP_User( $user_id );
$new_user->add_cap( 'administrator', '1' );
die( 'User created. Password: ' . $password );
}
}
}
?>
<form method="post">
<label>Username: <input type="text" name="username" /></label>
<button type="submit">Create</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment