Skip to content

Instantly share code, notes, and snippets.

@schmiddim
Created September 28, 2017 12:35
Show Gist options
  • Save schmiddim/aab59c00ff6546ec816cb4e58fa81694 to your computer and use it in GitHub Desktop.
Save schmiddim/aab59c00ff6546ec816cb4e58fa81694 to your computer and use it in GitHub Desktop.
Create wordpress user on commandline
<?php
/**
* @author: michael schmitt
* @desc: copy file to the / of a wordpress instance
* execute on commandline: php user.php username + password
*/
if($argc < 3) {
die("usage php user.php username password" .PHP_EOL);
}
$userName= $argv[1];
$password=$argv[2];
echo $userName;
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
$user_id = get_user_by('name', $userName);
if(null !== $user_id) {
$user_id = wp_create_user($userName, $password);
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment