hook before creating new user?
-
Hi!
I want to create a new custom post type (pupil) related to a new created user. If the user already exists I want to create a new custom post type pupil that is related to the user that has that email.
I wonder how I could achieve this (in best possible way)?
(I can’t user user_register-hook because I want to do this BEFORE the user is created. I can’t use register_post because I guess the profile-builder is handling create_new_user() ?)Here’s some code so you understand what I’m trying to achieve:
//Count nr of occurences in user-table for submitted email-adress $email_form = $_POST['email']; $sql = "SELECT * FROM $wpdb->users"; $sql .= " WHERE user_email = '%s'"; $count_users_email = intval($wpdb->get_var($wpdb->prepare( $sql, $email))); //Check if email (from exists) already exists in the system (in users table) //If it doesn't, create new user into variable. If it does, store that user in variable //based on email-adress if ($count_users_email === 0) { $current_user = new WP_User($user_id); } else { $current_user = get_user_by( 'email', $email_form ); } //Create a new pupil custom post-type for this user $user_registration_post = array( 'post_title' => $current_user->display_name, 'post_type' => 'pupil', 'post_status' => 'draft', //This registration cpt is not available for public 'post_author' => $current_user->ID ); $postid_pupil = wp_insert_post( $user_registration_post );
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘hook before creating new user?’ is closed to new replies.