Skip to content

Instantly share code, notes, and snippets.

@snapeuh
Last active September 28, 2016 19:34
Show Gist options
  • Save snapeuh/29593bd0e71d833d4c126211715f1e91 to your computer and use it in GitHub Desktop.
Save snapeuh/29593bd0e71d833d4c126211715f1e91 to your computer and use it in GitHub Desktop.
Create a WordPress user from code
<?php
function add_admin_acct(){
$login = 'utilisateur';
$passw = 'motdepasse';
$email = '[email protected]';
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