Is wp_read_audio_metadata() function deprecated?

I am trying to use the function wp_read_audio_metadata() to read the metadata for an mp3 file uploaded to a post using acf’s file field.

Below is my code:

<?php 
$audio_file = get_field('archive_audio_file'); 
$audio_file_id = $audio_file['id'];
$audio_file_path = get_attached_file( $audio_file_id);
var_dump(wp_read_audio_metadata($audio_file_path));
?>

When using that code I receive this error on the front end:

Fatal error: Call to undefined function wp_read_audio_metadata()

Am I using the code incorrectly? or this function is deprecated? because I couldn’t find it in wp-includes/media.php

1 Answer
1

wp_read_audio_metadata() is not deprecated. It’s located in /wp-admin/includes/media.php, which is not loaded on the front end, hence the error your’re getting.

You are using the function correctly. You can make wp_read_audio_metadata() available by including wp-admin/includes/media.php before calling the function, e.g.:

require_once( ABSPATH . 'wp-admin/includes/media.php' );
$audio_file_path = get_attached_file( 1821 ); // example attachment ID
var_dump( wp_read_audio_metadata( $audio_file_path ) );

Leave a Comment