Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#28641 closed defect (bug) (worksforme)

wp_enqueue_media() breaks media library

Reported by: mcguive7's profile McGuive7 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Media Keywords:
Focuses: ui, administration Cc:

Description

I've encountered an issue with wp_enqueue_media() and the media library that seems similar to some previous tickets, but unique enough that it may warrant it's own ticket. Furthermore this issue appears only in WP 4.0 alpha for me, so it may be a recently introduced bug.

The issue: Adding a call to wp_enqueue_media() in my plugin/theme causes the media library list view to break. Specifically, this appears to cause both the grid/gallery and list views to display simultaneously, with the grid/gallery view overlaid on top of the list view, rendering the list view unclickable. See below image:
http://i.imgur.com/Fmyc9Su.png

The code:

add_action( 'admin_enqueue_scripts', 'custom_admin_scripts' );
function custom_admin_scripts() {
	wp_enqueue_media();
}

I've created a demo plugin that includes a basic wp_enqueue_media() call hooked to admin_enqueue_scripts (the recommended hook as per http://codex.wordpress.org/Function_Reference/wp_enqueue_media) - see attached. Interestingly, it appears that things work just fine if I hook the call to the admin_footer hook, however if I attach it to any earlier hook, the issue occurs again.

I've tested this issue with only the demo plugin installed, and the default Twenty Fourteen theme activated, so it seems to be directly related to the wp_enqueue_media() call as opposed to any combined set of plugin/theme conflicts.

Happy to provide more data if need be, just let me know.

Attachments (1)

custom-plugin.zip (430 bytes) - added by McGuive7 11 years ago.
Installable plugin to demonstrate the issue

Download all attachments as: .zip

Change History (7)

@McGuive7
11 years ago

Installable plugin to demonstrate the issue

#1 @ericlewis
11 years ago

Quick response: you shouldn't be enqueueing media on every admin page request. Use the $hook_suffix provided by the admin_enqueue_scripts hook to only load your script on the admin page you want it to load on.

I'll give a fuller response when I have some more time next week.

Last edited 11 years ago by ericlewis (previous) (diff)

#2 follow-up: @McGuive7
11 years ago

Hi Eric,

Thanks for the explanation, and I would love to hear your longer response.

Unfortunately, this call to wp_enqueue_media() is part of the
Titan Framework (https://github.com/gambitph/Titan-Framework), and is being enqueued somewhat indiscriminately. This may be an oversight, or it may just be technically challenging for the framework to know exactly when and where to add the enqueue across multiple, dynamically-generated options pages. Anyhow, not sure if I can expect the framework code to change anytime soon. . .

I'd love to know if the issue is just that wp_enqueue_media() should not be called at all on the media library page, or if perhaps it's being called already on that page (although it seems like this should be an issue since the function checks if it's already been called, right? Something else entirely? I imagine there are probably lots of plugins calling wp_enqueue_media() across the board in the admin, and since this conflict only arises in WP 4.0 alpha, it seems like there are going to be lots of plugins causing the same issue. With all this in mind, is there a solution you'd suggest, either on the plugin/user end, or in WP core?

Thanks!

Last edited 11 years ago by McGuive7 (previous) (diff)

#3 in reply to: ↑ 2 @ericlewis
11 years ago

Replying to McGuive7:

Unfortunately, this call to wp_enqueue_media() is part of the
Titan Framework, and is being enqueued somewhat indiscriminately. This may be an oversight, or it may just be technically challenging for the framework to know exactly when and where to add the enqueue across multiple, dynamically-generated options pages. Anyhow, not sure if I can expect the framework code to change anytime soon. . .

I'd either fork it, make a good argument to make the changes upstream or get on a more stable framework.

I'd love to know if the issue is just that wp_enqueue_media() should not be called at all on the media library page, or if perhaps it's being called already on that page (although it seems like this should be an issue since the function checks if it's already been called, right?

Right, curious. Maybe the framework (or other code) is doing something else wrong. It could also be an issue with our implementation.

#4 @McGuive7
11 years ago

Thanks for the response. Yep, I just created my own fork to conditionally make the call only on options pages instead of on all admin pages.

As for the second bit, that's the part I'm wondering about. Seems to me like something got introduced with WP 4.0's new media library that doesn't play nice with calls to wp_enqueue_media(). It may well be that users shouldn't be calling it anyways on the media library page, but it seems to me like it shouldn't cause the whole display to fail. I have no idea what the actual issue is, but it seems for the sake of backwards compatibility it would be good to get to the bottom of this and make sure it's NOT a core WP issue.

Is this the right place to be filing this bug? I'm newish to Trac.

#5 @McGuive7
11 years ago

Looks like this is fixed with the newer commits. Can anyone confirm?

#6 @ocean90
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.