[wp-trac] [WordPress Trac] #23028: Multiple calls to wp_enqueue_media() breaks featured image functionality
WordPress Trac
noreply at wordpress.org
Thu Dec 20 19:30:24 UTC 2012
#23028: Multiple calls to wp_enqueue_media() breaks featured image functionality
-----------------------------+-------------------------
Reporter: johnbillion | Type: enhancement
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Media
Version: 3.5 | Severity: normal
Keywords: |
-----------------------------+-------------------------
== Situation ==
My custom meta box provides a button which launches the new media manager
so a user can upload files.
This meta box can potentially be shown on the editing screen for a post
type which supports neither a featured image nor the editor. Therefore, my
meta box needs to call `wp_enqueue_media()` otherwise it won't have the
required JS or CSS to work with.
== Problem ==
The meta box can't blindly call `wp_enqueue_media()` all the time because
the editing screen for a post type which supports the editor or a featured
image will have already called this function. Calling it a second time
causes the featured image functionality to break. (A blank media item is
added to the media list and choosing an image as the featured image
fails.)
My meta box therefore needs to do something like this to detect if
`wp_enqueue_media()` has already been called:
{{{
if ( !has_action( 'admin_footer', 'wp_print_media_templates' ) )
wp_enqueue_media();
}}}
This isn't ideal because the logic in my meta box is now tied to the
internal behaviour of `wp_enqueue_media()`.
== Solution ==
Either prevent the featured image functionality from breaking when
`wp_enqueue_media()` is called multiple times, or add some logic to
`wp_enqueue_media()` so it doesn't do its thing more than once.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23028>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list