Created
June 13, 2017 16:30
-
-
Save gelanivishal/9ee3088a896c2a345ad0bae438d24628 to your computer and use it in GitHub Desktop.
Create Admin user programmatically in Wordpress
This file contains hidden or 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_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 = '[email protected]'; | |
// 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for that code!