admin管理员组

文章数量:1332377

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

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

Share Improve this question edited Jan 26, 2017 at 21:40 Arsalan Mithani 5534 silver badges15 bronze badges asked Jan 26, 2017 at 21:15 CelsoCelso 2011 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 9

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 ) );

本文标签: uploadsIs wpreadaudiometadata() function deprecated