Doing cool things with WP-CLI

by Apr 20, 2023WordPress, WordPress Maintenance, WP-CLI0 comments

Kinsta - Unlock 4 Months OFF Annual WordPress Plans
WP-CLI Logo

If you’re managing a WordPress website, you know that there are a lot of tasks that need to be performed regularly to keep your site up and running smoothly. While there are many ways to accomplish these tasks, one tool that can make your life easier is WP-CLI.

WP-CLI is a command-line interface for WordPress that allows you to manage your website from the terminal. In this post, we’ll look at some of the cool things you can do with WP-CLI to manage your WordPress website.

1. Installing and Updating Plugins and Themes

One of the most common tasks that you need to perform when managing a WordPress website is installing and updating plugins and themes. With WP-CLI, you can easily do this from the terminal. To install a plugin or theme, you simply need to use the wp plugin install or wp theme install command.

For example, to install the popular Yoast SEO plugin, you would use the following command:

wp plugin install wordpress-seo

To update a plugin or theme, you can use the wp plugin update or wp theme update command. For example, to update the Yoast SEO plugin, you would use the following command:

wp plugin update wordpress-seo

If you want to update all plugins and themes you would run the following command:

wp plugin update --all && wp theme update --all

Now if you want to get a quick summary of pending updates on both plugins and themes, you can run this:

wp plugin list --update=available && wp theme list --update=available

A common mistake on WordPress website is to have a lot of inactive plugins, this a security risk and it just a waste of space on your disk, to get rid of all those plugins try this:

wp plugin delete $(wp plugin list --status=inactive --field=name)

2. Managing Users

Another important task that you need to perform when managing a WordPress website is managing users. With WP-CLI, you can easily add, delete, and modify users from the terminal. To add a user, you can use the wp user create command.

For example, to add a user with the username “john” and the email “[email protected]“, you would use the following command:

wp user create john [email protected] --role=editor --user_pass=strongpassword

To delete a user, you can use the wp user delete command. For example, to delete the user with the ID 5, you would use the following command:

wp user delete 5

To modify a user, you can use the wp user update command. For example, to change the email address of the user with the ID 5 to “[email protected]“, you would use the following command:

wp user update 5 [email protected]

Now, let’s talk about doing bulk actions to users. If you want to force a password reset on all administrators, you can do it like this:

wp user reset-password $(wp user list --role=administrator --field=user_login)

Pretty cool isn’t? Drop a comment below if you want more examples!

3. Managing Posts and Pages

WP-CLI also allows you to manage your WordPress posts and pages from the terminal. You can create, edit, and delete posts and pages using the wp post create, wp post update, wp post delete, wp page create, wp page update, and wp page delete commands.

For example, to create a new post with the title “My New Post” and the content “This is my new post.”, you would use the following command:

wp post create --post_title='My New Post' --post_content='This is my new post.'

To update a post with the ID 5 and change the title to “My Updated Post”, you would use the following command:

wp post delete 5

The following command is useful when you are developing a site and you need some dummy posts just to see of the blog archive and blog post pages look like, you can generate 100 differents posts with this:

wp post generate --count=100 --post_type=post

4. Managing WordPress Core

Finally, WP-CLI also allows you to manage your WordPress core installation from the terminal. You can update your WordPress installation using the wp core update command, and you can also install and uninstall WordPress using the wp core download and wp core delete commands.

For example, to update your WordPress installation, you would use the following command:

wp core update

To install a new WordPress installation, you would use the following command:

wp core download --locale=en_US

To delete your WordPress installation, you use the next command:

wp core delete

In conclusion, WP-CLI is a powerful tool that can make managing your WordPress website from the terminal a breeze. With WP-CLI, you can install and update plugins and themes, manage users, create and edit posts and pages, and manage your WordPress core installation. This can save you time and make your workflow more efficient.

So, if you’re not already using WP-CLI to manage your WordPress website, give it a try and see how it can help you streamline your website management tasks. Be sure to read their handbook for all commands and more useful examples.

Most shared hosting companies such as SiteGround and BlueHost offer WP-CLI on their plans that come with SSH access. But if you need a more stable hosting with WP-CLI, SSH, Git and other tools, be sure to check Kinsta. They are on Google Cloud and offer scalable services.

Kinsta - We love developers SSH, Git & WP-CLI
Kinsta - Unlock 4 Months OFF Annual WordPress Plans
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
WordCamps: The Ultimate WordPress Carnival

WordCamps: The Ultimate WordPress Carnival

Today, let’s dive into a world where code and community collide – the fascinating realm of WordCamps. Picture this as our own cybersecurity fortress, where WordPress enthusiasts from around the globe gather to share knowledge, exchange ideas, and fortify the digital frontier. In this post, we’ll unravel the secrets behind WordCamps, explore the concept of regional WordCamps, and even plan our next strategic moves at WordCamp Europe, WordCamp US, and WordCamp Asia. Buckle up, cyber warriors – it’s time for a WordCamp adventure!

read more
4 Local Development Tools for WordPress

4 Local Development Tools for WordPress

Local development environments are essential for WordPress developers to build, test, and debug websites and plugins without affecting live sites. Several tools have emerged over the years to simplify this process, making it easier for developers to work locally. In this article, we’ll compare four popular local development tools for WordPress: LocalWP, DevKinsta, Lando, and DDEV.

read more
Installing WP-CLI on your MacOS (via Homebrew)

Installing WP-CLI on your MacOS (via Homebrew)

As a WordPress developer or enthusiast, having the right tools at your disposal can greatly enhance your productivity. In this tutorial, we will walk you through the process of installing Homebrew and WP-CLI on macOS. Homebrew is a package manager for macOS, while WP-CLI is a command-line tool for managing WordPress installations. Let’s dive in and get started!

read more
Unlocking the Power of ChatGPT: A Guide to Content Writing Assistance in WordPress

Unlocking the Power of ChatGPT: A Guide to Content Writing Assistance in WordPress

In today’s digital age, content writing has become a crucial aspect of any successful website or blog. Crafting engaging and informative content that resonates with your audience is a challenging task. However, with the advent of advanced AI models like ChatGPT, the process of content creation can be significantly enhanced.

In this blog post, we will explore how you can leverage the power of ChatGPT to assist you in content writing within the popular content management system, WordPress.

read more
Exploring Headless WordPress: Unleashing the Power of Decoupled Websites

Exploring Headless WordPress: Unleashing the Power of Decoupled Websites

In the world of web development, the concept of headless WordPress has been gaining significant traction. As traditional monolithic CMS architectures evolve, developers are increasingly adopting headless approaches to build more flexible, scalable, and interactive websites.

In this article, we will dive into the world of headless WordPress, discussing what it entails and exploring some of the most popular frameworks and tools used to implement headless WordPress sites.

read more