Search code examples
phpwordpresspleskwp-cli

Using WP-CLI on Plesk to Update Media w/ Custom Image Size, Not Working


I'm attempting to use WP-CLI's media regenerate feature to update a website with 60k worth of images that I had to add a new image size for.

However, I'm not seeing it list the sizes correctly compared to what I've written, and what Regenerate Thumbnails, the plugin, lists on my attachment pages.

plesk ext wp-toolkit --wp-cli -instance-id 2 media regenerate --image_size=custom

Is what I'm trying to run. I've confirmed I'm on the right Plesk WP instance.

Running it with 'only-missing' gives me an HTTP error 413 which may be a separate issue relating to navigating regenerating on S3, any suggests there to try and make an end run around this would be appreciated as well, but I'd like to do this right if possible.


Solution

  • I was able to get this to work by adding the following:

    // assuming you've registered a custom size named my-custom-size elsewhere
    
    add_action('admin_init', function() {
        $list_of_sizes['my-custom-size'] = 'My Custom Size';
        add_filter(
            'image_size_names_choose',
            function( $sizes ) use ( $list_of_sizes ) {
                return array_merge( $sizes, $list_of_sizes );
            }
        );
    });
    

    I think this is necessary because nearly all tutorials on the Interwebs tell you to add custom image sizes in after_theme_setup but I don't think that action runs in the admin.

    HTH, and please reply if it doesn't.