Expanding new Media Uploader in WordPress 3.5

You can add inputs and fields to attachments by hooking into attachment_fields_to_edit. This will add fields to both the modal as well as the attachment editor. The catch I found is that WordPress (if anyone has experienced differently PLMK) doesn’t save the extra fields data so you have to hook into a couple other items. … Read more

get_the_post_thumbnail() doesn’t taking style attribute

get_the_post_thumbnail attribute array doesn’t know STYLE , the fields that are available for you to use are: src class alt title so just use the class and define you class to it: $attr = array( ‘title’ => get_the_title(), ‘alt’ => get_the_title(), ‘class’ => ‘rss_thumb’ ); $thumb = get_the_post_thumbnail($post->ID, ‘large-thumb’, $attr); and then define the style … Read more

Add custom class to attachment in media library grid mode

The classes added to each element in the media library grid are dinamically generated in the media-views.js file. Particularly, the code that renders the elements is part of the wp.media.view.Attachment function. It’s a Backbone.js view, so it’s possible to extend the library of that view in order to add the classes or other attributes you … Read more

Changing attachment urls?

You can do the following: /* add new rewrite rule */ function attachment_rewrite( $wp_rewrite ) { $rule = array( ‘media/(.+)’ => ‘index.php?attachment=” . $wp_rewrite->preg_index(1) ); $wp_rewrite->rules = $rule + $wp_rewrite->rules; } add_filter( “generate_rewrite_rules’, ‘attachment_rewrite’ ); /* redirect standard wordpress attachments urls to new format */ function redirect_old_attachment() { global $wp; if( !preg_match( ‘/^media\/(.*)/’, $wp->request ) … Read more

How to cleanly delete attachment but retain original file?

Year and some later with much improved skills, behold: Keep_Deleted_Attachment_File::on_load(); /** * Keep original file when deleting attachments. */ class Keep_Deleted_Attachment_File { static private $file; static function on_load() { add_action( ‘init’, array( __CLASS__, ‘init’ ) ); } static function init() { add_action( ‘delete_attachment’, array( __CLASS__, ‘delete_attachment’ ) ); } /** * @param int $post_id attachment … Read more