Currently this code only creates a subscriber user in WordPress. Due to security concerns I likely won’t work on this to make it do greater permissions.
php wp-create-user.php MyBasicUser User@example.com
# php wp-create-user.php MyBasicUser User@example.com Username not in use, creating user. User Created Username: MyBasicUser Password: 5y1kZSkMO0bP #
# php wp-create-user.php MyBasicUser User@example.com Username in use. #
<?php // Restrict access to this file - start if (php_sapi_name() != 'cli') { exit; } // Restrict access to this file - stop require_once('wp-blog-header.php') ; if (isset($argv[1]) && ('' != trim($argv[1]))) { $user_name= $argv[1]; } else { echo "\nMissing Username Parameter\n"; exit; } if (isset($argv[2]) && ('' != trim($argv[2]))) { $email=$argv[2]; } else { echo "\nMissing Email Parameter\n"; exit; } $password= wp_generate_password( $length=12, $include_standard_special_chars=false ); // Check if user exists - Start $bUserExists = false; if ( username_exists($user_name ) ) { echo "\nUsername in use.\n"; $bUserExists = true; } else { echo "\nUsername not in use, creating user.\n"; $bUserExists = false; } // Check if user exists - Stop // Create User - Start if ($bUserExists == false) { $user_id = wp_create_user($user_name, $password, $email) ; // check if there was an error if (is_wp_error($user_id)) { if (!isset($errhandler)) { $errhandler= new apperrors() or die ("\nUnable to create instance of app errors"); } $errhandler->add($user_id->get_error_message(),"my_wp_class->add_user") or die("\nUnable to add record to errors - $user_id"); } else { echo "\nUser Created\n\nUsername: " . $user_name . "\nPassword: " . $password . "\n\n"; } } // Create User - Stop ?>
Last Updated on February 26, 2016