| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: MWE Trac #42794
|
|---|
| 4 | Plugin URI: https://core.trac.wordpress.org/ticket/42794
|
|---|
| 5 | Description: Demonstration that one can't upload new media files when multiple media dialogues are present on a single page.
|
|---|
| 6 | Version: 1.0
|
|---|
| 7 | Author: carlobeltrame
|
|---|
| 8 | License: GPL2
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /* Minimal working example CPT with multiple media uploaders on the same page */
|
|---|
| 12 | function trac42794_custom_post_type_mwe( $wpptd ) {
|
|---|
| 13 | $wpptd->add_components( array(
|
|---|
| 14 | 'trac42794_mwe' => array(
|
|---|
| 15 | 'label' => __( 'MWE', 'trac42794' ),
|
|---|
| 16 | 'post_types' => array(
|
|---|
| 17 | 'mwe' => array(
|
|---|
| 18 | 'public' => true,
|
|---|
| 19 | 'metaboxes' => array(
|
|---|
| 20 | 'mwe_metabox' => array(
|
|---|
| 21 | 'title' => __( 'MWE metabox', 'trac42794' ),
|
|---|
| 22 | 'fields' => array(
|
|---|
| 23 | 'mwe-media-picker-1' => array(
|
|---|
| 24 | 'title' => __( 'Media picker 1', 'trac42794' ),
|
|---|
| 25 | 'type' => 'media',
|
|---|
| 26 | ),
|
|---|
| 27 | 'mwe-media-picker-2' => array(
|
|---|
| 28 | 'title' => __( 'Media picker 2', 'trac42794' ),
|
|---|
| 29 | 'type' => 'media',
|
|---|
| 30 | ),
|
|---|
| 31 | ),
|
|---|
| 32 | ),
|
|---|
| 33 | ),
|
|---|
| 34 | ),
|
|---|
| 35 | ),
|
|---|
| 36 | ),
|
|---|
| 37 | ), 'trac42794' );
|
|---|
| 38 | }
|
|---|
| 39 | add_action( 'wpptd', 'trac42794_custom_post_type_mwe' );
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | /* Proposed fix: modify UploaderStatus such that ready() is called at the end of every
|
|---|
| 43 | * initialize() invocation. This is demonstrated here by overriding UploaderStatus, but
|
|---|
| 44 | * in the proposed patch, we would patch the UploaderStatus class directly in core.
|
|---|
| 45 | * Uncomment the last line to activate the fix. */
|
|---|
| 46 | function trac42794_fix_media_uploader() {
|
|---|
| 47 | ?>
|
|---|
| 48 | <script>
|
|---|
| 49 | var oldUploaderStatus = wp.media.view.UploaderStatus;
|
|---|
| 50 | wp.media.view.UploaderStatus = oldUploaderStatus.extend({
|
|---|
| 51 | initialize: function() {
|
|---|
| 52 | oldUploaderStatus.prototype.initialize.call(this);
|
|---|
| 53 | this.ready();
|
|---|
| 54 | }
|
|---|
| 55 | });
|
|---|
| 56 | </script><?php
|
|---|
| 57 | }
|
|---|
| 58 | function trac42794_add_media_modification_js() {
|
|---|
| 59 | add_action( 'admin_print_footer_scripts', 'trac42794_fix_media_uploader' );
|
|---|
| 60 | }
|
|---|
| 61 | //add_action( 'wp_enqueue_media', 'trac42794_add_media_modification_js' );
|
|---|