WP-CLI

WP-CLI is a command-line interface for managing WordPress sites. It allows you to perform various administrative tasks from the command line. Follow these steps to use WP-CLI:

Install WP-CLI

  • Download WP-CLI: Download the WP-CLI Phar file from the official website.
  • Make Executable: Make the Phar file executable by running chmod +x wp-cli.phar.
  • Move to PATH: Move the Phar file to a directory in your PATH, e.g., mv wp-cli.phar /usr/local/bin/wp.
  • Basic Commands

  • Check Version: Run wp --version to check the installed version of WP-CLI.
  • Update Core: Run wp core update to update WordPress core to the latest version.
  • Install Plugin: Run wp plugin install plugin-slug to install a plugin.
  • Activate Plugin: Run wp plugin activate plugin-slug to activate a plugin.
  • Update Plugin: Run wp plugin update plugin-slug to update a plugin.
  • Create User: Run wp user create username [email protected] --role=author to create a new user.
  • Manage Themes

  • Install Theme: Run wp theme install theme-slug to install a theme.
  • Activate Theme: Run wp theme activate theme-slug to activate a theme.
  • Update Theme: Run wp theme update theme-slug to update a theme.
  • Manage Posts

  • Create Post: Run wp post create --post_title="Post Title" --post_content="Post content." --post_status=publish to create a new post.
  • List Posts: Run wp post list to list all posts.
  • Delete Post: Run wp post delete post-id to delete a post.
  • Best Practices

    • Backup: Always backup your site before running WP-CLI commands that modify data.
    • Test Commands: Test WP-CLI commands on a staging site before running them on your live site.
    • Use Help: Use the wp help command to get help with WP-CLI commands and options.