Last active
August 29, 2015 14:23
-
-
Save avioli/edc10b7eb8a6fc1c3764 to your computer and use it in GitHub Desktop.
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
<?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