Rename files on upload

no need to use a custom table, use an option, and the add_attachment hook: function wpa59168_rename_attachment( $post_ID ) { $post = get_post( $post_ID ); $file = get_attached_file( $post_ID ); $path = pathinfo( $file ); $count = get_option( ‘wpa59168_counter’, 1 ); // change to $new_name = $count; if you want just the count as filename $new_name … Read more

How do I hook into WordPress to save an uploaded photo as an alternate size to an existing photo?

This can be done by using: wp_get_attachment_metadata(); wp_update_attachment_metadata(); You’d get the meta data for it and change it around then save it. The $data array you get contains another array named sizes, this array contains all the different size images connected to the attachment. You want this to update automatically when you upload images that … Read more

Add default Backgrounds

There’s no default way to do that yet, though there is a Trac ticket. I found this (untested) that may work for you: http://www.devblog.fr/2011/05/16/plusieurs-fonds-personnalises-wordpress-add_custom_background/ It’s also worth noting the 3.4’s new way of defining a default background (still just one, though). Edit Here’s the code: <?php function wpse48332_setup_theme() { // Add support for custom backgrounds … Read more

Maintaining image color and quality when uploading using custom sizes

Use the jpeg_quality and wp_editor_set_quality filters to set the quality of resized images: add_filter( ‘wp_editor_set_quality’, ‘wpse246186_image_quality’ ); add_filter( ‘jpeg_quality’, ‘wpse246186_image_quality’ ); function wpse246186_image_quality( $quality ) { return 100; // 0 – 100% quality } I have not been able to reproduce the issue reported; the original PNG image looks the same as the thumbnails. Tested … Read more