How can I use WP-CLI to control LWSOptimize?

Procédure

The WP-CLI is a tool available from a Terminal that allows you to manage your WordPress site simply, without having to connect to your site. It is available free of charge on all the shared hosting packages offered by LWS and is very easy to use: even a novice can use it. Install plugins, update your site, manage multiple sites... All these actions are available with just a few commands.

Since version 3.3, LWS Optimize, the all-in-one plugin developed by LWS for caching pages, optimising images and lazy-loading elements on your WordPress site, has offered a range of commands using the WP-CLI for quick and easy control of the plugin's various functions.

How do I install the LWSOptimize WP-CLI?

Good news! If you already have version 3.3 or later of LWS Optimize installed on your site, then you already have access to the CLI commands. If you don't already have the LWS Optimize plugin, follow our documentation to learn how to install and configure it.

If the plugin installed on your site is not up to date, which you can check by going to "Extensions" from your WordPress dashboard, simply click on "update now" to proceed with the update.

What can WP-CLI do?

At present, the CLI is able to perform various actions on 7 different elements:

  • The file cache
  • Cache preloading
  • Memcached cache
  • Automatic purging
  • The server/dynamic cache
  • Plugin configuration and status
  • PageSpeed tests

All LWSOptimize commands start in the same way: "wp lwsoptimize" followed by the element to be modified and then the action to be performed. For example: "wp lwsoptimize filecache deactivate" will deactivate the file cache on the target site. Some commands, particularly those returning data, accept the --format=json (or --json) argument, which returns the result of the command in JSON format, useful for integrating WP-CLI into your code.

File caching

To manage the state of the cache, you can use the command :

wp lwsoptimize filecache activate|deactivate

Where activate activates the cache and deactivate deactivates it. If the cache is already in the selected state, you will be warned that no further action has been taken.

How can I use WP-CLI to control LWSOptimize?

You can also display a summary of the state of the cache, its status, using the command :

wp lwsoptimize filecache status [--json]

Depending on whether you add --json or not, the return will be displayed differently. In all cases, you will find the same information: the state of the cache and its contents at the time the command is run.

How can I use WP-CLI to control LWSOptimize?

Finally, and quite logically, there is a command that allows you to delete the entire file cache immediately:

wp lwsoptimize filecache clear

How can I use WP-CLI to control LWSOptimize?

Preloading the cache

In a similar way to the file cache, you can manage the state of the preload using the command :

wp lwsoptimize preload activate|deactivate [number]

The parameter activate enables it, while deactivate disables it. When you activate preloading, you can specify a number (between 1 and 30) of pages to be preloaded each time the cron is run. If no value is entered or if it is invalid, 3 pages will be preloaded by default.

How can I use WP-CLI to control LWSOptimize?

If you did not specify the number of pages to be preloaded when you activated preloading, or if you wish to change it, you can use the following command to change this value:

wp lwsoptimize preload change_amount {number}

How can I use WP-CLI to control LWSOptimize?

To monitor the progress of preloading, use the command :

wp lwsoptimize preload status [--json]

As with the file cache, depending on whether you add --json or not, the result will be returned differently. In any case, you will get the status of the cache and its preloading, as well as the number of pages to be processed and the next cron occurrence.

How can I use WP-CLI to control LWSOptimize?

If you only want to retrieve the next cron occurrence, you can also use the following command:

wp lwsoptimize preload next [--json]

How can I use WP-CLI to control LWSOptimize?

Memcached

To check the status of the Memcached service, use the command :

wp lwsoptimize memcached status [--json]

How can I use WP-CLI to control LWSOptimize?

In addition to the operating status of Memcached, if the Memcached module is disabled (as may be the case on cPanel), this will be indicated and if Redis is already active, you will be informed, due to the incompatibility between the 2.

The only other option available for Memcached is to manage the state of the module, using this command :

wp lwsoptimize memcached activate|deactivate

How can I use WP-CLI to control LWSOptimize?

The activate parameter activates the module, while deactivate deactivates it.

Automatic purge

To check the status of the automatic purge, use the command :

wp lwsoptimize autopurge status [--json]

How can I use WP-CLI to control LWSOptimize?

You can also activate or deactivate autopurge, making your site completely static, with the command: wp lwsoptimize autopurge status [--json]:

wp lwsoptimize autopurge activate|deactivate

How can I use WP-CLI to control LWSOptimize?

The activate parameter activates autopurge, while deactivate deactivates it.

Server cache (LWSCache)

The only action that can be taken on the file cache from the WP-CLI is to clear the cache, using the command :

wp lwsoptimize servercache clear

How can I use WP-CLI to control LWSOptimize?

General configuration

This category allows you to manage the LwsOptimize plugin directly, such as its status, using the command :

wp lwsoptimize configuration activate|deactivate {seconds}

The activate parameter activates the plugin, while deactivate deactivates it. The {seconds} parameter is used when deactivating, to choose how long the plugin should remain deactivated: 300s, 1800s, 3600s, 86400s. By default, if no argument is passed, the plugin is deactivated for 300 seconds.

How can I use WP-CLI to control LWSOptimize?

It is also possible to change the plugin configuration between the 3 predefined configurations: basic, advanced and complete, which correspond to those available in the plugin options, using the command :

wp lwsoptimize configuration basic|advanced|complete

How can I use WP-CLI to control LWSOptimize?

PageSpeed

PageSpeed, Google's service for testing the speed and performance of your website, is available directly from LWSOptimize and in WP-CLI with the command :

wp lwsoptimize pagespeed

How can I use WP-CLI to control LWSOptimize?

You will then get the main results (score and loading speed) returned by PageSpeed for the PC and Mobile versions of your site. By adding --json, you will receive a machine-readable version of this information:

How can I use WP-CLI to control LWSOptimize?

Conclusion

You now know how to :

  • Install and configure the WP-CLI for LWS Optimize,
  • Use WP-CLI commands to manage the file cache, cache preloading and the Memcached cache,
  • Enable or disable automatic purging and server caching,
  • Modify the configuration of the LWS Optimize plugin, and
  • Perform PageSpeed tests directly via the terminal.

🚀 Thanks to this powerful tool, you can now optimise your WordPress site quickly and efficiently, with just a few commands! 🛠️

Many thanks for reading! 🙏 Don't hesitate to share your experiences or ask your questions by leaving a comment below. Your feedback is invaluable in helping us improve our services. 💬

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

0mn reading

How can I minimize the files on my WordPress site with LWS Optimize?

0mn reading

How can I combine the files on my WordPress site with LWS Optimize?

0mn reading

How do I preload CSS files on my WordPress site with LWS Optimize?

0mn reading

How do I disable WordPress emojis with LWS Optimize?


Ask the LWS team and its community a question