• Stars
    star
    4,808
  • Rank 8,329 (Top 0.2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 12 years ago
  • Updated 9 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚙️ WP-CLI framework

WP-CLI

WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installations and much more, without using a web browser.

Ongoing maintenance is made possible by:

The current stable release is version 2.10.0. For announcements, follow @wpcli on Twitter or sign up for email updates. Check out the roadmap for an overview of what's planned for upcoming releases.

Testing Average time to resolve an issue Percentage of issues still open

Quick links: Using | Installing | Support | Extending | Contributing | Credits

Using

WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin. For instance, wp plugin install --activate (doc) lets you install and activate a WordPress plugin:

$ wp plugin install user-switching --activate
Installing User Switching (1.0.9)
Downloading installation package from https://downloads.wordpress.org/plugin/user-switching.1.0.9.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Activating 'user-switching'...
Plugin 'user-switching' activated.
Success: Installed 1 of 1 plugins.

WP-CLI also includes commands for many things you can't do in the WordPress admin. For example, wp transient delete --all (doc) lets you delete one or all transients:

$ wp transient delete --all
Success: 34 transients deleted from the database.

For a more complete introduction to using WP-CLI, read the Quick Start guide. Or, catch up with shell friends to learn about helpful command line utilities.

Already feel comfortable with the basics? Jump into the complete list of commands for detailed information on managing themes and plugins, importing and exporting data, performing database search-replace operations and more.

Installing

Downloading the Phar file is our recommended installation method for most users. Should you need, see also our documentation on alternative installation methods (Composer, Homebrew, Docker).

Before installing WP-CLI, please make sure your environment meets the minimum requirements:

  • UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment
  • PHP 5.6 or later
  • WordPress 3.7 or later. Versions older than the latest WordPress release may have degraded functionality

Once you've verified requirements, download the wp-cli.phar file using wget or curl:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Next, check the Phar file to verify that it's working:

php wp-cli.phar --info

To use WP-CLI from the command line by typing wp, make the file executable and move it to somewhere in your PATH. For example:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

If WP-CLI was installed successfully, you should see something like this when you run wp --info:

$ wp --info
OS:     Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64
Shell:  /usr/bin/zsh
PHP binary:     /usr/bin/php8.1
PHP version:    8.1.0
php.ini used:   /etc/php/8.1/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
SQL modes:
WP-CLI root dir:        /home/wp-cli/
WP-CLI vendor dir:      /home/wp-cli/vendor
WP_CLI phar path:
WP-CLI packages dir:    /home/wp-cli/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:  /home/wp-cli/wp-cli.yml
WP-CLI version: 2.10.0

Updating

You can update WP-CLI with wp cli update (doc), or by repeating the installation steps.

If WP-CLI is owned by root or another system user, you'll need to run sudo wp cli update.

Want to live life on the edge? Run wp cli update --nightly to use the latest nightly build of WP-CLI. The nightly build is more or less stable enough for you to use in your development environment, and always includes the latest and greatest WP-CLI features.

Tab completions

WP-CLI also comes with a tab completion script for Bash and ZSH. Just download wp-completion.bash and source it from ~/.bash_profile:

source /FULL/PATH/TO/wp-completion.bash

Don't forget to run source ~/.bash_profile afterwards.

If using zsh for your shell, you may need to load and start bashcompinit before sourcing. Put the following in your .zshrc:

autoload bashcompinit
bashcompinit
source /FULL/PATH/TO/wp-completion.bash

Support

WP-CLI's maintainers and contributors have limited availability to address general support questions. The current version of WP-CLI is the only officially supported version.

When looking for support, please first search for your question in these venues:

If you didn't find an answer in one of the venues above, you can:

  • Join the #cli channel in the WordPress.org Slack to chat with whomever might be available at the time. This option is best for quick questions.
  • Post a new thread in the WordPress.org support forum and tag it 'WP-CLI' so it's seen by the community.

GitHub issues are meant for tracking enhancements to and bugs of existing commands, not general support. Before submitting a bug report, please review our best practices to help ensure your issue is addressed in a timely manner.

Please do not ask support questions on Twitter. Twitter isn't an acceptable venue for support because: 1) it's hard to hold conversations in under 280 characters, and 2) Twitter isn't a place where someone with your same question can search for an answer in a prior conversation.

Remember, libre != gratis; the open source license grants you the freedom to use and modify, but not commitments of other people's time. Please be respectful, and set your expectations accordingly.

Extending

A command is the atomic unit of WP-CLI functionality. wp plugin install (doc) is one command. wp plugin activate (doc) is another.

WP-CLI supports registering any callable class, function, or closure as a command. It reads usage details from the callback's PHPdoc. WP_CLI::add_command() (doc) is used for both internal and third-party command registration.

/**
 * Delete an option from the database.
 *
 * Returns an error if the option didn't exist.
 *
 * ## OPTIONS
 *
 * <key>
 * : Key for the option.
 *
 * ## EXAMPLES
 *
 *     $ wp option delete my_option
 *     Success: Deleted 'my_option' option.
 */
$delete_option_cmd = function( $args ) {
	list( $key ) = $args;

	if ( ! delete_option( $key ) ) {
		WP_CLI::error( "Could not delete '$key' option. Does it exist?" );
	} else {
		WP_CLI::success( "Deleted '$key' option." );
	}
};
WP_CLI::add_command( 'option delete', $delete_option_cmd );

