Make WordPress Core


Ignore:
Timestamp:
03/15/2012 04:14:05 AM (12 years ago)
Author:
koopersmith
Message:

Theme Customizer: First pass for upload controls, using background image as an example. Add a wrapper for Plupload that allows for custom upload UIs. see #19910.

wp.Uploader is a wrapper that provides a simple way to upload an attachment (using the wp_ajax_upload_attachment handler). It is intentionally decoupled from the UI. When an upload succeeds, it will receive the attachment information (id, url, meta, etc) as a JSON response. If the upload fails, the wrapper handles both WordPress and plupload errors through a single handler.

As todos, we should add drag classes for the uploader dropzone and account for the rough 100mb filesize limit in most browsers. The UI for the customizer upload controls could be improved as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r19871 r20179  
    14421442    return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
    14431443}
     1444
     1445/**
     1446 * Prints default plupload arguments.
     1447 *
     1448 * @since 3.4.0
     1449 */
     1450function wp_plupload_default_settings() {
     1451    global $wp_scripts;
     1452
     1453    $max_upload_size = wp_max_upload_size();
     1454
     1455    $params = array(
     1456        'action' => 'upload-attachment',
     1457    );
     1458    $params = apply_filters( 'plupload_default_params', $params );
     1459
     1460    $params['_wpnonce'] = wp_create_nonce( 'media-form' );
     1461
     1462    $settings = array(
     1463        'runtimes'            => 'html5,silverlight,flash,html4',
     1464        'file_data_name'      => 'async-upload', // key passed to $_FILE.
     1465        'multiple_queues'     => true,
     1466        'max_file_size'       => $max_upload_size . 'b',
     1467        'url'                 => admin_url( 'admin-ajax.php' ),
     1468        'flash_swf_url'       => includes_url( 'js/plupload/plupload.flash.swf' ),
     1469        'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
     1470        'filters'             => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*') ),
     1471        'multipart'           => true,
     1472        'urlstream_upload'    => true,
     1473        'multipart_params'    => $params,
     1474    );
     1475
     1476    $settings = apply_filters( 'plupload_default_settings', $settings );
     1477
     1478    $script = 'var wpPluploadDefaults = ' . json_encode( $settings ) . ';';
     1479
     1480    $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
     1481    if ( $data )
     1482        $script = "$data\n$script";
     1483
     1484    $wp_scripts->add_data( 'wp-plupload', 'data', $script );
     1485}
     1486add_action( 'admin_init', 'wp_plupload_default_settings' );
Note: See TracChangeset for help on using the changeset viewer.