[ad_1]
Do any of you use WP-CLI?
If so, what do you use it for?
Been looking at this list: [https://developer.wordpress.org/cli/commands/](https://developer.wordpress.org/cli/commands/)
It seems to me, that most everything it does can be done via the WP interface or by modifying wp-config, or writing some functions in your theme’s functions.php. \[which means we wouldn’t forget that there’s some script doing things via command line somewhere\] So, legitimately asking what are some real world use-cases to implement WP-CLI scripts?
Thanks for the input.
[ad_2]
Oh it can be helpful. Anything that runs for a long time is better done via cli.
Exporting/importing db? Check
Search and replace? Check
Managing plugins? Check. Especially if your site is down or under load
With the CLI I can update core to whichever version I want. In GUI I have “update” button with zero flexibility.
This is easier than editing wp-config.php to add a setting
wp config set WP_DEBUG –raw true
and this is easier to remove it
wp config delete WP_DEBUG
There’s lots of stuff like this.
Yes for updating wp-core, search and replacing during launch, updating plugins/themes, listing plugins/themes/users – checking for values in the db. etc.
While developing something that uses the wp-cron, the `wp cron event list` and `wp cron even run [hook]` make it so easy to validate scheduling and initiate testing.
>It seems to me, that most everything it does can be done via the WP interface or by…
This is substantially true but a little beside the point. You get several big benefits from using WP-CLI vs the interface
* your code runs generally more “out of process” than when running through the interface, so you may benefit from more available memory and much less risk of timeouts
* you can bundle/aggregate commands into scripts, which saves time vs. repeatedly going from screen to screen
* you can more easily run on-off commands more efficiently than by editing functions.php, visiting the site to execute functions.php, and then removing the snippet.
Also, as others have mentioned, there are tasks like reverting versions of core, plugins, and themes that take seconds with WP-CLI and take minutes or longer to do manually, even assuming you could do them directly via the interface at all.
I rarely use WP-CLI in large part because I can’t count on my clients having SSH enabled for their hosting accounts. But when I worked exclusively with Drupal I lived and breathed by their Drush command-line tool. WP-CLI still hasn’t caught up with Drush in terms of high-level commands but WP-CLI is still a very slick app.
I’ll just add that it might be particularly useful/practical on production development platforms where you’re likely to need to run the same utility and cleanup processes at different stages on each new site as you build them out.
The only command I regularly use is `wp shell`
In combination with psysh this can become a powerful debugging tool. Also whenever I am in doubt about exactly what a function returns, I call it via `wp shell` and then I can investigate the returned data structure very easily.
If you plan to use wp cli, there is a site which helped me in the beginning because it has loads of examples on how to use the commands, I still use it sometimes.
https://wp-kama.com/handbook/wp-cli/wp
You can manually click buttons, sure, but wp-cli allows you to script basically any function wp core or compatible plugins offer.
I have full CI/CD pipeline scripts. Migrations are automated. Staging sites a single command. Development backups are automated. Upgrades are secure, tested, stable before deploying to production.
There are infinite benefits if you use a little imagination.
I keep WP permissions hardened to the point where the auto update function does not work and instead use wp-cli to handle all updates.
With use of some flags like –skip-plugins –skip-themes you can disable plugins or switch theme that broke your wp instance.
Like mentioned in another comment – you can use it to run crons, setup new ones etc.
Import/export db, run php code, or maintain users without external plugins.
It’s basically doing WordPress stuff without the WordPress dashboard. You want to delete a specific post? You can either login, look for it (imagine a website has thousands of posts), and then delete, or you can do directly with 1 line of code. We use WP CLI for migrations. We basically have a custom command and we run it to set up configurations and everything in have a seconds. Otherwise, it would be a very tedious and long and boring task to do it manually which could lead to errors
Anything that needs to be done in batches, such as resetting passwords and emails without verification, searching the database, search-replace and clearing transients. It’s extremely powerful and extremely dangerous if you don’t know what you are doing. It does plenty that UI can’t.
Absolutely nuthin’! Say it again!