LinuxCommandLibrary

wp

Manage WordPress websites from the command line

TLDR

Print information about the operating system, shell, PHP, and WP-CLI (wp) installation

$ wp --info
copy

Update WP-CLI
$ wp cli update
copy

Download a fresh WordPress installation to current directory, optionally specifying the locale
$ wp core download --locale=[locale]
copy

Create basic wpconfig file (assuming database on localhost)
$ wp config create --dbname=[dbname] --dbuser=[dbuser] --dbpass=[dbpass]
copy

Install and activate a WordPress plugin
$ wp plugin install [plugin] --activate
copy

Replace all instances of a string in the database
$ wp search-replace [old_string] [new_string]
copy

Import the contents of a WordPress Extended RSS (WXR) file
$ wp import [path/to/file.xml]
copy

SYNOPSIS

wp <command> [<subcommand>] [<args>...] [--<flag>=<value>]

<command>: Primary command (e.g., core, plugin, user).
<subcommand>: Specific action within a command (e.g., core install, plugin activate).
<args>...: Positional arguments for the subcommand.
--<flag>=<value>: Options or flags that modify command behavior.

PARAMETERS

--path=
    Path to the WordPress files. Defaults to current directory.

--url=
    The URL of the WordPress site. Helps WP-CLI determine site context.

--user=
    Set the user for operations, allowing actions to be attributed to a specific user.

--allow-root
    Permit WP-CLI to run as the root user. Use with extreme caution.

--skip-plugins[=]
    Skip loading all or a specific plugin(s) to avoid conflicts or errors.

--skip-themes[=]
    Skip loading all or a specific theme(s).

--skip-packages
    Skip loading packages installed via wp package install.

--debug[=]
    Show all PHP errors and add verbosity to the output, useful for debugging.

--prompt[=]
    Prompt for missing positional arguments or flag values during execution.

--quiet
    Suppress informational messages and only output errors.

--version
    Display the current WP-CLI version number.

--info
    Display details about the WP-CLI environment (PHP, MySQL, etc.).

--help
    Display help for a command or subcommand.

DESCRIPTION

WP-CLI is the official command-line interface for managing WordPress installations. It provides a powerful and efficient way to interact with your WordPress site directly from the terminal, eliminating the need for a web browser for many administrative and development tasks. Developers, system administrators, and even power users leverage wp to automate routine operations, troubleshoot issues, and manage various aspects of a WordPress site.

With wp, you can perform a wide range of actions, including installing and updating WordPress core, managing themes and plugins, creating and managing users, importing and exporting content, interacting with the database, clearing caches, and much more. Its hierarchical command structure makes it versatile, allowing for precise control over specific components of your WordPress environment. This tool significantly speeds up workflows for tasks that would otherwise require multiple clicks in the WordPress admin panel.

CAVEATS

WP-CLI requires a functional WordPress installation and a compatible PHP environment. It is not a standard, pre-installed Linux utility and must be installed separately. Running commands with administrative privileges, especially database operations like wp db drop, can lead to irreversible data loss if not used carefully. Always back up your site before performing major operations.

COMMAND STRUCTURE

WP-CLI operates with a hierarchical command structure. Commands are organized into namespaces (e.g., core, plugin, user), each containing multiple subcommands. For instance, to install WordPress, you use wp core install. To activate a plugin, you use wp plugin activate. This modular design allows for extensive functionality without an overly complex single command syntax.

INSTALLATION

The recommended way to install WP-CLI is by downloading its PHAR (PHP Archive) file, which is a single executable file. Alternatively, it can be installed via Composer. Once installed, it's typically moved to a directory in your system's PATH (e.g., /usr/local/bin) to make it globally accessible as the wp command.

HISTORY

The development of WP-CLI began around 2011 by Daniel Bachhuber, evolving from a personal tool into a robust, community-driven project. It rapidly gained popularity within the WordPress ecosystem due to its efficiency and power. In 2017, it became an official project on WordPress.org, signifying its importance and integration into the broader WordPress development landscape. Continuous development by a dedicated team and numerous contributors ensures its ongoing relevance and functionality.

SEE ALSO

php(1), mysql(1), nginx(8), apache2(8), composer(1), ssh(1)

Copied to clipboard