Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#39511 closed defect (bug) (fixed)

JS Error: Cannot read property 'models' of undefined in wp-includes/js/media-views.js at line no 7727

Reported by: chandrapatel Owned by: wonderboymusic
Milestone: 4.8 Priority: normal
Severity: normal Version: 4.6
Component: Media Keywords: commit
Focuses: javascript Cc:


Below are the steps to reproduce this JS error.

  1. Add this code in plugin or in mu-plugins directory.

function cmu_media_menu( $tabs ) {
    $newtab = array( 'cmu' => 'Custom Media Upload' );
    return array_merge( $tabs, $newtab );

add_filter( 'media_upload_tabs', 'cmu_media_menu' );

function cmu_media_handle() {
    echo 'Hey Everyone !';

add_action( 'media_upload_cmu', function() {
    return wp_iframe( 'cmu_media_handle' );
} );
  1. Create New Post -> Click on Add Media -> Click on Custom Media Upload and than close pop-up.
  1. Now click on Featured Image than click on Upload Files tab and than try to upload file. You will get JS error as mentioned above.

selection and library state are not set for custom tabs.

Simple solution is like add if condition. I've added initial patch.

Attachments (1)

39511.patch (731 bytes) - added by chandrapatel 5 years ago.

Download all attachments as: .zip

Change History (5)

5 years ago

#1 @chandrapatel
5 years ago

  • Keywords has-patch added

#2 @adamsilverstein
5 years ago

  • Keywords commit added; has-patch removed
  • Milestone changed from Awaiting Review to 4.8
  • Owner set to adamsilverstein
  • Status changed from new to assigned

@chandrapatel Thanks for your detailed bug report and the patch. The check seems quite reasonable and appropriate here.

I was able to reproduce the issue you described and see the error in my console when attempting to upload, and I am unable to upload images.


After applying your patch I verified I no longer see the console message, and image uploading works fine.

#3 @wonderboymusic
5 years ago

  • Owner changed from adamsilverstein to wonderboymusic

#4 @wonderboymusic
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 40050:

Media: in wp.media.view.Toolbar.refresh(), check for a selection before iterating over models.

Props chandrapatel.
Fixes #39511.

Note: See TracTickets for help on using tickets.