Streamlining Test User Management with WP-CLI

Creating test user accounts manually can be tedious and time-consuming, but with WP-CLI we can automate the process. In this post, we’ll take a look at a recent project and learn why WP-CLI is an essential tool for WordPress development.

A smooth onboarding experience

One of the most important aspects of any eLearning solution is the onboarding experience. When a user first visits your site, they should be able to quickly and easily create an account, log in, and start learning. If this process is too complicated or takes too long, users will leave before ever getting started.

For a recent client, we created a custom LearnDash user registration flow that made it easy for new users to get started. We kept the registration form short, collecting only the information required. The client was also keen to avoid using a CAPTCHA—which can be frustrating for users.

Preventing spam LearnDash user registration

To ensure that we hold valid email addresses and to prevent spam registration, we require users to complete a simple process before they can log in: they must first verify their email address by clicking on an activation link sent to them via email.

To avoid an exponential build up of spam WordPress user accounts, we wrote a process for identifying and removing unverified, inactive accounts.

The process runs via the WordPress cron, looking for accounts that haven’t yet been activated. We allow a two-week grace period for users to activate their accounts. This gives them plenty of time to get in touch if they need help with the activation.

Because of its destructive nature—an automated process in charge of deleting accounts! We wanted to be especially cautious. Thorough testing for the automated deletion of inactive user accounts was required.

We needed a way to generate dummy users for testing, and we required fine-grained control over the registration date and various user meta values like our verification token.

WP-CLI to the rescue, by providing us with a command that generates test users. While the initial command has some limitations, we can chain commands together to generate and manipulate our test users with the necessary registration date and user meta values.

Generating test users with WP-CLI

The wp user generate command is a powerful way to quickly create dummy user accounts for testing purposes. However, it has a limited number of parameters, allowing us to specify the number of users we want to generate, their role, and the output format.

We can make the wp user generate command more powerful by chaining it with other WP-CLI commands to further customise our test users.

Generate 10 test users

Screenshot of successful command output

Set user meta for each generated user

Screenshot of successful command output

Set both a registration date and user meta for each generated user

Screenshot of successful command output

Wrapping this up

WP-CLI shines when it comes to automating complex, multi-step actions. By chaining commands together and integrating with other command-line tools, you can perform intricate bulk operations on your WordPress site.

It was crucial to thoroughly test the account deletion process before deploying it on a live site. WP-CLI proved to again be a valuable tool, allowing us replicate the full registration workflow in bulk—taking the pain out of an otherwise repetitious WordPress admin task.

This look at our use of WP-CLI shows how automation can streamline the development process, taking advantage of the well-established and versatile WordPress ecosystem.

We are committed to crafting exceptional digital experiences that leave a lasting impact. If you have unique challenges or complex requirements, we’re here to help. Please reach out!

Get in touch

Ready to enhance your user onboarding experience or combat spam user registrations? Get in touch with the Digital Experience Experts today!

Drop us a line on 01785 279985

Send us an email

Quick Enquiry

Your information will be handled in line with our Privacy Policy.