Skip to content

Does WP-CLI’s Import Users from CSV Feature Write Directly to the Database?

I’m writing this post in response to a question that was asked during my WP-CLI Talk at WordCamp Columbus.  After demonstrating how you can import users into WordPress from the command line using the:

wp user import-csv

command, one attendee asked if, while looping through the rows in the CSV file, WP-CLI was directly writing the user data to the database, or if it was calling the built-in WordPress functions for doing so, allowing you to hook into WordPress’ actions and filters.  It was a good question, one that I wasn’t 100% confident answering in front of the audience.

I’ve now looked into the code, and found….

This command, as it should, uses the WordPress functions wp_insert_user() and wp_update_user() to add users to the database.  These functions call the user_register (new user) or the profile_update (updated user) actions upon successful completion.   You can also hook into a variety of filters during this process, including:

  1. pre_user_login
  2. pre_user_nicename
  3. pre_user_url
  4. pre_user_email
  5. pre_user_nickname
  6. pre_user_first_name
  7. pre_user_last_name
  8. pre_user_display_name
  9. pre_user_description

Hooking into any of the above listed filters will allow you to modify the value being inserted into those fields before they are written to the database.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.