The problem is from wp_insert_user
and the fact that your value for user_pass
is empty.
You should update your code as so
$random_password = wp_generate_password(8,false);
$user_data = array(
'user_login' => $first_name,
'user_pass' => $random_password,
'user_email' => $trainer_email,
'first_name' => $first_name,
'last_name' => $last_name,
'role' => 'trainer'
);
And remove this line wp_set_password($random_password, $user_id);
You should also check the value of your $user_id
to make sure it’s not returning a WP_Error object
You can use var_dump($user_id')
Related Posts:
- Automatically delete inactive users after 2 months
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- ‘username_exists’ still returns an ID even after deleting record from the database?
- How can I add a user through SQL?
- importing users where password is provided as md5 + much metadata
- Search multiple meta keys at once
- Return ID of authors who have at least one post
- Add user data to table when user is created?
- Bulk create clean user_nicename from user_email with SQL function
- C# user_nicename and Display name blank
- How do I transfer user passwords from one WordPress site to another?
- I am getting mysql_real_escape_string() function error while adding user?
- MySQL query to mass change role of users
- WordPress SQL Issue not returning correct reselts
- create new users in db starting at what ID?
- Delete Users without a First and Last Name
- Delete all users with Editor role and their content mysql
- How do I change the user via SQL?
- is_user_logged_in() not working after domain change
- MySQL query to list users who never signed in
- List users by last name in WP_User_Query
- Email user when password is reset by admin
- How to work around “that email address has already been used” error?
- How can I run a WP-CLI command as authenticated user?
- How to redirect a specific user after log-in?
- How to Prevent deleting user accounts in WordPress Back-end?
- LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
- How to stop a user from updating the post date
- Recover the user that have been deleted
- determining if the user is logged in
- Adding a photo to each WP user
- WordPress edit_user_profile_update update secondary role
- Check if user is online?
- WP_User->add_role producing unexpected results
- Adding tags and inputs to a user’s profile
- Changing default Buddypress avatar affects all site avatars (because gravatar)
- Custom style on profile options page
- Best way to have an per-user customized private section
- How to query users who have empty first_name?
- Post as someone else
- How to make user accept license agreement before download
- Does wp_delete_user() remove all user content?
- wp_login_form() passing user ID into URL on redirect?
- Users: List A to Z, for Users
- Max no of simultaneous active sessions for a single user
- WPML Default Language User Meta [closed]
- Search Users base on meta_value & meta_key
- Favorite taxonomy archive page?
- Removing all trace of member profiles
- WordPress API for search
- Fix permissions for users role
- Are there mutiple ways to get usernames (as a hacker)
- Rest api return all users (even without content) to all users
- Column Sorting Code on users.php
- How can I allow an User to publish only 5 posts per month?
- How to stop redirect if user is already on correct page (Using Case Switch)
- Where are $current_user->allcaps set?
- How to activate the user search
- How change user type from contributor to author
- Obtaining user table for one site on multisite set up
- How to allow registered users to submit the form only 5 times per day?
- Is there any action /filter hook I can use to disable login for some user role?
- Preventing user enumeration: which logic is better?
- How can I do a url redirect to include a wordpress username?
- WP_User_Query combining role and ids
- WordPress current month users
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- Custom registration and pending approval
- Let logged-in users use radio buttons (yes and no) to exclude their author profile from the user listing
- Make new users automatically approved
- Adding fields to the “Add New User” but the form data not saved into DB
- Using a custom field value as current users name [closed]
- How would I restrict certain user levels from editing categories
- How can I set wp_dropdown_users so that it shows only authors?
- What does “link” refer to when you delete a user?
- WP Create User – Preventing repeated information
- set automatically email address for WordPress users
- hide user is currently editing warning in admin post page
- Restricting wordpress login sessions for a web app
- change user password REST API
- Use WP cookie to authentificate user on an external app
- Find count of WordPress users by role and search string for user name
- How do I add profile fields in specific section?
- fine-grained capabilities for user related capabilities
- Users activity history
- How to destroy all user sessions via WP-CLI
- Is a list of user names or IDs in a custom profile field the best way to create a followers list?
- Custom User Role: Can Edit Own Page, Cannot Create New
- How to restrict Admin from creating new users from Add new user screen in dashboard to only of one domain?
- Redirect current user
- custom login form, guide me
- Edit dashboard based on user ID
- Designing a member area on my site
- Link to Authors blog posts
- view and update form only for registered users
- Redirect based on log-in status per JavaScript
- Create users from frontend without password
- How to get user contact info
- Set a minimal number for next user_id