AIによる回答
To remove converted originals or WebP copies using WP-CLI with EWWW IO, use the commands
ewwwio remove_converted_originalsandewwwio remove_webprespectively. These commands, when run from the command line with WP-CLI, will remove the specified files from your WordPress installation.Here’s a breakdown:
1. Removing Converted Originals:
- If you have used EWWW IO to convert images (e.g., PNG to JPG) and have not configured it to delete the originals, you can use the following command to remove the original files:
ソースコードphp wp-cli.phar ewwwio remove_converted_originalsThis command specifically targets and removes the original files that were converted by EWWW IO.
2. Removing WebP Copies:
- If you are using EWWW IO to generate WebP versions of your images and want to remove those, you can use this command:
ソースコードphp wp-cli.phar ewwwio remove_webpThis command will delete all the .webp files generated by the plugin from your local server.
Important Notes:
Backup:Before running any of these commands, it’s always a good idea to back up your website, especially the
wp-content/uploadsdirectory, to ensure you have a copy of your files in case something goes wrong. Location:Ensure you are in the correct directory (your WordPress installation’s root) when running these commands. Typically this is where your
wp-config.phpfile is located. WP-CLI:These commands rely on WP-CLI. Make sure you have WP-CLI installed and configured correctly before attempting to use them.
EWWW IO:These commands are specific to EWWW IO. If you are using a different plugin for image optimization, you’ll need to find the corresponding commands or methods for that plugin.
【参考】
Command line interface for WordPress | WP-CLI
実務で使える!WordPressのWP-CLIの使い方について徹底解説(コマンド解説付き) – UMENOKI|すぐに仕事で使えるIT技術情報メディア
【CLI】WordPressをコマンドラインから実行するWP-CLIを使ってみよう
Optimizing with WP-CLI – EWWW IO Support ↓左記サイトより
Optimizing with WP-CLI
WP-CLI usage
EWWW Image Optimizer features a WP-CLI extension that allows you to optimize your images “en masse”. Using WP-CLI has the added advantage that the command line has no time limits, and (normally) no memory limits. This makes it easy to just get things done. So how do we use it?
In some cases, you will need to install WP-CLI first, if your web host doesn’t provide it by default. When you download it, the file is usually named wp-cli.phar, and the most basic usage is to run it as-is:
php wp-cli.phar --infoHowever, if you have root access to your server, you can follow the wp-cli instructions to make the file executable, and to install it in your “path”. If you follow the instructions at wp-cli.org, this means you can run it by simply typing ‘wp –info’ at the command line, instead of using php, like we did above. If your webhost has it pre-installed, you will typically run it the same way:
wp --infoYou can literally name the wp-cli.phar file anything you want, like wapuu or ninjutsu. For our purposes, we’ll stick with the first example where we assume you have downloaded wp-cli.phar into the “root” of your WordPress folder. If your wp-cli binary is named something else, just substitute it throughout.
We will also assume that you are running wp-cli from your WordPress root folder, but you can use the –path option to tell wp-cli where your WordPress installation lives. This will output the WordPress core version:
php wp-cli.phar --path=/home/user/www/ core versionUsing EWWW IO via WP-CLI
Now that we are familiar with WP-CLI, let’s move on to the EWWW IO command. WP-CLI uses commands and sub-commands for various actions, and in our case ‘ewwwio’ is the command and ‘optimize’ is the sub-command. If we run it with no options, we’ll get some usage information:
php wp-cli-phar ewwwio optimize usage: wp ewwwio optimize <library> [<delay>] [--force] [--webp-only] [--reset] [--noprompt]That tells us that the <library> parameter is required, since EWWW IO can optimize the Media Library, theme folders, NextGEN, FlaGallery, etc. To find out more about these options, we can use the –help flag/option:
php wp-cli.phar ewwwio optimize --helpThis will display detailed usage information, and you can use the arrows to scroll, and ‘q’ to quit/exit from the help screen. So let’s break this down a bit more.
The first, required, parameter is the type of image that we want to optimize. We call this the library or ‘gallery’ parameter.
Valid values are ‘all’ which will optimize everything on your site, ‘media’ which will optimize everything that the normal bulk optimizer does: the Media Library, your theme folder, and anything configured in Folders to optimize. Using ‘nextgen’ will tell the plugin to process any Nextcellent or NextGEN 2.x galleries, and ‘flagallery’ will optimize all GRAND FlaGallery images.All the other parameters are optional, and if you look at the list above, you’ll note some of them have dashes, and some don’t. This indicates how you should type those parameters. The parameters without dashes must be in the exact order listed, whereas the others can follow after that in any order.
For example, to optimize the media library with a 5 second delay between images, you would do this:
php wp-cli.phar ewwwio optimize media 5The –force option is the same as the Force Re-optimize checkbox on the Bulk Optimizer. EWWW IO normally skips images it has optimized before, but the –force option tells it to re-optimize everything regardless of previous actions.
If you stop the WP-CLI process midway through, it will resume where it left off when you run it again. To make it start over with a fresh scan, use the –reset option. This is NOT the same as the –force option. The –force option will re-optimize everything, the –reset option simply tells the plugin to re-scan all your images.
Using cron on some webhosts, you can schedule WP-CLI commands to run at a certain time every hour, day, week, or month. Normally, EWWW IO will prompt you to continue after it has scanned your images. To avoid that, you need to use the –noprompt option, like so:
php wp-cli.phar ewwwio optimize media 5 --nopromptMore WP CLI Tools!
We have some handy tools under Tools->EWWW Image Optimizer, and most of these can also be run from the CLI.
Use this one to restore all images from the EWWW IO backups (cloud or local):
php wp-cli.phar ewwwio restoreWhen WordPress scales down an upload that was over 2560px wide, it keeps the original on disk. This tool lets you remove the originals, and keep only the “full size” 2560px version.
php wp-cli.phar ewwwio remove_originalsIf you run PNG to JPG or other conversion operations on your images and don’t have EWWW IO configured to delete the originals, you can use this tool to remove the pre-converted originals later on:
php wp-cli.phar ewwwio remove_converted_originalsYou might find that having WebP copies takes up too much disk space, or you might be using something like our Easy IO CDN that does WebP conversion & delivery without using up your disk space. You can use the WebP cleanup tool to remove all the .webp copies from your local server:
php wp-cli.phar ewwwio remove_webpWhether you are a seasoned pro, or just getting your feet wet, using WP-CLI can give you super-powers, so don’t be afraid to jump right in! If you have any further questions, just use our contact form and we’ll be happy to assist you. Happy Optimizing!
