Generate image size, based on the image-orientation

Here is my working solution. The code is documented, so it should be clear what each function does. I pretty much use the wp_generate_attachment_metadata filter to create the needed images after the image has been uploaded. The generated images are listed in the metadata too, like any other intermediate image size. That way you can … Read more

Get the size (size in Kb or MB) of an featured image?

You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to Convert a given number of bytes into a human readable … Read more

Did I do it right? Deleting images after deleting product. Woocommerce

Looking at @obmerks answer on https://stackoverflow.com/questions/12997698/delete-images-after-post you can simplify it with this: foreach ( $productIds as $productId ) { $child_atts = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_parent = $productId AND post_type=”attachment””); foreach ( $child_atts as $id ) wp_delete_attachment($id,true); } Note: as per documentation https://codex.wordpress.org/Function_Reference/wp_delete_attachment set the second parameter to true to force delete the attachment, … Read more