I had recently implemented custom Plupload form in a plugin (located in admin area and working with SVG files).
Plupload has half a ton of settings, provided for WP's own upload zone by wp_plupload_default_settings()
, from which I had to copy settings out and customize.
Now in upcoming 3.9 core release those settings are getting changed (see Plupload 2.x in WordPress 3.9), which would likely blow my custom upload up, at least partially.
How do I implemented Plupoad in a way that won't fall apart every time core changes related bits and won't interfere with arbitrary upload zones in core or other plugins/themes?
This is settings I ended up with so far (they might not be perfect, but they got it done):
public function get_uploader_settings() {
return array(
'runtimes' => 'html5,silverlight,flash,html4',
'browse_button' => 'cdd-plupload-browse-button',
'container' => 'cdd-plupload-upload-ui',
'drop_element' => 'cdd-drag-drop-area',
'file_data_name' => 'async-upload',
'multiple_queues' => true,
'max_file_size' => wp_max_upload_size() . 'b',
'url' => admin_url( 'admin-ajax.php' ),
'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' ), 'extensions' => 'svg' ) ),
'multipart' => true,
'urlstream_upload' => true,
'multi_selection' => false,
'multipart_params' => array(
'_ajax_nonce' => wp_create_nonce( 'media-form' ),
'action' => 'upload-attachment',
'post_id' => get_the_ID(),
'cdd-upload' => true,
),
);
}
wp_plupload_default_settings()
function was simply more generic in a way you could use outside ofwp.Uploader
andwp.media
. Second is to try and decouplewp.Uploader
from media and have plugins use that instead. Inside we can provide back-compat code for things likemax_file_size
. Thoughts?$defaults
fromwp_plupload_default_settings()
without its side effects. I could probably handle this in JS, but this assume native stuff is enabled, for generic case / public code would be too fragile.max_file_size
andfilters
ref, so I guess the only things we're missing are the paths to the swf/xap files...