Cms cheatsheet
WordPress WP-CLI 2 Cheatsheet
Install, configure, update and back up WordPress sites from the command line with WP-CLI 2.
Setup
- Check your WP-CLI setup — Show the WP-CLI, PHP and OS versions and where the config files are.
- Download WordPress — Download the latest WordPress files into the current folder.
- Create wp-config.php — Write wp-config.php with your database details. Use real credentials.
- Create the database — Create the database named in wp-config.php.
- Install WordPress — Run the installer: create tables, the first admin user and the site title.
- Check the WordPress version — Print the installed WordPress version.
- Start a local server — Serve the site with PHP's built-in web server for local development.
Plugins
- List plugins — Show installed plugins with their status and available updates.
- Install and activate a plugin — Download a plugin from WordPress.org and activate it.
- Activate a plugin — Activate an installed plugin.
- Deactivate a plugin — Turn a plugin off without deleting it. Useful when a plugin breaks the site.
- Deactivate every plugin — Turn off all plugins to find out which one causes a problem.
- Update all plugins — Update every plugin that has a newer version.
- Delete a plugin — Remove an inactive plugin's files.
Themes
- List themes — Show installed themes with their status.
- Install and activate a theme — Download a theme from WordPress.org and make it the active theme.
- Switch theme — Activate an installed theme.
- Update all themes — Update every theme that has a newer version.
Users
- List users — Show users with their roles.
- Create a user — Create an editor account. WP-CLI prints a generated password unless you pass --user_pass.
- Reset a user's password — Set a new password for the user with ID 1. Use a real password.
- Delete a user and keep their posts — Delete a user and reassign their content to user 1.
Content and options
- List posts — Show posts with their status.
- Create a post — Create and publish a post.
- Read a site option — Print the site URL stored in the options table.
- Change a site option — Change the site title stored in the options table.
- Fix permalinks — Regenerate rewrite rules, which fixes most pages that return 404 after a change.
- Clear the object cache — Flush the WordPress object cache.
- Delete transients — Delete all cached transient values.
- Run due scheduled tasks — Run all WP-Cron events that are due now.
- Turn on debug mode — Set WP_DEBUG to true in wp-config.php.
Database
- Back up the database — Write the whole database to a SQL file.
- Restore the database — Import a SQL file into the database.
- Preview a URL change — Show how many replacements a search and replace would make, without changing anything.
- Change a URL everywhere — Replace a URL across the database. It handles serialized data safely, unlike a plain SQL replace.
- Check the database — Run a check on the database tables.
- Optimize the database — Run optimize on the database tables.
- Empty the database — Delete all tables in the database.
Updates and maintenance
- Update WordPress — Update WordPress to the latest version.
- Run database updates — Run the database upgrade that some releases require.
- Check core files for tampering — Compare WordPress core files with the official checksums.
- Check plugin files — Compare plugins from WordPress.org with their official checksums.
- Turn on maintenance mode — Show the maintenance page to visitors while you work.
- Turn off maintenance mode — Put the site back online.
- Run PHP in WordPress — Run a PHP snippet with WordPress loaded.
- Open an interactive PHP shell — Start a shell with WordPress loaded for trying out functions.
- Generate a plugin skeleton — Create a plugin folder with the standard files.
- Update WP-CLI — Update WP-CLI itself to the latest release.
Related cheatsheets
- Drupal 11 cheatsheet — Create, configure, update and debug Drupal 11 sites with Composer and Drush.