WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 4 months ago

#46795 closed defect (bug) (fixed)

Fatal error: Call to undefined function get_available_post_mime_types on frontend

Reported by: david.binda Owned by: adamsilverstein
Milestone: 5.2 Priority: normal
Severity: normal Version: 5.2
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

Hello there,

When testing r44947 from #43658 I'm getting following fatal error:

Fatal error: Uncaught Error: Call to undefined function get_available_post_mime_types() in wp-includes/media.php:3612

The above fatal error can be reproduced using the P2 theme, since it includes wp-includes/media.php and calls do_action( 'media_buttons' ); which calls wp_enqueue_media in a non-admin context / on front-end.

Since the r44947 any call to wp_enqueue_media on front-end would result in the above fatal error.

To solve the issue, the get_available_post_mime_types function, imho, needs to be moved to some more commonly available file, eg.: wp-includes/post.php.

Attachments (1)

46795.diff (1.5 KB) - added by david.binda 5 months ago.

Download all attachments as: .zip

Change History (9)

@david.binda
5 months ago

#1 @SergeyBiryukov
5 months ago

  • Component changed from General to Media

#2 @jorbin
5 months ago

  • Milestone changed from Awaiting Review to 5.2

@adamsilverstein Can you take a look as this is a follow up to [44947] and #43658.

#3 @adamsilverstein
5 months ago

@jorbin yes, I will take a look - thanks for the ping.

#4 @adamsilverstein
4 months ago

@davidbinda moving this seems fine, wondering if there is any chance code could expect the function where it is and fatal after this move? Another approach would be load the existing file on the fly if the function is not available.

#5 @adamsilverstein
4 months ago

  • Keywords has-patch 2nd-opinion added
  • Owner set to adamsilverstein
  • Status changed from new to assigned

Testing the P2 theme I can see the fatal and I verified it is resolved by the patch. i do see wp_enqueue_media is generally intended for back end use however get_available_post_mime_types gets far less use in plugins and themes.

I'd like to get a second opinion on this change to make sure I am not missing a potential side effect.

#6 @joemcgill
4 months ago

  • Keywords commit added; 2nd-opinion removed

I see no reason why this function needs to be limited to an admin context and can imagine many reasons why someone might want to get this information on the front end. +1 from me.

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


4 months ago

#8 @adamsilverstein
4 months ago

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

In 45219:

Media: move get_available_post_mime_types to wp-includes/post.php making it more generally available.

Address an issue since r44947 where calling wp_enqueue_media on the front-end would result in a PHP fatal.

Props david.binda.
Fixes #46795.

Note: See TracTickets for help on using tickets.