WP-CLI comes with dozens of commands. It's easier than it looks to create a custom WP-CLI command. Read the commands cookbook to learn more. Browse the internal API docs to discover a variety of helpful functions you can use in your custom WP-CLI command.

Contributing

We appreciate you taking the initiative to contribute to WP-CLI. It’s because of you, and the community around you, that WP-CLI is such a great project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Read through our contributing guidelines in the handbook for a thorough introduction to how you can get involved. Following these guidelines helps to communicate that you respect the time of other contributors on the project. In turn, they’ll do their best to reciprocate that respect when working with you, across timezones and around the world.

Leadership

WP-CLI has one project maintainer: schlessera.

On occasion, we grant write access to contributors who have demonstrated, over a period of time, that they are capable and invested in moving the project forward.

Read the governance document in the handbook for more operational details about the project.

Credits

Besides the libraries defined in composer.json, we have used code or ideas from the following projects:

More Repositories

1

php-cli-tools

A collection of tools to help with PHP command line utilities
PHP
667
star
2

profile-command

Quickly identify what's slow with WordPress
PHP
253
star
3

handbook

📖 Complete documentation for WP-CLI
PHP
178
star
4

scaffold-command

Generates code for post types, taxonomies, blocks, plugins, child themes, etc.
Gherkin
164
star
5

restful

Unlocking the potential of the WP REST API at the command line
PHP
146
star
6

doctor-command

Diagnose problems within WordPress by running a series of checks for symptoms
Gherkin
134
star
7

sample-plugin

Example plugin, generated using `wp scaffold plugin sample-plugin`
Shell
101
star
8

entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
PHP
92
star
9

i18n-command

Provides internationalization tools for WordPress projects.
Gherkin
91
star
10

wp-cli-bundle

📦 WP-CLI package that bundles the framework with a set of common commands
Gherkin
81
star
11

extension-command

Manages plugins and themes, including installs, activations, and updates.
PHP
79
star
12

wp-config-transformer

Programmatically edit a wp-config.php file
PHP
76
star
13

scaffold-package-command

Scaffolds WP-CLI commands with functional tests, full README.md, and more.
Gherkin
68
star
14

db-command

Performs basic database operations using credentials stored in wp-config.php.
PHP
68
star
15

server-command

Launches PHP's built-in web server for a specific WordPress installation.
PHP
68
star
16

search-replace-command

Searches/replaces strings in the database.
Gherkin
58
star
17

wp-super-cache-cli

A CLI interface for the WP Super Cache plugin
PHP
56
star
18

core-command

Downloads, installs, updates, and manages a WordPress installation.
Gherkin
48
star
19

dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
Gherkin
42
star
20

media-command

Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
Gherkin
42
star
21

ideas

💡 Ideas and feature requests are collected here
39
star
22

wp-cli-dev

🛠 WP-CLI development environment that allows for easy development across all packages
PHP
36
star
23

builds

Phar, Debian, and RPM builds of WP-CLI
35
star
24

wp-cli-tests

WP-CLI testing framework
PHP
32
star
25

config-command

Generates and reads the wp-config.php file.
Gherkin
32
star
26

package-index

A list of packages containing WP-CLI commands
Twig
31
star
27

checksum-command

Verifies file integrity by comparing to published checksums.
PHP
31
star
28

cron-command

Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
PHP
30
star
29

wp-cli.github.com

wp-cli.org website
CSS
24
star
30

shell-command

Opens an interactive PHP console for running and testing PHP code.
PHP
20
star
31

import-command

Imports content from a given WXR file.
PHP
20
star
32

rewrite-command

Lists or flushes the site's rewrite rules, updates the permalink structure.
PHP
20
star
33

package-command

Lists, installs, and removes WP-CLI packages.
PHP
17
star
34

google-sitemap-generator-cli

A CLI interface for the Google Sitemap Generator plugin
Gherkin
17
star
35

find-command

Find WordPress installations on the filesystem
PHP
14
star
36

admin-command

Open /wp-admin/ in a browser
PHP
14
star
37

cache-command

Manages object and transient caches.
PHP
14
star
38

language-command

Installs, activates, and manages language packs.
PHP
12
star
39

dash-docset-generator

WP-CLI Dash docset generator
PHP
12
star
40

export-command

Exports WordPress content to a WXR file.
PHP
12
star
41

maintenance-mode-command

Activates, deactivates or checks the status of the maintenance mode of a site.
PHP
9
star
42

super-admin-command

Lists, adds, or removes super admin users on a multisite installation.
Gherkin
9
star
43

eval-command

Executes arbitrary PHP code or files.
Gherkin
8
star
44

embed-command

Inspects oEmbed providers, clears embed cache, and more.
Gherkin
7
star
45

.github

🌐 Centralized community health files for all repositories
6
star
46

widget-command

Adds, moves, and removes widgets; lists sidebars.
PHP
5
star
47

role-command

Adds, removes, lists, and resets roles and capabilities.
PHP
5
star
48

automated-tests

Runs the entire test suite on a regular basis
Shell
4
star
49

autoload-splitter

PHP
3
star
50

wp-cli-shim

This repository provides easy way to install WP-CLI without the risk of conflicting dependencies.
2
star
51

dashboard

Dashboard for WP-CLI contributors
HTML
1
star
52

wp-cli-roadmap

Roadmap planning for WP-CLI
1
star
53

rpm-build

Builds a RPM of the latest stable WP-CLI release
1
star
54

deb-build

1
star