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.

Remote upload file to server B

Try adding die(‘message’); and use that to debug where it fails. Also try and use ftp://external-server.com as opposed to just external-server.com. Also make sure you use your FTP password. And try it on active mode as opposed to passive mode. When I was trying to upload by FTP that’s what I had to do. Also … Read more

Decrease file size upload in Media

That number is taken from wp_max_upload_size(), and there is a filter: ‘upload_size_limit’. See wp-admin/includes/template.php. So this should work (not tested): add_filter( ‘upload_size_limit’, ‘wpse_70754_change_upload_size’ ); function wpse_70754_change_upload_size() { return 1000 * 1024; }

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

Is there a hook which fires after all thumbnails are generated?

Thumbnails in WordPress can be generated by using wp_generate_attachment_metadata(), this function fires a filter after generating all the thumbnails wp_generate_attachment_metadata and the filter provides $metadata and $attachment_id to the hooked functions. You can hook your custom function to this filter. $metadata : Attachment metadata. What you need is $metadata[‘sizes’][‘<size-name>’], the <size-name> is the name of … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)