{"id":425,"date":"2024-06-14T13:16:01","date_gmt":"2024-06-14T13:16:01","guid":{"rendered":"https:\/\/zalvis.com\/docs\/?p=425"},"modified":"2024-06-14T13:16:01","modified_gmt":"2024-06-14T13:16:01","slug":"wp-cli","status":"publish","type":"post","link":"https:\/\/zalvis.com\/docs\/wp-cli.html","title":{"rendered":"How to Use the WordPress Command Line Interface \u2013 WP-CLI Tutorial"},"content":{"rendered":"<p>In the world of website development and content management, efficiency and automation are key. The WordPress Command Line Interface \u2013 or WP-CLI \u2013 is a powerful tool that can help you streamlines tasks and manage WordPress websites more effectively.<\/p>\n<p>This article provides an overview of WP-CLI, focusing on its capabilities to create, modify, and delete users, as well as handle plugins with ease. This article will show you how WP-CLI can significantly elevate your WordPress management experience.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#What_is_WP-CLI\" >What is WP-CLI?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#WP-CLI_Commands\" >WP-CLI Commands<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#Site_Information_Retrieval\" >Site Information Retrieval<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#Database_Management\" >Database Management<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#Theme_Manipulation\" >Theme Manipulation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#Post_and_Page_Creation\" >Post and Page Creation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Install_WP-CLI\" >How to Install WP-CLI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Manage_Users_with_WP-CLI\" >How to Manage Users with WP-CLI<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Create_Users\" >How to Create Users<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Modify_Users\" >How to Modify Users<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Delete_Users\" >How to Delete Users<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Manage_Plugins_with_WP-CLI\" >How to Manage Plugins with WP-CLI<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Install_Plugins\" >How to Install Plugins<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Activate_and_Deactivate_Plugins\" >How to Activate and Deactivate Plugins<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_Update_Plugins\" >How to Update Plugins<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#How_to_List_Installed_Plugins\" >How to List Installed Plugins<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/zalvis.com\/docs\/wp-cli.html\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 id=\"what-is-wp-cli\"><span class=\"ez-toc-section\" id=\"What_is_WP-CLI\"><\/span>What is WP-CLI?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>WP-CLI is a command-line tool designed for managing WordPress installations. It empowers developers, administrators, and site owners to interact with their websites directly from the command line, bypassing the need for manual interventions through the web interface.<\/p>\n<p>It&#8217;s built on PHP, and offers a wide range of commands that you can execute right from the terminal.<\/p>\n<p>By using WP-CLI, you&#8217;ll be able to manage your WordPress sites much more efficiently. Let&#8217;s see a few examples of how WP-CLI commands can simplify your workflow:<\/p>\n<h2 id=\"wp-cli-commands\"><span class=\"ez-toc-section\" id=\"WP-CLI_Commands\"><\/span>WP-CLI Commands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3 id=\"site-information-retrieval\"><span class=\"ez-toc-section\" id=\"Site_Information_Retrieval\"><\/span>Site Information Retrieval<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <code>wp site info<\/code> command provides a quick overview of your WordPress site&#8217;s important details, including the site&#8217;s URL, the number of posts and pages, the active theme, and more.<\/p>\n<p>For instance, by running <code>wp site info<\/code>, you can promptly gather essential information about your site without navigating through the WordPress admin dashboard.<\/p>\n<h3 id=\"database-management\"><span class=\"ez-toc-section\" id=\"Database_Management\"><\/span>Database Management<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>WP-CLI allows you to manage your WordPress database seamlessly. Use the <code>wp db export<\/code> command to create a database export file, ensuring a backup of your site&#8217;s data.<\/p>\n<p>If you need to import data, the <code>wp db import<\/code> command facilitates this process. For example, if you have a database backup named <code>backup.sql<\/code>, executing <code>wp db import backup.sql<\/code> restores the database to a previous state.<\/p>\n<h3 id=\"theme-manipulation\"><span class=\"ez-toc-section\" id=\"Theme_Manipulation\"><\/span>Theme Manipulation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Manipulating themes is extremely efficient with WP-CLI. For example, the <code>wp theme install<\/code> command lets you install a theme directly from the official WordPress theme repository. To install the &#8220;Twenty Twenty-One&#8221; theme, you can use the command <code>wp theme install twentytwentyone<\/code>.<\/p>\n<h3 id=\"post-and-page-creation\"><span class=\"ez-toc-section\" id=\"Post_and_Page_Creation\"><\/span>Post and Page Creation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Generating new content is made easier using WP-CLI. The <code>wp post create<\/code> and <code>wp post generate<\/code> commands enable you to create and populate posts and pages with content.<\/p>\n<p>For example, <code>wp post create --post_type=post --post_title=\"New Post\"<\/code>creates a new post with the specified title.<\/p>\n<p>These examples illustrate the versatility and power of WP-CLI in managing various aspects of your WordPress site. By harnessing its capabilities, you can enhance your efficiency, reduce manual tasks, and gain greater control over your website&#8217;s management.<\/p>\n<h2 id=\"how-to-install-wp-cli\"><span class=\"ez-toc-section\" id=\"How_to_Install_WP-CLI\"><\/span>How to Install WP-CLI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before diving into more features of WP-CLI, let&#8217;s understand the installation process.<\/p>\n<p>You can install WP-CLI globally on your system, making it accessible from any directory.<\/p>\n<p>To install WP-CLI, make sure you have PHP installed, along with a compatible version of WordPress. Download the Phar archive, place it in a directory reachable through your system&#8217;s PATH, and you&#8217;re ready to go.<\/p>\n<p>You can verify the installation by typing <code>wp --info<\/code> in your terminal. <a href=\"https:\/\/wp-cli.org\/\" target=\"_blank\" rel=\"noopener\">Here<\/a> you can find the doc with the URL to download WP-CLI with a wget.<\/p>\n<h2 id=\"how-to-manage-users-with-wp-cli\"><span class=\"ez-toc-section\" id=\"How_to_Manage_Users_with_WP-CLI\"><\/span>How to Manage Users with WP-CLI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Managing users is a fundamental task when overseeing a WordPress site. WP-CLI simplifies user management with various commands that make creating, modifying, and deleting users much easier.<\/p>\n<h3 id=\"how-to-create-users\"><span class=\"ez-toc-section\" id=\"How_to_Create_Users\"><\/span>How to Create Users<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <code>wp user create<\/code> command lets you quickly create users directly from the command line.<\/p>\n<p>To illustrate, let&#8217;s create a new user named &#8220;Alice&#8221; with the email address &#8220;<a>alice@example.com<\/a>&#8221; and the role of editor. Simply enter:<\/p>\n<pre><code>wp user create alice alice@example.com --role=editor\r\n<\/code><\/pre>\n<h3 id=\"how-to-modify-users\"><span class=\"ez-toc-section\" id=\"How_to_Modify_Users\"><\/span>How to Modify Users<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>WP-CLI also streamlines user modifications. Use the <code>wp user update<\/code>command to adjust a user&#8217;s details.<\/p>\n<p>For instance, let&#8217;s change Alice&#8217;s display name to &#8220;Alice Johnson&#8221; using the following command:<\/p>\n<pre><code>wp user update 123 --display_name=\"Alice Johnson\"\r\n<\/code><\/pre>\n<p>In this example, &#8220;123&#8221; is Alice&#8217;s ID.<\/p>\n<h3 id=\"how-to-delete-users\"><span class=\"ez-toc-section\" id=\"How_to_Delete_Users\"><\/span>How to Delete Users<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>When user accounts become obsolete or require removal for security reasons, WP-CLI simplifies the process.<\/p>\n<p>To delete a user, use the <code>wp user delete<\/code>command. To remove Alice&#8217;s account, simply execute:<\/p>\n<pre><code>wp user delete 123 --reassign=567\r\n<\/code><\/pre>\n<p>In this case, again &#8220;123&#8221; is Alice&#8217;s ID and &#8220;567&#8221; is the ID of the user you want to assign Alice&#8217;s content to (for example posts, pages, and so on).<\/p>\n<h2 id=\"how-to-manage-plugins-with-wp-cli\"><span class=\"ez-toc-section\" id=\"How_to_Manage_Plugins_with_WP-CLI\"><\/span>How to Manage Plugins with WP-CLI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Plugins play a crucial role in enhancing WordPress websites. WP-CLI extends its capabilities to manage plugins, making tasks such as installation, activation, deactivation, and updates incredibly efficient.<\/p>\n<h3 id=\"how-to-install-plugins\"><span class=\"ez-toc-section\" id=\"How_to_Install_Plugins\"><\/span>How to Install Plugins<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use the <code>wp plugin install<\/code> command to seamlessly install plugins from the WordPress repository.<\/p>\n<p>For instance, let&#8217;s install the &#8220;Akismet&#8221; anti-spam plugin:<\/p>\n<pre><code>wp plugin install akismet\r\n<\/code><\/pre>\n<h3 id=\"how-to-activate-and-deactivate-plugins\"><span class=\"ez-toc-section\" id=\"How_to_Activate_and_Deactivate_Plugins\"><\/span>How to Activate and Deactivate Plugins<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Managing plugin status is quite easy with WP-CLI. Activate or deactivate plugins using the <code>wp plugin activate<\/code> and <code>wp plugin deactivate<\/code> commands respectively.<\/p>\n<p>To activate the &#8220;Akismet&#8221; plugin, type the following command:<\/p>\n<pre><code>wp plugin activate akismet\r\n<\/code><\/pre>\n<h3 id=\"how-to-update-plugins\"><span class=\"ez-toc-section\" id=\"How_to_Update_Plugins\"><\/span>How to Update Plugins<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Keeping plugins up to date is vital for security and performance. The <code>wp plugin update<\/code> command makes updates hassle-free.<\/p>\n<p>To update all installed plugins, simply run:<\/p>\n<pre><code>wp plugin update --all\r\n<\/code><\/pre>\n<h3 id=\"how-to-list-installed-plugins\"><span class=\"ez-toc-section\" id=\"How_to_List_Installed_Plugins\"><\/span>How to List Installed Plugins<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>WP-CLI offers an overview of installed plugins with the <code>wp plugin list<\/code>command. This provides a quick snapshot of each plugin&#8217;s status, version, and available updates:<\/p>\n<pre><code>wp plugin list\r\n<\/code><\/pre>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>WP-CLI is an invaluable asset in the world of WordPress management. Its extensive command set helps you manage users and plugins \u2013 and much more \u2013 with remarkable ease. This saves you time and minimizes manual interventions.<\/p>\n<p>By harnessing the power of WP-CLI, administrators and developers can streamline workflows, improve security, and ensure their WordPress websites operate seamlessly.<\/p>\n<div class=\"mgqbj69d75cbf0e8ac\" >If you enjoyed this article, then you\u2019ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24\/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! <a href=\"https:\/\/zalvis.com\/\">Check out our services.<\/a><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.mgqbj69d75cbf0e8ac {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.mgqbj69d75cbf0e8ac {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.mgqbj69d75cbf0e8ac {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.mgqbj69d75cbf0e8ac {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.mgqbj69d75cbf0e8ac {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>In the world of website development and content management, efficiency and automation are key. The WordPress Command Line Interface \u2013 or WP-CLI \u2013 is a powerful tool that can help you streamlines tasks and manage WordPress websites more effectively. This article provides an overview of WP-CLI, focusing on its capabilities to create, modify, and delete [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":1,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":426,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/425\/revisions\/426"}],"wp:attachment":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}