Изображение Илюстрация или скриншот на някои от горепосочените WP CLI команди изпълнени в терминал

How to use WP-CLI to manage WordPress sites quickly and efficiently

WP-CLI is a powerful command-line tool that allows managing WordPress installations directly from the terminal. This tool can save developers and site administrators a lot of time and effort, especially when dealing with multiple installations or performing complex tasks. In this post, we'll cover the basics of working with WP-CLI, as well as some of the most useful commands you can use to manage your WordPress sites.

Изображение Илюстрация или скриншот на WP CLI в терминал

1. Install and setup WP-CLI

To get started with WP-CLI, you must first install it on your system. Here are the steps to install WP-CLI:

  • Open a terminal (on Mac/Linux) or command window (on Windows)
  • Run the following command:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  • After downloading wp-cli.phar, make the file executable with this command:
chmod +x wp-cli.phar
  • Move wp-cli.phar in a directory that is included in the system PATH, so you can use wp command from anywhere. For example:
sudo mv wp-cli.phar /usr/local/bin/wp

After installing WP-CLI, you can check the version and make sure the installation was successful by running the following command:

wp --info

2. Basic commands and management of WordPress sites

After you have successfully installed WP-CLI, you can start using its versatile commands to manage your WordPress sites. Here are some basic commands to get you started:

  • Update WordPress: wp core update
  • Install theme: wp theme install
  • Activate a theme: wp theme activate
  • Disable a theme: wp theme deactivate
  • Install Plugin: wp plugin install
  • Activating a plugin: wp plugin activate
  • Disable plugin: wp plugin deactivate
  • Update Plugins: wp plugin update --all
  • Create a new user: wp user create --role=
  • Change a user's password: wp user update --user_pass=
Изображение Илюстрация или скриншот на някои от горепосочените WP CLI команди изпълнени в терминал

3. Working with the database and migrations

WP-CLI offers powerful tools for working with the database of your WordPress sites, allowing you to backup, restore, import and export data, as well as execute SQL queries directly from the command line. Here are some useful commands for working with databases:

  • Export the database: wp db export
  • Import the database: wp db import
  • Database Optimization: wp db optimize
  • Executing an SQL query: wp db query " "

4. Automate tasks using WP-CLI

WP-CLI can be used to automate routine tasks such as updating WordPress themes, plugins, and core, clearing the cache, or generating database backups. You can create scripts that use WP-CLI commands and set them to run automatically at certain intervals using your operating system's system task scheduler (cron).

Изображение Илюстрация или скриншот на пример за автоматизиран скрипт с WP CLI команди

WP-CLI is a powerful and flexible tool that can significantly improve the efficiency of managing WordPress sites. With its help, you can perform a wide range of tasks, such as installing and updating themes and plugins, managing users, working with the database, and automating routine tasks. Mastering WP-CLI can save you time and effort, allowing you to focus on the essential aspects of your work as a WordPress site developer or administrator.

Similar Posts

Leave a Reply

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