woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Unable to remove image sizes #862

Closed vijayhardaha closed 3 years ago

vijayhardaha commented 3 years ago

I am trying to remove 'ppec_logo_image_size', 'ppec_header_image_size' image sizes using this code.

/**
 * Remove unused image sizes
 */
function custom_remove_image_sizes() {
    $sizes = array( 'ppec_logo_image_size', 'ppec_header_image_size' );
    foreach ( $sizes as $size ) {
        remove_image_size( $size );
    }
}
add_action( 'init', 'custom_remove_image_sizes', 20 );

on the regenerate thumbnail page those sizes don't show up but they get generated somehow. if I generate individual images then those sizes show up.

check attachments.

image

in the above screenshot, you'll see that those sizes are not showing.

image

But in the individual image, you can see those image sizes are showing and they also exist in the upload directory.

Is there a proper way to remove those sizes? and are they necessary for the plugin to work?

jorgeatorres commented 3 years ago

Hi @vijayhardaha,

The problem with your code is that it is hooked onto the init action (with priority 20), which is too early. Depending on what triggers PayPal Checkout, it might register those image sizes at different moments (widget hooks, while visiting the WooCommerce settings page, REST API init, etc.). Because some of those things can happen after init, your snippet might or might not be successful at preventing the sizes from being registered.

The logo and header image have been deprecated, though, so we will probably remove the code that adds those sizes in a future version. In the mean time, if you don't want to constantly fight with the different moments the sizes might be registered, I'd suggest you comment out the following lines (76-79) in file woocommerce-gateway-paypal-express-checkout/includes/abstracts/abstract-wc-gateway-ppec.php:

https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/blob/6e61d3ffef574760d9a9f022ff9cfe1e1a2ce970/includes/abstracts/abstract-wc-gateway-ppec.php#L76-L79

Hope that helps. Feel free to re-open this issue if you're having trouble or have any questions.