Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created June 13, 2017 16:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gelanivishal/9ee3088a896c2a345ad0bae438d24628 to your computer and use it in GitHub Desktop.
Save gelanivishal/9ee3088a896c2a345ad0bae438d24628 to your computer and use it in GitHub Desktop.
Create Admin user programmatically in Wordpress
<?php
define('WP_USE_THEMES', true);
// Load the WordPress library.
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
$username = 'developer';
$password = 'developer123';
$email = 'developer@localhost.com';
// Create the new user
$user_id = wp_create_user( $username, $password, $email );
// Get current user object
$user = get_user_by( 'id', $user_id );
// Remove role
$user->remove_role( 'subscriber' );
// Add role
$user->add_role( 'administrator' );
@nsukonny
Copy link

Thank you for that code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment