Created
November 19, 2017 20:05
-
-
Save xnau/90a648686bccd3af0565c317ba9f947e to your computer and use it in GitHub Desktop.
Demonstrates how to show a uploaded audio file in an audio element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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