### Install a plugin with WP-CLI Source: https://make.wordpress.org/cli/handbook/guides/quick-start Demonstrates how to install 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. ``` -------------------------------- ### Download and install WordPress Source: https://make.wordpress.org/cli/handbook/guides/quick-start Steps to download, create wp-config.php, create the database, 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. ``` -------------------------------- ### Complete installation example with verification Source: https://make.wordpress.org/cli/handbook/guides/verifying-downloads This example demonstrates the complete process of downloading, verifying, and installing WP-CLI, including GPG signature verification and making the executable available in the system's PATH. ```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 ``` -------------------------------- ### Installing a package Source: https://make.wordpress.org/cli/handbook/bug-reports Example of installing the 'scaffold-package-command' package. ```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. ``` -------------------------------- ### Usage Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-wp-installation-with-composer Example of how to use the 'Given a WP installation with Composer' Behat step in a scenario. ```gherkin Scenario: My example scenario Given a WP installation with Composer ... Scenario: My other scenario Given a WP installation with Composer ... ``` -------------------------------- ### Usage Source: https://make.wordpress.org/cli/handbook/references/behat-steps/given-a-wp-installation-in-subdir 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' ... ``` -------------------------------- ### Usage Source: https://make.wordpress.org/cli/handbook/references/behat-steps/given-a-wp-installation-in Examples of how to use the Behat step to install WordPress in a given directory. ```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' ... ``` -------------------------------- ### Usage Examples Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-wp-installation Demonstrates how to use the Given /^a WP( \d[^\s]+)? install(?:ation)?$/ Behat step in various 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 ... ``` -------------------------------- ### Get Help on Specific Command Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Examples of how to get help on a specific WP-CLI command, such as 'plugin'. ```bash wp help plugin wp help plugin install ``` -------------------------------- ### Navigate to WordPress Directory Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Example command to navigate to your WordPress installation directory in the terminal. ```bash cd /var/www/mysite ``` -------------------------------- ### Usage Examples Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-wp-installation-in Demonstrates various ways to use the Given /^a WP( [^\s]+)? install(?:ation)? in [‘"]?([^’"]+)[‘"]?$/ Behat step. ```gherkin Scenario: My example scenario Given a WP installation in 'foo' ... ``` ```gherkin Scenario: My other scenario Given a WP install in 'bar' ... ``` ```gherkin Scenario: My version-specific scenario Given a WP 6.4.2 installation in 'subdir' ... ``` -------------------------------- ### Scenario with installed and active plugins Source: https://make.wordpress.org/cli/handbook/behat-steps/given-these-installed-and-active-plugins This is an example of how to use the 'Given these installed and active plugins:' Behat step to install and activate specific plugins. ```gherkin Scenario: My example scenario Given a WP installation And these installed and active plugins: """ akismet wordpress-importer """ ``` -------------------------------- ### Synopsis for wp plugin install Source: https://make.wordpress.org/cli/handbook/commands-cookbook This example shows the synopsis for the 'wp plugin install' command, illustrating positional and associative arguments. ```bash $ wp plugin install usage: wp plugin install ... [--version=] [--force] [--activate] [--activate-network] ``` -------------------------------- ### Install a package Source: https://make.wordpress.org/cli/handbook/contributions/bug-reports Example of installing the scaffold-package-command package. ```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. ``` -------------------------------- ### Example Commands Source: https://make.wordpress.org/cli/handbook/contributions/philosophy Examples of WP-CLI commands for managing WordPress. ```bash wp theme activate wp user create wp cron event run wp search-replace wp scaffold child-theme ``` -------------------------------- ### Skipping Plugins and Themes Source: https://make.wordpress.org/cli/handbook/guides/troubleshooting Examples of how to skip specific plugins or all plugins and themes with WP-CLI. ```bash wp --skip-plugins --skip-themes ``` ```bash wp --skip-plugins=akismet ``` -------------------------------- ### Running WP-CLI Commands Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Example of navigating to a WordPress folder and running the 'wp plugin list' command. ```bash cd /var/www/mysite wp plugin list ``` -------------------------------- ### Installing a WP-CLI Package from a ZIP File Source: https://make.wordpress.org/cli/handbook/commands-cookbook An example of how to install a WP-CLI package from a local ZIP file. ```bash # Installing the package using a ZIP file $ wp package install ~/Downloads/server-command-main.zip ``` -------------------------------- ### Install WordPress Source: https://make.wordpress.org/cli/handbook/how-to/how-to-install Command to perform the final WordPress installation with specified URL, title, and admin credentials. ```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 Examples Source: https://make.wordpress.org/cli/handbook/behat-steps/when-i-run-try Demonstrates the difference between 'run' and 'try' with example scenarios. ```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 ``` -------------------------------- ### Automate WP-CLI setup with composer scripts (bash, alternative) Source: https://make.wordpress.org/cli/handbook/guides/installing An alternative configuration for composer.json scripts to automate WP-CLI setup, suitable for different environments or update commands. ```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\"" ] } ``` -------------------------------- ### Automate WP-CLI setup with composer scripts (bash) Source: https://make.wordpress.org/cli/handbook/guides/installing Configure composer.json scripts to automate setting up the WP-CLI command and bash completion after installation. ```json "scripts" : { "post-install-cmd" : [ "[[ -f /usr/bin/wp ]] || sudo ln -s /var/www/vendor/wp-cli/wp-cli/bin/wp /usr/bin/wp", "source /var/www/vendor/wp-cli/wp-cli/utils/wp-completion.bash", "[[ -f ~/.bash_profile ]] || touch ~/.bash_profile", "source ~/.bash_profile" ] } ``` -------------------------------- ### Start the web server using default settings Source: https://make.wordpress.org/cli/handbook/how-to/how-to-start-webserver Launches PHP's built-in web server using the default host (localhost) and port (8080). The output shows the server starting and the listening address. ```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. ``` -------------------------------- ### List Plugins Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Command to list all installed plugins on your WordPress site. ```bash wp plugin list ``` -------------------------------- ### Example Source: https://make.wordpress.org/cli/handbook/internal-api/wp-cli-run-command Example of using WP_CLI::run_command() to capture output. ```php ob_start(); WP_CLI::run_command( array( 'cli', 'cmd-dump' ) ); $ret = ob_get_clean(); ``` -------------------------------- ### Installing a WP-CLI Package from a Git Repository Source: https://make.wordpress.org/cli/handbook/commands-cookbook Examples of how to install a WP-CLI package from a Git repository using either an HTTPS or an SSH link. ```bash # Installing the package using an HTTPS link $ wp package install https://github.com/wp-cli/server-command.git ``` ```bash # Installing the package using an SSH link $ wp package install git@github.com:wp-cli/server-command.git ``` -------------------------------- ### Scenario Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-database An example of how to use the 'Given a database' Behat step in a scenario. ```gherkin Scenario: My example scenario Given a database ... ``` -------------------------------- ### Display WP-CLI Info Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Command to display information about your WP-CLI installation. ```bash wp --info ``` -------------------------------- ### Example of steps to reproduce a bug Source: https://make.wordpress.org/cli/handbook/bug-reports This snippet shows the exact commands to run to reproduce a specific bug related to package installation. ```bash wp package install wp-cli/scaffold-package-command:@stable Allow installation process to complete ‘Success: Package installed.’ is displayed wp help scaffold package Observe ‘Error: ‘scaffold package’ is not a registered wp command.’ ``` -------------------------------- ### Start the web server using custom settings Source: https://make.wordpress.org/cli/handbook/how-to/how-to-start-webserver Starts the web server and specifies a custom port (9090) and host (192.168.0.4) using the `--port` and `--host` flags. ```bash $ wp server --port=9090 --host=192.168.0.4 ``` -------------------------------- ### Add a user as a super-admin Source: https://make.wordpress.org/cli/handbook/guides/quick-start Command to grant super admin capabilities to an existing user on a multisite installation. ```bash $ wp super-admin add wpcli Success: Granted super-admin capabilities. ``` -------------------------------- ### My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/given-an-empty-cache An example scenario demonstrating the usage of the 'Given an empty cache' Behat step. ```gherkin Scenario: My example scenario Given an empty cache ... ``` -------------------------------- ### Example Usage Source: https://make.wordpress.org/cli/handbook/internal-api/wp-cli-get-config Example of how to retrieve the '--url=' configuration parameter. ```php WP_CLI::log( 'The --url= value is: ' . WP_CLI::get_config( 'url' ) ); ``` -------------------------------- ### SSH into Remote Server Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Example command to SSH into a remote server where WordPress is hosted. ```bash ssh username@yoursite.com ``` -------------------------------- ### Install and activate a plugin in one step Source: https://make.wordpress.org/cli/handbook/guides/common-tasks Installs and activates a plugin in a single command. ```bash wp plugin install contact-form-7 --activate ``` -------------------------------- ### Examples of Argument Syntax Source: https://make.wordpress.org/cli/handbook/references/argument-syntax 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 ``` -------------------------------- ### List all installed themes Source: https://make.wordpress.org/cli/handbook/guides/common-tasks Lists all installed themes. ```bash wp theme list ``` -------------------------------- ### Scenario: My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/given-wp-config-php Example Behat scenario demonstrating the usage of the 'Given wp-config.php' step. ```gherkin Scenario: My example scenario Given an empty directory And WP files And wp-config.php ``` -------------------------------- ### Install a package by name, Git URL, local directory, or .zip file Source: https://make.wordpress.org/cli/handbook/guides/installing-packages Demonstrates various ways to install a WP-CLI package using the `wp package install` command. ```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 ``` -------------------------------- ### Install a plugin Source: https://make.wordpress.org/cli/handbook/guides/common-tasks Installs a plugin from the WordPress.org repository. ```bash wp plugin install contact-form-7 ``` -------------------------------- ### Install a theme Source: https://make.wordpress.org/cli/handbook/guides/common-tasks Installs a theme from the WordPress.org theme repository. ```bash wp theme install twentytwentyfour ``` -------------------------------- ### Example Usage Source: https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-make-progress-bar Example of using make_progress_bar to generate users and display progress. ```php # `wp user generate` ticks progress bar each time a new user is created. # # $ wp user generate --count=500 # Generating users 22 % [=======> ] 0:05 / 0:23 $progress = \WP_CLI\Utils\make_progress_bar( 'Generating users', $count ); for ( $i = 0; $i < $count; $i++ ) { // uses wp_insert_user() to insert the user $progress->tick(); } $progress->finish(); ``` -------------------------------- ### Scenario: My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/when-i-launch-in-the-background Example of how to use the 'When /^I launch in the background `([^`]+)`$/' Behat step. ```gherkin Scenario: My example scenario Given a WP install And I launch in the background `wp server --host=localhost --port=8181` ... ``` -------------------------------- ### Example Usage Source: https://make.wordpress.org/cli/handbook/internal-api/wp-cli-success Example of using WP_CLI::success() after flushing rewrite rules. ```php # wp rewrite flush expects 'rewrite_rules' option to be set after flush. flush_rewrite_rules( WP_CLI\Utils\get_flag_value( $assoc_args, 'hard' ) ); if ( ! get_option( 'rewrite_rules' ) ) { WP_CLI::warning( "Rewrite rules are empty." ); } else { WP_CLI::success( 'Rewrite rules flushed.' ); } ``` -------------------------------- ### Get WordPress Version Source: https://make.wordpress.org/cli/handbook/guides/beginners-guide Command to display the version of WordPress installed on your site. ```bash wp core version ``` -------------------------------- ### Scenario Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-an-empty-non-existent-directory An example of how to use the Behat step in a scenario. ```gherkin Scenario: My example scenario Given an empty foo-plugin directory And a non-existent bar-plugin directory ... ``` -------------------------------- ### Example Usage Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-wp-multisite-subdirectory-subdomaininstall-installation Demonstrates how to use the Behat step in scenarios. ```gherkin Scenario: My example scenario Given a WP multisite subdomain installation ... Scenario: My other scenario Given a WP subdirectory install ... ``` -------------------------------- ### Install wp profile command Source: https://make.wordpress.org/cli/handbook/figure-out-why-wordpress-is-slow Installs the `wp profile` package, which is necessary for profiling WordPress performance. ```bash $ wp package install wp-cli/profile-command ``` -------------------------------- ### Example custom step definition Source: https://make.wordpress.org/cli/handbook/guides/behat-tests An example of a custom step definition written in PHP. ```php /** * @Given a custom configuration file */ public function aCustomConfigurationFile() { $config = <<proc( "echo '{$config}' > wp-cli.yml" )->run_check(); } ``` -------------------------------- ### Scenario: My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/given-download This is an example of how to use the 'download:' Behat step to download multiple files into specified destinations. ```gherkin Scenario: My example scenario Given download: | path | url | | {CACHE_DIR}/foo.jpg | https://example.com/foo.jpg | | {CACHE_DIR}/bar.png | https://example.com/another-image.png | ``` -------------------------------- ### Running a custom command remotely after installation Source: https://make.wordpress.org/cli/handbook/guides/running-commands-remotely Example of successfully running a custom command on a remote machine after it has been installed. ```bash # Now we can run the command remotely, even though it is not installed locally $ wp @dev db ack test_email@example.com wp_users:user_email 9:test_email@example.com ``` -------------------------------- ### Scenario: My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/given-save-the-file-as This is an example scenario demonstrating the usage of the step. ```gherkin Scenario: My example scenario Given a WP installation with Composer And save the {RUN_DIR}/composer.json file as {COMPOSER_JSON} ``` -------------------------------- ### Background Sections Example Source: https://make.wordpress.org/cli/handbook/guides/behat-tests An example of using the `Background:` keyword in Behat to define common setup steps that run before each scenario in a feature. ```gherkin Feature: Post management Background: Given a WP install And I run `wp post create --post_title='Test'` Scenario: Update post title When I run `wp post update 1 --post_title='Updated'` Then STDOUT should contain: """ Success """ Scenario: Delete post When I run `wp post delete 1` Then STDOUT should contain: """ Success """ ``` -------------------------------- ### Scenario Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-php-built-in-web-server-to-serve-subdir An example of how to use the 'Given a PHP built-in web server to serve' step in a Behat scenario. ```gherkin Scenario: My example scenario Given a WP installation And a PHP built-in web server to serve 'WordPress' ``` -------------------------------- ### Create the database Source: https://make.wordpress.org/cli/handbook/how-to/how-to-install Command to create the database based on the credentials in wp-config.php. ```bash $ wp db create Success: Database created. ``` -------------------------------- ### Usage Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-wp-installation-with-composer-and-a-custom-vendor-directory-vendor-directory Example scenarios demonstrating the usage of the 'Given a WP installation with Composer and a custom vendor directory' 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' ... ``` -------------------------------- ### Download WordPress Source: https://make.wordpress.org/cli/handbook/how-to/how-to-install Command to download WordPress to a specified path and locale. ```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. ``` -------------------------------- ### Include WP-CLI Docker image Source: https://make.wordpress.org/cli/handbook/guides/installing Example of how to include the WP-CLI Docker image in your project's Docker configuration. ```yaml image: wordpress:cli ``` -------------------------------- ### Scenario: My example scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/when-i-run-try-from Demonstrates running a command in the current directory and 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 ``` -------------------------------- ### Start wp-cli with ABSPATH in the current dir and under the current dir's owner Source: https://make.wordpress.org/cli/handbook/references/shell-friends This bash script defines a function 'wp_install' that allows you to start WP-CLI with the ABSPATH set to the current directory and run commands under the ownership of the current directory's owner. This is useful for setting up WordPress installations. ```bash #!/bin/bash sudo -u $(stat . -c %U) -- wp --path="$PWD" "$@" ``` -------------------------------- ### Alias Configuration Example Source: https://make.wordpress.org/cli/handbook/config Defines aliases for different WordPress installations, including SSH details, user, and path. It also shows how to group aliases and reference other aliases. ```yaml @staging: ssh: wpcli@staging.wp-cli.org user: wpcli path: /srv/www/staging.wp-cli.org @production: ssh: wpcli@wp-cli.org:2222 user: wpcli path: /srv/www/wp-cli.org @both: - @staging - @production _: merge: true inherit: prod.yml ``` -------------------------------- ### Example Scenario Source: https://make.wordpress.org/cli/handbook/behat-steps/given-wp-files An example of how to use the 'Given WP files' Behat step within a scenario. ```gherkin Scenario: My example scenario Given an empty directory And WP files ``` -------------------------------- ### Usage Example Source: https://make.wordpress.org/cli/handbook/behat-steps/then-the-file-directory-should-strictly-exist-not-exist-be-contain-not-contain Example of how to use the Behat step in a scenario. ```gherkin Scenario: My example scenario When I run `wp core download` Then the wp-settings.php file should exist And the wp-content directory should exist And the {RUN_DIR} directory should contain: """ index.php license.txt """ And the wp-config.php file should contain: """ That's all, stop editing! Happy publishing. """ ``` -------------------------------- ### Delete all pages using command substitution Source: https://make.wordpress.org/cli/handbook/references/shell-friends Example of combining 'wp post list' to get page IDs and 'wp post delete' using command substitution ($()). ```bash $ wp post list --post_type='page' --format=ids 1164 1186 ``` ```bash $ wp post delete $(wp post list --post_type='page' --format=ids) Success: Trashed post 1164. Success: Trashed post 1186. ``` -------------------------------- ### Install on CentOS Source: https://make.wordpress.org/cli/handbook/guides/installing Command to install WP-CLI using yum on CentOS. ```bash su -c 'yum install wp-cli' ``` -------------------------------- ### Usage Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-downloaded-phar-with-the-same-version-version Demonstrates how to use 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 on Fedora 30+ Source: https://make.wordpress.org/cli/handbook/guides/installing Command to install WP-CLI using dnf on Fedora. ```bash su -c 'dnf install wp-cli' ``` -------------------------------- ### Install WP-CLI via Homebrew Source: https://make.wordpress.org/cli/handbook/guides/installing Install WP-CLI using the Homebrew package manager. ```bash brew install wp-cli ``` -------------------------------- ### Activate a plugin with WP-CLI Source: https://make.wordpress.org/cli/handbook/guides/quick-start Shows how to activate a plugin using the 'wp plugin activate' command. ```bash $ wp plugin activate akismet Success: Plugin 'akismet' activated. ``` -------------------------------- ### Install and Configure WordPress with WP-CLI Source: https://make.wordpress.org/cli/handbook/references/shell-friends This bash function 'wp_install' automates the process of downloading WordPress, creating a database, configuring wp-config.php, and performing a core installation. It prompts the user for the database name and uses default credentials for user, password, and host. ```bash wp_install ( wp core download --path=$1; cd $1; read -p 'name the database:' dbname; wp config create --dbname=$dbname --dbuser=root --dbpass=awoods --dbhost=localhost; wp db create; wp core install --prompt ) ``` -------------------------------- ### Generate a config file Source: https://make.wordpress.org/cli/handbook/how-to/how-to-install Command to create the wp-config.php file with database credentials, prompting for the password. ```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. ``` -------------------------------- ### Update WP-CLI project installed via Composer Source: https://make.wordpress.org/cli/handbook/guides/installing Steps to update a WP-CLI project that was installed using Composer. ```bash cd wp-cli-bundle git pull origin main composer install ``` -------------------------------- ### Longdesc Example Source: https://make.wordpress.org/cli/handbook/commands-cookbook Example of a longdesc PHPDoc block defining options and examples for a WP-CLI command. ```php * ## OPTIONS * * * : The name of the person to greet. * * [--type=] * : Whether or not to greet the person with success or error. * --- * default: success * options: * - success * - error * --- * * ## EXAMPLES * * wp example hello Newman ``` -------------------------------- ### Install WP-CLI globally to a custom path Source: https://make.wordpress.org/cli/handbook/guides/installing Install WP-CLI globally to a specified custom path using Composer and then symlink the binary. ```bash composer create-project wp-cli/wp-cli-bundle /usr/share/wp-cli --no-dev ``` ```bash sudo ln -s /usr/share/wp-cli-bundle/vendor/wp-cli/wp-cli/bin /usr/bin/wp ``` -------------------------------- ### Initialize Testing Environment Locally Source: https://make.wordpress.org/cli/handbook/how-to/plugin-unit-tests This command initializes the testing environment locally by installing WordPress and the testing tools, and creating a database. 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 ``` -------------------------------- ### Install a package with version constraints Source: https://make.wordpress.org/cli/handbook/guides/installing-packages Shows how to specify version constraints when installing WP-CLI packages, using Composer's syntax. ```bash wp package install : ``` ```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 ``` -------------------------------- ### Example Command Labels Source: https://make.wordpress.org/cli/handbook/contributions/repository-management Provides examples of labels prefixed with 'command:' to indicate specific commands. ```text command:core ``` ```text command:cli-check-update ``` ```text command:post-meta-update ``` -------------------------------- ### Install WP-CLI globally via Composer Source: https://make.wordpress.org/cli/handbook/guides/installing Install WP-CLI globally using Composer, assuming the Composer vendor bin directory is in the system's PATH. ```bash composer global require wp-cli/wp-cli-bundle ``` -------------------------------- ### Scenario Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-a-php-built-in-web-server Example of using the 'Given a PHP built-in web server' step in a Behat scenario. ```gherkin Scenario: My example scenario Given a WP installation And a PHP built-in web server ``` -------------------------------- ### Example Package Name Source: https://make.wordpress.org/cli/handbook/contributions/repository-management Illustrates the naming convention for WP-CLI command repositories. ```text wp-cli/scaffold-package-command ``` -------------------------------- ### Check PHP Version Source: https://make.wordpress.org/cli/handbook/guides/installing Command to check the installed PHP version. ```bash php --version ``` -------------------------------- ### Scenario Example Source: https://make.wordpress.org/cli/handbook/behat-steps/given-an-empty-directory An example of how to use the 'Given an empty directory' Behat step within a scenario. ```gherkin Scenario: My example scenario Given an empty directory ... ```