3

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

5

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 ) );
  • 1
    Thanks! Didn't realize the function was only accessible in wp-admin. – Celso Jan 26 '17 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.