Force WordPress 3.3 to use Flash uploader

Context Searching for .swf in the Core, found this in /wp-admin/includes/media.php: $plupload_init = array( ‘runtimes’ => ‘html5,silverlight,flash,html4’, ‘browse_button’ => ‘plupload-browse-button’, ‘container’ => ‘plupload-upload-ui’, ‘drop_element’ => ‘drag-drop-area’, ‘file_data_name’ => ‘async-upload’, ‘multiple_queues’ => true, ‘max_file_size’ => $max_upload_size . ‘b’, ‘url’ => $upload_action_url, ‘flash_swf_url’ => includes_url(‘js/plupload/plupload.flash.swf’), ‘silverlight_xap_url’ => includes_url(‘js/plupload/plupload.silverlight.xap’), ‘filters’ => array( array(‘title’ => __( ‘Allowed Files’ ), … Read more

Display attachments by ID in a wp.media frame

You can always filter on the client side: var query = wp.media.query(); query.filterWithIds = function(ids) { return _(this.models.filter(function(c) { return _.contains(ids, c.id); })); }; var res = query.filterWithIds([6,87]); // change these to your IDs res.each(function(v){ console.log( v.toJSON() ); }); Disclaimer: found the beautiful filterWithIds function in this SO question.

Organize uploads by year, month and day

Code based in other Answer of mine and this SO Answer. It uses the post/page/cpt publish date to build the paths. Note that $the_post->post_date_gmt is also available. add_filter(‘wp_handle_upload_prefilter’, ‘wpse_70946_handle_upload_prefilter’); add_filter(‘wp_handle_upload’, ‘wpse_70946_handle_upload’); function wpse_70946_handle_upload_prefilter( $file ) { add_filter(‘upload_dir’, ‘wpse_70946_custom_upload_dir’); return $file; } function wpse_70946_handle_upload( $fileinfo ) { remove_filter(‘upload_dir’, ‘wpse_70946_custom_upload_dir’); return $fileinfo; } function wpse_70946_custom_upload_dir($path) { /* … Read more

upload_async.php returns 500 error

It’s a bit of a shot in the dark, but would you like to move up your memory limit? My guess is that your uploader fails on uploading big files with more serious plugins on just because they are using some of the memory too. In some cases “Memory exhausted” message does not appear if … Read more

Rename files during upload using variables

You’ll want to hook in to the wp_handle_upload_prefilter filter (which I can’t find any documentation on, but seems pretty simple). I’ve tried this out locally, and it seems to work for me: function wpsx_5505_modify_uploaded_file_names($arr) { // Get the parent post ID, if there is one if( isset($_REQUEST[‘post_id’]) ) { $post_id = $_REQUEST[‘post_id’]; } else { … Read more

Create image formats with different qualities when uploading

1) A workaround by extending the WP_Image_Editor_GD class The problem is how to access the image sizes before we change the quality of intermediate jpeg images. Note that the image_resize() function is deprecated. We can use the jpeg_quality filter from the public get_quality method of the abstract WP_Image_Editor class: $quality = apply_filters( ‘jpeg_quality’, $quality, ‘image_resize’ … Read more