Try to add new user in WordPress via function
-
I try to go my first steps with WordPress & php. I need to add a new user and if I do not try to wrap some parts in a function, all went fine and smooth. But in this version, no user is created. Would anyone please be so kind to point me the way?
function create_terminal_user() { if ( !function_exists( 'wp_create_user' ) ) { require_once ABSPATH . WPINC . '/user.php'; //For wp_create_user and wp_delete_user() function } $user_data = array( 'ID' => '', // automatically created 'user_pass' => '', 'user_login' => $terminal_name, 'user_nicename' => $terminal_name, 'user_email' => '', 'display_name' => $terminal_name, 'nickname' => $terminal_name, 'first_name' => $location, 'last_name' => '', 'user_url' => '', 'description' => $description, 'user_registered' => '', // leave empty for auto 'role' => 'subscriber' // administrator, editor, subscriber, author, etc ); $user_id = wp_insert_user( $user_data ); // finaly creat the user } function create_category() { if ( !function_exists( 'wp_insert_category' ) ) { } $cat_data = array( 'cat_name' => $terminal_name, 'category_description' => $description, 'category_nicename' => '', 'category_parent' => '', 'taxonomy' => 'category' ); $create_category = wp_insert_category($cat_data); } add_filter('frm_validate_entry', 'validate_my_form', 20, 2); function validate_my_form($errors, $values){ if($values['form_id'] == 5){ //If we have the right form - ID 5 is our form ID for the setup $terminal_name = $values['item_meta'][21]; // ID 21 = entry with Terminal Name $description = $values['item_meta'][28]; // ID 27 = entry with description $location = $values['item_meta'][29]; // ID 29 = entry with location $terminal_name_old = FrmProEntriesController::get_field_value_shortcode(array('field_id' => 21, 'user_id' => 'current')); if ( username_exists( $terminal_name ) ) { //check if name is free $errors['my_error'] = $terminal_name.': registered'; } else { add_action( 'admin_init', 'create_terminal_user' ); add_action( 'admin_init', 'create_category' ); } //$errors['my_error'] = $terminal_name_old; } return $errors; }
I believe I did not understand the function() and some restriction – did I?
Thank you, I am just on my way to learn ??Michael
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Try to add new user in WordPress via function’ is closed to new replies.