Skip to content

Instantly share code, notes, and snippets.

@xnau
Created November 19, 2017 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/90a648686bccd3af0565c317ba9f947e to your computer and use it in GitHub Desktop.
Save xnau/90a648686bccd3af0565c317ba9f947e to your computer and use it in GitHub Desktop.
Demonstrates how to show a uploaded audio file in an audio element
<?php
/**
* Plugin Name: PDB Audio Element
* Description: Demonstrates how to show an uploaded audio file in an audio element
*
*/
add_filter( 'pdb-before_display_form_element','pdb_audio_element_display_function', 10, 2);
/**
* displays the audio element
*
* @param array $value the raw value of the field
* @param PDb_Field_Item object $field
* @return string HTML
*/
function pdb_audio_element_display_function( $value, $field )
{
if ( $field->form_element === 'file-upload' && preg_match( '/\.(aif|ogg|mp3|wav)$/', $field->value, $matches ) > 0) {
$value = '
<div class="pdb-audio-container ' . $field->name . '-audio">
<audio controls>
<source src="' . esc_attr( $field->value ) . '" type="audio/' . $matches[1] . '">
Your browser does not support the audio element.
</audio>
</div>
';
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment