Category Archives: WP-CLI

Command Line WordPress with WP-CLI – WordPress Perth User Goup

Today at the WordPress Perth User Group October 2014 Meetup, I gave a presentation titled Command Line WordPress with WP-CLI.

These days my favourite uses of WP-CLI include:

  1. Performing search/replaces in the WordPress database
  2. Bulk importing/managing WordPress user accounts
  3. Installing WordPress
  4. Regenerating media library items

If you’re not already using WP-CLI, I suggest heading on over to wp-cli.org and installing it.

The command line isn’t as scary as it sounds 🙂

Importing 1100 users into WordPress from a CSV file using WP-CLI

The Problem

A spreadsheet of ~1100 people (name, email address, etc) that needs to be imported into a WordPress site as users:

User Import CSV File
The User Import CSV File

I tried several user import plugins, but I had trouble with some users not importing (duplicate email addresses and/or usernames), and the plugins I tried didn’t make it easy to see which accounts were failing to import and why.

The import process via the WordPress dashboard was also encountering timeout problems due to the large amount of data being imported.

The Solution

WP-CLI’s user import command available to the rescue!

I used the following command to import the 1100+ user accounts:

wp user import-csv --skip-update user-import.csv

Note: this command skips user accounts that already exist because I included the --skip-update flag.

The output of this command made it very easy to identify the lines/users that were failing to import due to their email addresses already exist.

Bulk Deleting all Subscriber Accounts

I fixed up the duplicate data in the CSV file, and then used the following command to delete the imported user accounts before attempting the import again:

wp user list --role=subscriber --field=ID | xargs wp user delete --yes

Note: this command deletes ALL existing subscriber user accounts.

Once the imported accounts were deleted, I was able to retry the import using the command above.

Using WP-CLI for this ended up working great, and the import process was much quicker than using a plugin because I didn’t have to worry about server timeouts and other problems.

Are you using WP-CLI?

If you’re not already using WP-CLI, be sure to check out my previous presentation.

Command Line WordPress with WP-CLI

Tonight at the WordPress Melbourne User Group September 2013 Meetup, I gave a presentation titled Command Line WordPress with WP-CLI.

Video:

Slides:

 

Are you already using WP-CLI? If so, please let me know what your favourite WP-CLI command is.

If not, I suggest you go to wp-cli.org and give it a try 🙂