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

Use Media Uploader in Plugin

Try using this code: define(“ME_URL”, rtrim(WP_PLUGIN_URL,”https://wordpress.stackexchange.com/”) . “https://wordpress.stackexchange.com/” . basename(dirname(__FILE__))); define(“ME_DIR”, rtrim(dirname(__FILE__), “https://wordpress.stackexchange.com/”)); function my_admin_scripts() { wp_enqueue_script(‘media-upload’); wp_enqueue_script(‘thickbox’); } function my_admin_styles() { wp_enqueue_style(‘thickbox’); } add_action(‘admin_print_scripts’, ‘my_admin_scripts’); add_action(‘admin_print_styles’, ‘my_admin_styles’); <td> <img src=”<?php echo esc_attr( get_the_author_meta( ‘profileimage’, $user->ID ) ); ?>” id=”ppimage”> <input type=”text” name=”profileimage” id=”profileimagetxt” value=”<?php echo esc_attr( get_the_author_meta( ‘profileimage’, $user->ID ) ); ?>” class=”regular-text” /><br … Read more

Add suffix to filename of uploaded images

I did it in a different way. I just had to update the code from Gerasimos Tsiamalos Retina Plugin to WordPress 3.5., using image editor instead of image resize. This is how it looks like: function nothing_image_make_retina_size($file, $width, $height, $crop=false) { if ( $width || $height ) { $resized_file = wp_get_image_editor($file); if ( ! is_wp_error( … Read more

How to get custom image sizes into media uploader dropdown?

Try seperating it like this: function setup_image_sizes() { if ( function_exists( ‘add_image_size’ ) ) { add_image_size( ‘post-image’, 608, 350, true ); } } add_action( ‘after_setup_theme’, ‘setup_image_sizes’ ); function post_image_sizes($sizes){ $custom_sizes = array( ‘post-image’ => ‘Post Image’ ); return array_merge( $sizes, $custom_sizes ); } add_filter(‘image_size_names_choose’, ‘post_image_sizes’); That way it is working in my setup. Additional Sources: … Read more

How to add a rel attribute to images that contains their categories?

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( ‘get_image_tag’, function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; } return str_ireplace( ‘<img ‘, sprintf( ‘<img rel=”%s” ‘, join( ‘ … Read more