#51791 closed defect (bug) (fixed)
When wp_prepare_attachment_for_js() is called too early, a fatal occurs "Call to undefined function get_media_states()"
Reported by: | rebasaurus | Owned by: | helen |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | major | Version: | 5.6 |
Component: | Media | Keywords: | has-patch commit |
Focuses: | Cc: |
Description (last modified by )
When we call wp_prepare_attachment_for_js()
too early, we see the fatal:
Call to undefined function get_media_states()
Introduced in [49223] from #42063.
To test in twentytwenty:
--- a/themes/twentytwenty/header.php +++ b/themes/twentytwenty/header.php @@ -26,6 +26,7 @@ <body <?php body_class(); ?>> + <?php var_dump( wp_prepare_attachment_for_js( '28' ) ); ?> <?php wp_body_open(); ?>
You will see it fatal.
Attachments (1)
Change History (11)
This ticket was mentioned in Slack in #core-media by hellofromtonya. View the logs.
4 years ago
#3
@
4 years ago
@helen Correct, specifically, we've seen usages for it in shortcodes, template tags, etc.
@
4 years ago
Since I see that we check for the existence of get_compat_media_markup above, I think we can do the same behavior here?
#5
@
4 years ago
- Keywords commit added
Yeah I think it makes sense to just do it the same as get_compat_media_markup
given the context. More broadly I kind of feel like it should actually be filtered in closer to usage time since it's just a string and not super useful without more futzing outside of the specific admin usage but that's probably too much to be messing with for not a ton of benefit.
#6
@
4 years ago
Just tested this and it's working after patch with the example code given to fatal.
Just for reference, what's the use case for calling this in such a context (JS front end, something else)? This will help make sure we make the right fix and don't break it again in the future.