Skip to content

Instantly share code, notes, and snippets.

@ellefsen
Created October 22, 2014 21:57
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 ellefsen/94c7d329e251a0c8bec5 to your computer and use it in GitHub Desktop.
Save ellefsen/94c7d329e251a0c8bec5 to your computer and use it in GitHub Desktop.
Create WordPress user programatically
<?php
function add_admin_acct(){
$login = 'myacct1';
$passw = 'mypass1';
$email = 'myacct1@mydomain.com';
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','add_admin_acct');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment