WordPress Custom User Creation Script
What do I have to include to be able to use wp_create_user
?
My current includes are
include_once($_SERVER['DOCUMENT_ROOT']."/wp-config.php");
include_once($_SERVER['DOCUMENT_ROOT']."/wp-includes/registration.php");
include_once($_SERVER['DOCUMENT_ROOT']."/wp-includes/user.php");
But it never creates the user.
What am I missing?
Here is the full code block.
global $wpdb;
$user_name = $_GET['user_login'];
$user_password 开发者_开发问答= $_GET['user_password'];
$user_email = $_GET['user_email'];
/* echo $user_name . " " . $user_password . " " . $user_email . " <br />"; */
$user_id = username_exists( $user_name );
if ( !$user_id ) { // User doesn't exist. Create user. Notify via JSON
$user_id = wp_create_user( $user_name, $user_password, $user_email );
echo '{"success": "'. $user_id .'"}';
} else { // User exists. Return JSON error.
$msg = 'User already exists.';
echo '{"error": "'. $msg .'"}';
}
The wpdb
class is in wp-includes/wp-db.php
. You can probably just use it like this (note, I haven't tested this)
require_once('wp-includes/wp-db.php');
$wpdb = new wpdb();
//Do your add user stuff
Problem solved. Include path problem occurred during migration.
精彩评论