Rename image uploads with width in filename

I’ve managed to do it with the filter image_make_intermediate_size. Probably all the path/filename.extension dismembering and remaking could be optimized or made in a single stroke fashion, but alas, I’ll let that to the reader: // The filter runs when resizing an image to make a thumbnail or intermediate size. add_filter( ‘image_make_intermediate_size’, ‘rename_intermediates_wpse_82193’ ); function rename_intermediates_wpse_82193( … Read more

Importing WordPress Attachments Into Custom Directories In wp-content/uploads/

Yes you can by programatically adding the attachment. $upl = wp_upload_dir(); $target = $upl[‘basedir’] . ‘/YOUR_CUSTOM_FOLDERS/YOUR_FILE’; $filetype = wp_check_filetype($target); $attachment = array( ‘post_mime_type’ => $filetype[‘type’], ‘post_title’ => $YOUR_FILE_TITLE, ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ); wp_insert_attachment( $attachment, $target, $POST_ID_TO_ATTACH_TO ); This will tell WordPress that there is an attachment at $target and you can optionally … Read more

How can I upload SVG images using the media uploader?

You need to filter the allowed upload file types and add the SVG filetype to the list: function allow_svg_upload_mimes( $mimes ) { $mimes[‘svg’] = ‘image/svg+xml’; return $mimes; } add_filter( ‘upload_mimes’, ‘allow_svg_upload_mimes’ ); Also on GitHub

Extend 3.5 media uploader plugin to change button name

Figured it out using a different method. Help from here. $.fn.oeUpload = function(options) { // Set default options var defaults = { ‘preview’ : ‘.preview-upload’, ‘text’ : ‘.text-upload’, ‘button’ : ‘.button-upload’, ‘name’ : ‘Choose Image’ }; var options = $.extend(defaults, options); var uploader; $(options.button).click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen … Read more

Modify the array of selected images in media modal

I’m able to do the following in media modal: var selection = wp.media.frame.state().get(‘selection’); // get selected collection attachment = wp.media.attachment(id); // get attachment with id attachment.fetch(); selection.add(attachment); // add attachment to selection collection There should be .remove() method or something similar.

Ignore a filter on the media library

You can use is_admin() in conjunction with the admin global variable $pagenow to make sure you’re not on either the upload or media page: function remove_images( $where ) { global $wpdb, $pagenow; if( is_admin() && in_array( $pagenow, array( ‘upload.php’, ‘media-upload.php’ ) ) { return $where } $where .= ” AND {$wpdb->posts}.post_mime_type NOT LIKE ‘image/%'”; return … Read more

How to add a category or tag to media at upload time with the browser uploader?

I’ve been using Media Tags plugin with much success – it was very useful for retrieving images belonging to certain page with specific tags with following code: $results = get_attachments_by_media_tags(array(“media_tags”=>”gallery”, “post_parent” => $global_id, “order” => “ASC”)); Of course you can easily tag anything that sits in your media library (I wasn’t even aware that you … Read more