### Install a plugin Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Example of installing a plugin using the 'wp plugin install' command. ```bash $ wp plugin install akismet Installing Akismet (3.1.8) Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.1.8.zip... Unpacking the package... Installing the plugin... Plugin installed successfully. ``` -------------------------------- ### Running the first WP-CLI command Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Example of navigating to a WordPress folder and running the 'wp --info' command to display WP-CLI installation information. ```bash cd /var/www/mysite wp --info ``` -------------------------------- ### Install WordPress in 5 seconds Source: https://github.com/wp-cli/handbook/blob/main/commands/core/install.md This example shows how to install WordPress with all the necessary parameters. ```bash $ wp core install --url=example.com --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com Success: WordPress installed successfully. ``` -------------------------------- ### Complete installation example with verification Source: https://github.com/wp-cli/handbook/blob/main/guides/verifying-downloads.md A comprehensive example demonstrating how to download, verify, and install WP-CLI. ```bash # Download WP-CLI curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # Download signature curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.asc # Import signing key (first time only) curl -L https://raw.githubusercontent.com/wp-cli/builds/gh-pages/wp-cli.pgp | gpg --import # Verify signature gpg --verify wp-cli.phar.asc wp-cli.phar # If verification succeeds, test it works php wp-cli.phar --info # Make executable and move to PATH chmod +x wp-cli.phar sudo mv wp-cli.phar /usr/local/bin/wp # Verify installation wp --info ``` -------------------------------- ### Scenario Example Source: https://github.com/wp-cli/handbook/blob/main/references/behat-steps/given-these-installed-and-active-plugins.md An example of how to use the 'Given these installed and active plugins:' Behat step within a scenario. ```gherkin Scenario: My example scenario Given a WP installation And these installed and active plugins: """ akismet wordpress-importer """ ``` -------------------------------- ### WP-CLI Specific Subcommand Help Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Illustrates how to get help on a specific subcommand, like 'plugin install'. ```bash wp help plugin install ``` -------------------------------- ### Download and install WordPress Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Steps to download, configure, and install WordPress using WP-CLI. ```bash $ wp core download --path=wpclidemo.dev Creating directory '/srv/www/wpclidemo.dev/'. Downloading WordPress 4.6.1 (en_US)... Using cached file '/home/vagrant/.wp-cli/cache/core/wordpress-4.6.1-en_US.tar.gz'... Success: WordPress downloaded. ``` ```bash $ cd wpclidemo.dev $ wp config create --dbname=wpclidemo --dbuser=root --prompt=dbpass 1/10 [--dbpass=]: Success: Generated 'wp-config.php' file. ``` ```bash $ wp db create Success: Database created. ``` ```bash $ wp core install --url=wpclidemo.dev --title="WP-CLI" --admin_user=wpcli --admin_password=wpcli --admin_email=info@wp-cli.org Success: WordPress installed successfully. ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-wp-installation-in.md Examples of using the Behat step to install WordPress in a given directory, including version-specific installations. ```gherkin Scenario: My example scenario Given a WP installation in 'foo' ... Scenario: My other scenario Given a WP install in 'bar' ... Scenario: My version-specific scenario Given a WP 6.4.2 installation in 'subdir' ... ``` -------------------------------- ### Getting the WordPress core version Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Command to display the version of the installed WordPress core. ```bash wp core version ``` -------------------------------- ### Install from a local zip file Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/install.md This example shows how to install a theme from a local zip file. ```bash $ wp theme install ../my-theme.zip ``` -------------------------------- ### Install from a local zip file Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/install.md This example shows how to install a plugin from a local zip file. ```bash $ wp plugin install ../my-plugin.zip Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. ``` -------------------------------- ### Synopsis for wp plugin install Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md The synopsis for the 'wp plugin install' command, showing positional and associative arguments. ```bash $ wp plugin install usage: wp plugin install ... [--version=] [--force] [--activate] [--activate-network] ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/references/behat-steps/given-a-wp-installation-in-subdir.md Examples of using the 'Given a WP installation in :subdir' Behat step. ```gherkin Scenario: My example scenario Given a WP installation in 'foo' ... Scenario: My other scenario Given a WP install in 'bar' ... ``` -------------------------------- ### Find WordPress installations. Source: https://github.com/wp-cli/handbook/blob/main/commands/find.md This example demonstrates how to find WordPress installations starting from the current directory. ```bash $ wp find ./ ``` -------------------------------- ### Install the latest version from wordpress.org and activate Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/install.md This example shows how to install the latest version of a plugin from wordpress.org and activate it immediately. ```bash $ wp plugin install bbpress --activate Installing bbPress (2.5.9) Downloading install package from https://downloads.wordpress.org/plugin/bbpress.2.5.9.zip... Using cached file '/home/vagrant/.wp-cli/cache/plugin/bbpress-2.5.9.zip'... Unpacking the package... Installing the plugin... Plugin installed successfully. Activating 'bbpress'... Plugin 'bbpress' activated. Success: Installed 1 of 1 plugins. ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-wp-installation.md Examples of how to use the "Given a WP installation" Behat step in different scenarios. ```gherkin Scenario: My example scenario Given a WP installation ... Scenario: My other scenario Given a WP install ... Scenario: My version-specific scenario Given a WP 6.4.2 installation ... ``` -------------------------------- ### Install the latest version from wordpress.org and activate Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/install.md This example shows how to install a theme from wordpress.org and activate it immediately. ```bash $ wp theme install twentysixteen --activate Installing Twenty Sixteen (1.2) Downloading install package from http://downloads.wordpress.org/theme/twentysixteen.1.2.zip... Unpacking the package... Installing the theme... Theme installed successfully. Activating 'twentysixteen'... Success: Switched to 'Twenty Sixteen' theme. Success: Installed 1 of 1 themes. ``` -------------------------------- ### Install a package hosted at a GitLab.com URL. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/install.md This example shows how to install a package from a GitLab.com repository using its URL. ```bash $ wp package install https://gitlab.com/foo/wp-cli-bar-command.git ``` -------------------------------- ### Install a package hosted at a git URL. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/install.md This example shows how to install a package directly from a Git URL. ```bash $ wp package install runcommand/hook ``` -------------------------------- ### Behat Scenarios Source: https://github.com/wp-cli/handbook/blob/main/references/behat-steps/given-a-wp-installation-with-composer.md Example Behat scenarios demonstrating the 'Given a WP installation with Composer' step. ```gherkin Scenario: My example scenario Given a WP installation with Composer ... Scenario: My other scenario Given a WP install with Composer ... ``` -------------------------------- ### Listing installed plugins Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Command to list all plugins installed on the WordPress site. ```bash wp plugin list ``` -------------------------------- ### Forcefully re-install all installed plugins Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/install.md This example demonstrates how to forcefully re-install all currently installed plugins. ```bash $ wp plugin install $(wp plugin list --field=name) --force Installing Akismet (3.1.11) Downloading install package from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip... Unpacking the package... Installing the plugin... Removing the old version of the plugin... Plugin updated successfully Success: Installed 1 of 1 plugins. ``` -------------------------------- ### Activate a plugin Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Example of activating a plugin using the 'wp plugin activate' command. ```bash $ wp plugin activate akismet Success: Plugin 'akismet' activated. ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-wp-installation-with-composer.md Example scenarios demonstrating the usage of the 'Given a WP installation with Composer' Behat step. ```gherkin Scenario: My example scenario Given a WP installation with Composer ... Scenario: My other scenario Given a WP install with Composer ... ``` -------------------------------- ### Install the development version from wordpress.org Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/install.md This example demonstrates how to install a development version of a plugin from wordpress.org. ```bash $ wp plugin install bbpress --version=dev Installing bbPress (Development Version) Downloading install package from https://downloads.wordpress.org/plugin/bbpress.zip... Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. ``` -------------------------------- ### Install a package in a .zip file. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/install.md This example illustrates installing a package from a local .zip file. ```bash $ wp package install google-sitemap-generator-cli.zip ``` -------------------------------- ### Add a user as a super-admin Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Command to grant super admin privileges to an existing user on a multisite installation. ```bash $ wp super-admin add wpcli Success: Granted super-admin capabilities. ``` -------------------------------- ### Install the latest stable version. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/install.md This example demonstrates installing the most recent stable release of a package using a version constraint. ```bash $ wp package install wp-cli/server-command:@stable ``` -------------------------------- ### Update plugins to their latest version Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Command to update all installed plugins to their latest available versions. ```bash $ wp plugin update --all Enabling Maintenance mode... Downloading update from https://downloads.wordpress.org/plugin/akismet.3.1.11.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Downloading update from https://downloads.wordpress.org/plugin/nginx-champuru.3.2.0.zip... Unpacking the update... Installing the latest version... Removing the old version of the plugin... Plugin updated successfully. Disabling Maintenance mode... Success: Updated 2/2 plugins. +------------------------+-------------+-------------+---------+ | name | old_version | new_version | status | +------------------------+-------------+-------------+---------+ | akismet | 3.1.3 | 3.1.11 | Updated | | nginx-cache-controller | 3.1.1 | 3.2.0 | Updated | +------------------------+-------------+-------------+---------+ ``` -------------------------------- ### Specify version constraints when installing packages Source: https://github.com/wp-cli/handbook/blob/main/guides/installing-packages.md Examples of using version constraints with the `wp package install` command. ```bash # Install a specific version wp package install wp-cli/server-command:2.0.0 # Install with caret operator (allows non-breaking updates) wp package install wp-cli/server-command:^1.0 # Install with tilde operator (allows patch-level updates) wp package install wp-cli/server-command:~1.2 # Install the latest stable release wp package install wp-cli/server-command:@stable # Install from a development branch wp package install wp-cli/server-command:dev-main ``` -------------------------------- ### Package Installation Output Source: https://github.com/wp-cli/handbook/blob/main/contributions/bug-reports.md Example output from installing a WP-CLI package, showing success and then an error. ```bash $ wp package install wp-cli/scaffold-package-command:@stable Installing package wp-cli/scaffold-package-command (@stable) Updating /root/.wp-cli/packages/composer.json to require the package... Using Composer to install the package... --- Loading composer repositories with package information Updating dependencies Resolving dependencies through SAT Dependency resolution completed in 0.001 seconds Analyzed 421 packages to resolve dependencies Analyzed 96 rules to resolve dependencies Package operations: 1 install, 0 updates, 0 removals Installs: wp-cli/scaffold-package-command:1.2.0 - Installing wp-cli/scaffold-package-command (1.2.0) Writing lock file Generating autoload files --- Success: Package installed. ``` -------------------------------- ### Install a package by name, Git URL, local directory, or .zip file Source: https://github.com/wp-cli/handbook/blob/main/guides/installing-packages.md Examples of installing a WP-CLI package using different sources. ```bash # Install a package by name wp package install wp-cli/server-command # Install from a Git URL wp package install https://github.com/wp-cli/server-command.git # Install from a local directory wp package install /path/to/package # Install from a .zip file wp package install package.zip ``` -------------------------------- ### Get help for `core` command Source: https://github.com/wp-cli/handbook/blob/main/commands/help.md This example shows how to get help for the `core` command in WP-CLI. ```bash wp help core ``` -------------------------------- ### Install a multisite network Source: https://github.com/wp-cli/handbook/blob/main/commands/core/multisite-install.md Example of installing a multisite network with specified admin credentials and site title. ```bash $ wp core multisite-install --title="Welcome to the WordPress" \ > --admin_user="admin" --admin_password="password" \ > --admin_email="user@example.com" Single site database tables already present. Set up multisite database tables. Added multisite constants to wp-config.php. Success: Network installed. Don't forget to set up rewrite rules. ``` -------------------------------- ### Generate all documentation Source: https://github.com/wp-cli/handbook/blob/main/README.md Example command to update WP-CLI, install packages, and generate all documentation. ```bash wp cli update --nightly bin/install_packages.sh WP_CLI_PACKAGES_DIR=bin/packages WP_CLI_CONFIG_PATH=/dev/null wp handbook gen-all ``` -------------------------------- ### Get path to an installed package. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/path.md This example demonstrates how to retrieve the path for a specific installed package. ```bash $ wp package path wp-cli/server-command /home/person/.wp-cli/packages/vendor/wp-cli/server-command ``` -------------------------------- ### SSH into Remote Server Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md An example command to connect to a remote server via SSH. ```bash ssh username@yoursite.com ``` -------------------------------- ### Install a package from a Git repository Source: https://github.com/wp-cli/handbook/blob/main/guides/commands-cookbook.md Examples of using the 'wp package install' command with both HTTPS and SSH links to a Git repository. ```bash # Installing the package using an HTTPS link $ wp package install https://github.com/wp-cli/server-command.git # Installing the package using an SSH link $ wp package install git@github.com:wp-cli/server-command.git ``` -------------------------------- ### Error when running WP-CLI outside WordPress folder Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Example of the error message received when WP-CLI is run from a directory that is not a WordPress installation. ```bash Error: This does not seem to be a WordPress installation. ``` -------------------------------- ### Start the web server using different settings Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-start-webserver.md Launches PHP's built-in web server with a specified host and port. ```bash $ wp server --port=9090 --host=192.168.0.4 ``` -------------------------------- ### WP-CLI Specific Command Help Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Shows how to get help on a specific WP-CLI command, such as 'plugin'. ```bash wp help plugin ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-wp-installation-with-composer-and-a-custom-vendor-directory-vendor-directory.md Example scenarios demonstrating the usage of the Behat step. ```gherkin Scenario: My example scenario Given a WP installation with Composer and a custom vendor directory 'vendor-custom' ... Scenario: My other scenario Given a WP install with Composer with Composer and a custom vendor directory 'vendor-custom' ... ``` -------------------------------- ### Examples Source: https://github.com/wp-cli/handbook/blob/main/references/argument-syntax.md Practical examples showing different syntax types. ```bash # Required arguments (no brackets) wp config create --dbname=mydb --dbuser=root ``` ```bash # Optional arguments with defaults wp config create --dbname=mydb --dbuser=root --dbhost=localhost ``` ```bash # Boolean flags wp plugin install hello-dolly --activate --force ``` ```bash # Negated boolean flags wp plugin list --no-color ``` ```bash # Associative arguments wp cron event schedule my_hook --foo=bar --baz=qux ``` ```bash # Multiple values wp plugin install plugin1 plugin2 plugin3 ``` ```bash # Optional fields with specific format options wp post list --format=json --fields=ID,post_title,post_date ``` -------------------------------- ### Install from a remote zip file Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/install.md This example shows how to install a theme from a remote zip file URL. ```bash $ wp theme install http://s3.amazonaws.com/bucketname/my-theme.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef ``` -------------------------------- ### Scenario: My example scenario Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-database.md Example usage of the 'Given a database' Behat step. ```gherkin Scenario: My example scenario Given a database ... ``` -------------------------------- ### Install from a remote zip file Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/install.md This example demonstrates how to install a plugin from a remote zip file URL. ```bash $ wp plugin install http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef Downloading install package from http://s3.amazonaws.com/bucketname/my-plugin.zip?AWSAccessKeyId=123&Expires=456&Signature=abcdef Unpacking the package... Installing the plugin... Plugin installed successfully. Success: Installed 1 of 1 plugins. ``` -------------------------------- ### List installed plugins Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-create-custom-plugins.md Lists all installed plugins, showing their status, update availability, and version. ```bash $ wp plugin list +-------------------+----------+-----------+---------+ | name | status | update | version | +-------------------+----------+-----------+---------+ | akismet | inactive | available | 4.1.5 | | hello | inactive | none | 1.7.2 | | wpcli-demo-plugin | inactive | none | 0.1.0 | +-------------------+----------+-----------+---------+ ``` -------------------------------- ### Running WP-CLI commands within the WordPress folder Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Example of navigating to a WordPress site's folder and listing plugins. ```bash cd /var/www/mysite wp plugin list ``` -------------------------------- ### Install wp profile package Source: https://github.com/wp-cli/handbook/blob/main/how-to/figure-out-why-wordpress-is-slow.md Installs the `wp profile` command-line tool. ```bash $ wp package install wp-cli/profile-command ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-php-built-in-web-server-to-serve-subdir.md Example of using the Behat step in a scenario. ```gherkin Scenario: My example scenario Given a WP installation And a PHP built-in web server to serve 'WordPress' ``` -------------------------------- ### Install Japanese language for Akismet Source: https://github.com/wp-cli/handbook/blob/main/commands/language/plugin/install.md This example shows how to install the Japanese language pack for the Akismet plugin. ```bash $ wp language plugin install akismet ja Downloading translation from https://downloads.wordpress.org/translation/plugin/akismet/4.0.3/ja.zip... Unpacking the update... Installing the latest version... Removing the old version of the translation... Translation updated successfully. Language 'ja' installed. Success: Installed 1 of 1 languages. ``` -------------------------------- ### Scenario Example Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-save-the-file-as.md Example of how to use the Behat step in a scenario. ```gherkin Scenario: My example scenario Given a WP installation with Composer And save the {RUN_DIR}/composer.json file as {COMPOSER_JSON} ``` -------------------------------- ### List all signups. Source: https://github.com/wp-cli/handbook/blob/main/commands/user/signup/list.md This example shows how to list all signups with their details in a table format. ```bash $ wp user signup list +-----------+------------+---------------------+---------------------+--------+------------------+ | signup_id | user_login | user_email | registered | active | activation_key | +-----------+------------+---------------------+---------------------+--------+------------------+ | 1 | bobuser | bobuser@example.com | 2024-03-13 05:46:53 | 1 | 7320b2f009266618 | | 2 | johndoe | johndoe@example.com | 2024-03-13 06:24:44 | 0 | 9068d859186cd0b5 | +-----------+------------+---------------------+---------------------+--------+------------------+ ``` -------------------------------- ### Get all theme mods. Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/mod/get.md This example shows how to retrieve all theme modifications. ```bash $ wp theme mod get --all +------------------+---------+ | key | value | +------------------+---------+ | background_color | dd3333 | | link_color | #dd9933 | | main_text_color | #8224e3 | +------------------+---------+ ``` -------------------------------- ### Usage Examples Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-downloaded-phar-with-the-same-version-version.md Examples of using the Behat step in scenarios. ```gherkin Scenario: My example scenario Given an empty directory And a downloaded Phar with version "2.11.0" Scenario: My other scenario Given an empty directory And a downloaded Phar with the same version ``` -------------------------------- ### Install and activate a plugin in one step Source: https://github.com/wp-cli/handbook/blob/main/guides/common-tasks.md Installs and immediately activates a specified plugin. ```bash wp plugin install contact-form-7 --activate ``` -------------------------------- ### Get package path. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/path.md This example shows how to get the default package path. ```bash $ wp package path /home/person/.wp-cli/packages/ ``` -------------------------------- ### Registering a command with arguments and options Source: https://github.com/wp-cli/handbook/blob/main/guides/commands-cookbook.md Example of registering a 'hello' command with positional, associative, and flag arguments, demonstrating the use of 'shortdesc', 'synopsis', and 'longdesc'. ```php $hello_command = function( $args, $assoc_args ) { list( $name ) = $args; $type = $assoc_args['type']; WP_CLI::$type( "Hello, $name!" ); if ( isset( $assoc_args['honk'] ) ) { WP_CLI::log( 'Honk!' ); } }; WP_CLI::add_command( 'example hello', $hello_command, array( 'shortdesc' => 'Prints a greeting.', 'synopsis' => array( array( 'type' => 'positional', 'name' => 'name', 'description' => 'The name of the person to greet.', 'optional' => false, 'repeating' => false, ), array( 'type' => 'assoc', 'name' => 'type', 'description' => 'Whether or not to greet the person with success or error.', 'optional' => true, 'default' => 'success', 'options' => array( 'success', 'error' ), ), array( 'type' => 'flag', 'name' => 'honk', 'optional' => true, ), ), 'when' => 'after_wp_load', 'longdesc' => '## EXAMPLES' . "\n\n" . 'wp example hello Newman', ) ); ``` -------------------------------- ### Get cache. Source: https://github.com/wp-cli/handbook/blob/main/commands/cache/get.md Example of how to retrieve a cached value using its key and group. ```bash $ wp cache get my_key my_group my_value ``` -------------------------------- ### Generate a config file Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-install.md The basic syntax of the command is the following: `wp config create --dbname= --dbuser= [--dbpass=]` ```bash $ wp config create --dbname=your_db_name_here --dbuser=your_db_user_here --prompt=dbpass 1/10 [--dbpass=]: type_your_password Success: Generated 'wp-config.php' file. ``` -------------------------------- ### Usage Examples Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/when-i-run-try.md Examples demonstrating the usage of 'run' and 'try' Behat steps. ```gherkin Scenario: My example scenario When I run `wp core version` Then STDOUT should contain: """ 6.8 """ Scenario: My other scenario When I try `wp i18n make-pot foo bar/baz.pot` Then STDERR should contain: """ Error: Not a valid source directory. """ And the return code should be 1 ``` -------------------------------- ### List installed packages. Source: https://github.com/wp-cli/handbook/blob/main/commands/package/list.md This example shows how to list all installed WP-CLI packages with their details. ```bash $ wp package list +-----------------------+------------------+----------+-----------+----------------+ | name | authors | version | update | update_version | +-----------------------+------------------+----------+-----------+----------------+ | wp-cli/server-command | Daniel Bachhuber | dev-main | available | 2.x-dev | +-----------------------+------------------+----------+-----------+----------------+ ``` -------------------------------- ### Usage Example Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/then-stdout-stderr-should-be-a-version-string-w.md This is an example of how to use the Behat step in a scenario. ```gherkin Scenario: My example scenario Given a WP install When I run `wp core version Then STDOUT should be a version string >= 6.8 ``` -------------------------------- ### Get a transient value Source: https://github.com/wp-cli/handbook/blob/main/commands/transient/get.md This example shows how to retrieve the value of a transient with the key 'sample_key'. ```bash $ wp transient get sample_key test data ``` -------------------------------- ### Search and replace URLs Source: https://github.com/wp-cli/handbook/blob/main/guides/quick-start.md Commands for searching and replacing URLs in the database, with options for dry runs. ```bash wp search-replace 'http://oldsite.com' 'http://newsite.com' --dry-run ``` ```bash wp search-replace 'http://oldsite.com' 'http://newsite.com' ``` -------------------------------- ### Get theme path Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/path.md This example shows how to get the path to the currently active theme. ```bash $ wp theme path /var/www/example.com/public_html/wp-content/themes ``` -------------------------------- ### Activate a plugin Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-create-custom-plugins.md Activates a specified plugin. ```bash $ wp plugin activate wpcli-demo-plugin Plugin 'wpcli-demo-plugin' activated. Success: Activated 1 of 1 plugins. ``` -------------------------------- ### Get status of comment. Source: https://github.com/wp-cli/handbook/blob/main/commands/comment/status.md This example shows how to get the status of a specific comment by its ID. ```bash $ wp comment status 1337 approved ``` -------------------------------- ### Get only the description. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/get.md This example shows how to retrieve only a specific field, in this case, the 'description', for an ability. ```bash $ wp ability get core/get-site-info --field=description Returns site information configured in WordPress. ``` -------------------------------- ### Execute and output as YAML. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/run.md This example shows how to execute an ability and format the output as YAML. ```bash $ wp ability run core/get-site-info --format=yaml --user=admin name: Test Blog description: Just another WordPress site ... ``` -------------------------------- ### WP_CLI\Utils\http_request() Usage Example Source: https://github.com/wp-cli/handbook/blob/main/internal-api/wp-cli-utils-http-request.md Example of using http_request to get an MD5 hash for a downloaded WordPress archive. ```php # `wp core download` verifies the hash for a downloaded WordPress archive $md5_response = Utils\http_request( 'GET', $download_url . '.md5' ); if ( 20 != substr( $md5_response->status_code, 0, 2 ) ) { WP_CLI::error( "Couldn't access md5 hash for release (HTTP code {$response->status_code})" ); } ``` -------------------------------- ### Install WordPress Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-install.md To install WordPress now, we need to run one last command. ```bash $ wp core install --url=wpclidemo.dev --title="WP-CLI" --admin_user=wpcli --admin_password=wpcli --admin_email=info@wp-cli.org Success: WordPress installed successfully. ``` -------------------------------- ### Get site upload filetypes Source: https://github.com/wp-cli/handbook/blob/main/commands/site/option/get.md This example shows how to retrieve the 'upload_filetypes' option for a site. ```bash $ wp site option get upload_filetypes jpg jpeg png gif mov avi mpg ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-these-installed-and-active-plugins.md Installs and activates one or more plugins. ```gherkin Scenario: My example scenario Given a WP installation And these installed and active plugins: """ akismet wordpress-importer """ ``` -------------------------------- ### Get post ID by URL Source: https://github.com/wp-cli/handbook/blob/main/commands/post/url-to-id.md This example shows how to get the post ID for a given URL. ```bash $ wp post url-to-id https://example.com/?p=1 1 ``` -------------------------------- ### Scenario Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-a-php-built-in-web-server.md Example usage of the 'Given a PHP built-in web server' step. ```gherkin Scenario: My example scenario Given a WP installation And a PHP built-in web server ``` -------------------------------- ### Get pattern content only Source: https://github.com/wp-cli/handbook/blob/main/commands/block/synced-pattern/get.md This example demonstrates how to extract only the 'post_content' field of a synced pattern. ```bash $ wp block synced-pattern get 123 --field=post_content ``` -------------------------------- ### Activate plugin Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/activate.md This example shows how to activate a single plugin named 'hello'. ```bash $ wp plugin activate hello Plugin 'hello' activated. Success: Activated 1 of 1 plugins. ``` -------------------------------- ### Get as JSON Source: https://github.com/wp-cli/handbook/blob/main/commands/block/style/get.md This example demonstrates how to retrieve the block style details in JSON format. ```bash $ wp block style get core/button outline --format=json ``` -------------------------------- ### Get only the label. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/category/get.md This example shows how to retrieve only a specific field, the 'label', for the 'site' category. ```bash $ wp ability category get site --field=label Site ``` -------------------------------- ### Get category as JSON. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/category/get.md This example demonstrates how to fetch the category details in JSON format. ```bash $ wp ability category get site --format=json {"slug":"site","label":"Site","description":"...","meta":"{}"} ``` -------------------------------- ### Start the web server using the default settings Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-start-webserver.md Launches PHP's built-in web server using the default host (localhost) and port (8080). ```bash $ wp server PHP 7.2.24-0ubuntu0.18.04.4 Development Server started at Thu Jun 4 17:40:13 2020 Listening on http://localhost:8080 Document root is ../wpdemo.test Press Ctrl-C to quit. ``` -------------------------------- ### Get ability as JSON. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/get.md This example demonstrates how to fetch ability details and format the output as JSON. ```bash $ wp ability get core/get-site-info --format=json ``` -------------------------------- ### WP-CLI Help Command Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md Demonstrates how to use the built-in help command in WP-CLI to list all available commands. ```bash wp help ``` -------------------------------- ### Composer post-update-cmd script for WP-CLI (example for Vagrant) Source: https://github.com/wp-cli/handbook/blob/main/guides/installing.md Example script for updating WP-CLI, adapted for a Vagrant environment. ```json "scripts" : { "post-update-cmd" : [ "/bin/bash -c \"[[ -f /usr/local/bin/wp ]] || sudo ln -s /var/www/vendor/wp-cli/wp-cli/bin/wp /usr/bin/wp\"", "/bin/bash -c \"source /var/www/vendor/wp-cli/wp-cli/utils/wp-completion.bash\"", "/bin/bash -c \"[[ -f ~/.bash_profile ]] || touch ~/.bash_profile\"", "/bin/bash -c \"source ~/.bash_profile\"" ] } ``` -------------------------------- ### Example Commands Source: https://github.com/wp-cli/handbook/blob/main/contributions/philosophy.md Examples of WP-CLI commands for common WordPress operations and unique functionalities. ```bash wp theme activate wp user create wp cron event run wp search-replace wp scaffold child-theme ``` -------------------------------- ### Initialize the testing environment locally Source: https://github.com/wp-cli/handbook/blob/main/how-to/plugin-unit-tests.md Initializes the testing environment by installing a WordPress instance and the unit testing tools, then creates a database for running tests. The parameters configure the test database name, MySQL user, password, host, and WordPress version. ```bash bash bin/install-wp-tests.sh wordpress_test root "" localhost latest ``` -------------------------------- ### Get user meta Source: https://github.com/wp-cli/handbook/blob/main/commands/user/meta/get.md This example shows how to retrieve a user's meta field value. ```bash $ wp user meta get 123 bio Mary is an WordPress developer. ``` -------------------------------- ### Get multiple theme mods. Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/mod/get.md This example illustrates retrieving the values for multiple theme mods. ```bash $ wp theme mod get background_color header_textcolor +------------------+--------+ | key | value | +------------------+--------+ | background_color | dd3333 | | header_textcolor | | +------------------+--------+ ``` -------------------------------- ### Get the status of theme auto-updates Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/auto-updates/status.md This example shows how to get the auto-update status for a specific theme. ```bash $ wp theme auto-updates status twentysixteen +---------------+----------+ | name | status | +---------------+----------+ | twentysixteen | disabled | +---------------+----------+ ``` -------------------------------- ### Scenario Example Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/when-i-run-try-from.md Demonstrates how to use the 'When I run/try `command` from `path`' Behat step to execute commands in a subdirectory. ```gherkin Scenario: My example scenario When I run `wp core is-installed` Then STDOUT should be empty When I run `wp core is-installed` from 'foo/wp-content' Then STDOUT should be empty ``` -------------------------------- ### Get plugin details. Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/get.md This example shows how to retrieve detailed information about the 'bbpress' plugin in JSON format. ```bash $ wp plugin get bbpress --format=json {"name":"bbpress","title":"bbPress","author":"The bbPress Contributors","version":"2.6.9","description":"bbPress is forum software with a twist from the creators of WordPress.","status":"active"} ``` -------------------------------- ### Get help for `core download` subcommand Source: https://github.com/wp-cli/handbook/blob/main/commands/help.md This example shows how to get help for the `core download` subcommand in WP-CLI. ```bash wp help core download ``` -------------------------------- ### Scenario: My example scenario Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/when-i-run-try-the-previous-command-again.md Demonstrates how to use the 'When I run the previous command again' Behat step. ```gherkin Scenario: My example scenario When I run `wp site option update admin_user_id 1` Then STDOUT should contain: """ Success: Updated 'admin_user_id' site option. """ When I run the previous command again Then STDOUT should contain: """ Success: Value passed for 'admin_user_id' site option is unchanged. """ ``` -------------------------------- ### Usage Source: https://github.com/wp-cli/handbook/blob/main/behat-steps/given-wp-config-php.md Example of using the 'Given wp-config.php' Behat step. ```gherkin Scenario: My example scenario Given an empty directory And WP files And wp-config.php ``` -------------------------------- ### Get details of a specific category. Source: https://github.com/wp-cli/handbook/blob/main/commands/ability/category/get.md This example shows how to retrieve all details for the 'site' ability category. ```bash $ wp ability category get site +-------------+-----------------------------------------------------+ | Field | Value | +-------------+-----------------------------------------------------+ | slug | site | | label | Site | | description | Abilities that retrieve or modify site information. | | meta | {} | +-------------+-----------------------------------------------------+ ``` -------------------------------- ### Download WordPress Source: https://github.com/wp-cli/handbook/blob/main/how-to/how-to-install.md The syntax of the command to download WordPress is the following: `wp core download [--path=] [--locale=] [--version=] [--skip-content] [--force]` ```bash $ wp core download --path=wpdemo.test --locale=it_IT Creating directory '/wpdemo.test/'. Downloading WordPress 5.4.1 (it_IT)... md5 hash verified: 3fa03967b47cdfbf263462d451cdcdb8 Success: WordPress downloaded. ``` -------------------------------- ### Debug Flag Example Source: https://github.com/wp-cli/handbook/blob/main/contributions/bug-reports.md Example of using the --debug flag with a WP-CLI command to get more verbose output. ```bash wp post list --debug ``` -------------------------------- ### Example Usage Source: https://github.com/wp-cli/handbook/blob/main/internal-api/wp-cli-runcommand.md Demonstrates how to use WP_CLI::runcommand() with various options to list plugins and parse the output as JSON. ```php $options = array( 'return' => true, // Return 'STDOUT'; use 'all' for full object. 'parse' => 'json', // Parse captured STDOUT to JSON array. 'launch' => false, // Reuse the current process. 'exit_error' => true, // Halt script execution on error. 'command_args' => [ '--skip-themes' ], // Additional arguments to be passed to the $command. ); $plugins = WP_CLI::runcommand( 'plugin list --format=json', $options ); ``` -------------------------------- ### List signup IDs. Source: https://github.com/wp-cli/handbook/blob/main/commands/user/signup/list.md This example shows how to list only the signup IDs. ```bash $ wp user signup list --field=signup_id 1 ``` -------------------------------- ### Verify the checksums of all installed plugins Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/verify-checksums.md This example demonstrates how to verify the checksums of all installed plugins using the `--all` flag. ```bash $ wp plugin verify-checksums --all Success: Verified 8 of 8 plugins. ``` -------------------------------- ### Get value of a single theme mod. Source: https://github.com/wp-cli/handbook/blob/main/commands/theme/mod/get.md This example shows how to extract only the value of a specific theme mod. ```bash $ wp theme mod get background_color --field=value dd3333 ``` -------------------------------- ### Basic Terminal Navigation Commands Source: https://github.com/wp-cli/handbook/blob/main/guides/beginners-guide.md A table outlining essential commands for navigating the terminal. ```markdown | Command | What it does | |---------|-------------| | `pwd` | Shows the folder you are currently in | | `ls` (macOS/Linux) or `dir` (Windows) | Lists files and folders in the current folder | | `cd folder-name` | Moves into a folder named `folder-name` | | `cd ..` | Goes up one folder level | | `clear` | Clears the terminal screen | ``` -------------------------------- ### Get the path to the plugins directory Source: https://github.com/wp-cli/handbook/blob/main/commands/plugin/path.md This example demonstrates how to get the path to the plugins directory and then change the current directory to it. ```bash $ cd $(wp plugin path) && pwd /var/www/wordpress/wp-content/plugins ``` -------------------------------- ### Get the table_prefix as defined in wp-config.php file. Source: https://github.com/wp-cli/handbook/blob/main/commands/config/get.md This example demonstrates how to retrieve the value of the 'table_prefix' constant from the wp-config.php file. ```bash $ wp config get table_prefix wp_ ``` -------------------------------- ### Create a site with a slug Source: https://github.com/wp-cli/handbook/blob/main/commands/site/create.md Example of creating a new site with a specified slug. ```bash $ wp site create --slug=example Success: Site 3 created: http://www.example.com/example/ ```