An automatic upgrade to Wordpress 3.9 broke the "Add media" functionality for posts on our client's site...when you click "Add media", it wasn't showing any of the photos in the media library (just had a blank area where the photos should be), even though those photos are still there when you go to the Media Library via the "Media" menu item in the main navigation.
Since then, I have tried upgrading to Wordpress 3.9.2, disabling all plugins, and setting the theme to the default TwentyTen theme. The issue still remains, and the only difference after all of that is that the upgrade to Wordpress 3.9.2 (from an earlier 3.9 version) seems to have caused a spinning icon to appear in the area where the photos should load, but it just spins forever and the photos never load.
I looked at the AJAX calls in Chrome Developer Tools and found that the admin_ajax.php call is actually returning the correct data, including all the correct image paths, so that's not the problem...I'm thinking there must be some Javascript-related issue that's causing the images not to appear.
Debugging this further, I found the initialize() function of media.controller.GalleryAdd, which is a standard Wordpress file at wp-includes/js/media-views.js. I added the console.log()
function to see what was going on:
initialize: function() {
// If we haven't been provided a `library`, create a `Selection`.
if ( ! this.get('library') ) {
console.log('media.query result', media.query({ type: 'image' }) )
this.set( 'library', media.query({ type: 'image' }) );
}
media.controller.Library.prototype.initialize.apply( this, arguments );
}
Wordpress uses Backbone.js, and although I don't know Backbone, I found what looks like a problem here...the media.query() result has a length
of 0 and its models
array is empty.
I am trying to debug further to find the source of the problem, but I'm not all that familiar with the Wordpress source code and as I mentioned I'm not familiar with Backbone either, and it would be nice to get this resolved without having to spend hours upon hours debugging it more.
Can anyone provide any ideas/suggestions as to what might be the problem here?