Cloud Service >> Knowledgebase >> WordPress >> Common Commands Used To Update WordPress Using WP-CLI
submit query

Cut Hosting Costs! Submit Query Today!

Common Commands Used To Update WordPress Using WP-CLI

WP-CLI is a command line interface for WordPress, a platform using which the WordPress site can be handled by using commands. This can be way faster and more convenient than using the WordPress admin dashboard for example if it’s used frequently for repetitive tasks or across multiple sites. Another function you can carry out by using WP-CLI is upgrading your WordPress environment, the core application, plugins, and themes. Below are the frequently used commands that apply WP-CLI for updating WordPress.

1. Updating WordPress Core

WordPress core should always be updated to enhance the safety, efficiency and to get access to the new features. To update the WordPress core to the latest version, use the following command:

wp core update

If you need to update to a specific version, you can specify it:If you need to update to a specific version, you can specify it:

wp core update --version=5.8.1

 

The next thing to check after updating the core is the databases to make sure that they current. WordPress undergoes several changes on the database structure, and these changes need to be implemented to ensure normal functioning of Your site. Use the following command to update the database:

wp core update-db

 

2. Updating Plugins

Plugins are essential in every WordPress site since they add more functions and capabilities to the site. To ensure the systems’ security and compatibility, these are important for keeping them updated. To update all installed plugins to their latest versions, use:

wp plugin update --all

 

If you want to update a specific plugin, you can specify the plugin slug (the unique identifier for a plugin):

wp plugin update plugin-slug

 

3. Updating Themes

Thinking is used to maintain the overall appearance and design of the WordPress site. Similar to plugins, it is also crucial to always update the themes for security and to ensure compatibility. To update all installed themes to their latest versions,use:

wp theme update --all

 

To update a specific theme, specify the theme slug:

 

wp theme update theme-slug

 

4. Checking Versions and Available Updates

In this check version and available update option there are so many sub-options available to us such as fileType, Fields, versions etc.

Prior to updating you can see the current versions of your WordPress core, plugins and themes and also check for any updates.

To check the current version of WordPress installed:

wp core version

To see if there are any updates available for plugins:To see if there are any updates available for plugins:

wp plugin list --update=available










To see if there are any updates available for themes:

 

wp theme list --update=available

 

5. Installing Plugins and Themes

New plugins and themes can also easily be installed through WP-CLI. To install a new plugin, use:

wp plugin install plugin-slug

 

If you want to activate the plugin after installation, add the --activate flag:

wp plugin install plugin-slug --activate

 

To install a new theme, use:

wp theme install theme-slug

 

If you want to activate the theme after installation, add the --activate flag:

wp theme install theme-slug --activate

 

6. Backing Up Your Database

It should be noted that prior to performing any updates, it will be a sound strategy to back up the database. This way you are assured that in the event that things go wrong as you update your site, you can revert to the original position. Use the following command to export your database:

wp db export backup.sql

 

This command will create a file with the name backup. db file in your current directory that includes all the data of your database.

7. Enabling and Disabling Maintenance Mode

While updating, especially during core updates, it is always best practice to set your website to maintenance mode to prevent users to see an incomplete or errored update. To enable maintenance mode, use:

wp maintenance-mode activate

Once the updates are completed, you can deactivate maintenance mode with:

wp maintenance-mode deactivate

 

8. Automating Updates

In case an administrator maintains several WordPress sites or a developer in need of simplifying his process, this automation through WP-CLI does take lots of time. As you may have noted, there are WP-CLI commands that the above process entails; you can develop scripts containing such commands and then schedule the scripts to run at fixed times through the cron jobs for Unix-based systems or Task Scheduler for Windows.

For example, a simple shell script to update WordPress core, plugins, and themes might look like this:

#!/bin/bash

 

# Navigate to the WordPress installation directory

cd /path/to/wordpress

 

# Backup the database

wp db export backup.sql

 

# Enable maintenance mode

wp maintenance-mode activate

 

# Update WordPress core

wp core update

wp core update-db

 

# Update all plugins and themes

wp plugin update --all

wp theme update --all

 

# Disable maintenance mode

wp maintenance-mode deactivate

 

It can then be set up to run at a later interval so your site always has the update it needs.

Conclusion

WP-CLI is pretty useful when it comes to the management of multiple installations of WordPress and updating of the WordPress core, plugins and themes in this list. All these can be conveniently carried out using WP-CLI commands and the process minimally takes much time, carried out effectively with minimal error rates as compared to when updates are done manually from the admin dashboard. WP-CLI would help you to have control, update, and security of your WordPress site since it will enable you to manage every aspect of your WordPress site remotely. If you are in the administration of only one site or many sites, then adopting the WP-CLI in your administration procedures will be very helpful and time-saving.

 

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!