Legacy Audio Shortcode

I have recently redone a site that was originally created in 2011. Of course there were a few big development issues and one of them is the usage of an old audio shortcode:

I have not seen any documentation of the native WordPress audio shortcode ever using a colon. I have also not been able to find a plugin that uses it in this way.

Does anyone know how I can get this shortcode functioning? I believe my options are.

  1. Create a script that turns this audio shortcode into the newer format https://codex.wordpress.org/Audio_Shortcode.
  2. Find the plugin that originally made the shortcode this way.
  3. ?

/======== Progress ========/

@gmazzap got me on the right track! The issue is that with the shortcode_atts_audio hook the $atts variable doesn’t output strings outside of the predefined attributes (src, loop, autoplay, preload.) After some digging I found that I can use the wp_audio_shortcode_override to access my url. That is what I’m doing in the code below. But now I’m having trouble passing that attribute back into the shortcode and outputting it.

function legacy_audio_shortcode_converter( $html, $attr ) {

        $colon_src = $attr[0]; //get the url string with the colon included.
        $attr['src'] = substr($colon_src, 1); //filter out the colon
        $new_audio_src = $attr['src']; //save the url as the official audio src
        var_dump($new_audio_src); //this is currently outputing the exact url I need but not sure how to make sure the player shows up with this new src.
}

add_filter( 'wp_audio_shortcode_override', 'legacy_audio_shortcode_converter', 10, 2 ); 

2 Answers
2

If your only issue is that the format is incorrect then switch it in the_content hook with the correct version.


Non-local content:


Place in a plugin or functions.php

// hook earlier than 10

add_filter('the_content', 'wpse_20160110_the_content_fix_audio', 0);

function wpse_20160110_the_content_fix_audio($content){
    return str_replace ( '[audio:', '[audio src="https://wordpress.stackexchange.com/questions/214052/, $content );
}

Leave a Comment