functionwpttuts_createuser() { // User Data $user_name = 'new_user'; $user_password = 'new_user_password'; $user_email = 'new_user@gmail.com';
// Create the user $user_id = wp_create_user( $user_name, $user_password, $user_email );
// Checks if the function returned a WP Error Object if ( is_wp_error ($user_id) ) { $user_id->get_error_message(); } else { // user created successfully } }
functionwpttuts_insertuser() { // Prepare the user data $user_data = array ( 'user_login' => 'new_user', 'user_password' => 'new_user_password' 'user_email' => 'new_user@gmail.com', 'role' => 'administrator' );
// Create the user $user_id = wp_insert_user( $user_data );
// Checks if the function returned a WP Error Object if ( is_wp_error( $user_id ) ) { $user_id->get_error_message(); } else { // user created successfully } }
// Prepare the user data $user_data = array ( 'user_id' => 3, 'description' => ' Our newly created user' );
// Updates the user description $user_id = wp_update_user( $user_data );
// Checks if the function returned a WP Error Object if ( is_wp_error( $user_id ) ) { $user_id->get_error_message(); } else { // user updated successfully } }
wp_delete_user 的用法
1 2 3 4 5 6 7
add_action( 'init', 'wpttuts_deleteuser' );
functionwpttuts_deleteuser() { if ( wp_delete_user( 3, 1 ) ) { // User removed successfully } }