Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 21 months ago

#55828 closed enhancement (fixed)

Add filter in `wp_read_audio_metadata` function

Reported by: luigipulcini's profile luigipulcini Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch commit needs-dev-note
Focuses: Cc:

Description

At the moment, the function wp_read_audio_metadata is returning the $metadata extracted from an uploaded audio file without applying any filter to it. In addition to the limitations that this poses (e.g. third-party plugins may want/need to attach additional properties to the $metadata array by pulling them from the $data array), the missing filter also seems to be in contrast and inconsistent with the corresponding wp_read_image_metadata and wp_read_video_metadata functions, which both filter the file metadata array before returning it (here for images and here for videos).

This could easily be fixed by simply replacing line 3700:

return $metadata;

with

return apply_filters( 'wp_read_audio_metadata', $metadata, $file, $data );

There are so many properties stored in the ID3 tag that get_id3() is capable of extracting from the file but WordPress simply leaves behind that this filter is very much needed and is perfectly consistent with what WordPress already has for images and videos, including its hook name.

Change History (10)

This ticket was mentioned in PR #2747 on WordPress/wordpress-develop by LuigiPulcini.


2 years ago
#1

At the moment, the function wp_read_audio_metadata is returning the $metadata extracted from an uploaded audio file without applying any filter to it. In addition to the limitations that this poses (e.g. third-party plugins may want/need to attach additional properties to the $metadata array by pulling them from the $data array), the missing filter also seems to be in contrast and inconsistent with the corresponding wp_read_image_metadata and wp_read_video_metadata functions, which both filter the file $metadata array before returning it (here for images and here for videos).

This could easily be fixed by simply replacing line 3700:

return $metadata;

with

return apply_filters( 'wp_read_audio_metadata', $metadata, $file, $data );

There are so many properties stored in the ID3 tag that the getID3() class is already extracting from the uploaded file but WordPress simply leaves behind that this filter is very much needed and is perfectly consistent with what WordPress already has for images and videos, including its hook name.

Trac ticket: https://core.trac.wordpress.org/ticket/55828

#2 @davidbaumwald
2 years ago

  • Milestone changed from Awaiting Review to 6.1

#3 follow-up: @SergeyBiryukov
2 years ago

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

I think this makes sense. As you mentioned, it would also bring parity with the existing filters:

#4 @mukesh27
2 years ago

Hi there!

As we have $file_format for the wp_read_video_metadata filter do we need it for audio filter?

Can you please update @since 6.0.1 tag to @since 6.1.0?

#5 in reply to: ↑ 3 @luigipulcini
2 years ago

Good point about the $file_format parameter, @mukesh27.
I initially left it out just because it is always possible to access it from both the $metadata and the $data parameters. But I agree with you that this will improve the consistency between the two audio and video filters.

I will also update the @since tag.

#6 @audrasjb
2 years ago

  • Keywords commit needs-dev-note added
  • Owner set to audrasjb
  • Status changed from new to accepted
  • Version trunk deleted

Thanks for spotting this and for the PR,

Self assigning for commit consideration.

#7 @audrasjb
2 years ago

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

In 53764:

Media: Allow filtering audio file metadata in wp_read_audio_metadata().

This changeset introduces the wp_read_audio_metadata hook which allows to filter metadata extracted from an uploaded audio file.

This brings consistency with corresponding filters available for image and video file types:

Props luigipulcini, SergeyBiryukov, mukesh27.
Fixes #55828.

#9 @SergeyBiryukov
2 years ago

In 53768:

Docs: Document that the $file_format parameter of metadata filters can be null.

This affects the wp_read_video_metadata and wp_read_audio_metadata filters.

Follow-up to [41746], [53764].

See #55646, #55828.

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


21 months ago

Note: See TracTickets for help on using tickets.