How to allow audio files with GET parameters in the audio shortcode?

There’s an interesting question on WordPress Stackexchange regarding the audio shortcode .

It looks like it doesn’t support sources with GET parameters.

Here are two examples:

1) Without GET parameters the audio player displays:

where the shortcode is:

[audio src="http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3"]

2) With GET parameters it only shows the audio link:

http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3?play=1

where the shortcode is:

[audio src="http://s.w.org/images/core/3.9/JellyRollMorton-BuddyBoldensBlues.mp3?play=1"]

I managed to work around it with the following code snippet:

/**
 * Allow unrecognize audio sources hosted on 's.w.org'.
 *
 * @see http://wordpress.stackexchange.com/a/152352/26350
 */

add_filter( 'wp_audio_shortcode_override',
    function( $html, $atts )
    {
        if( 's.w.org' === parse_url( $atts['src'], PHP_URL_HOST ) )
        {
            add_filter( 'wp_audio_extensions', 'wpse_152316_wp_audio_extensions' );
        }
        return $html;
    }
, PHP_INT_MAX, 2 );

function wpse_152316_wp_audio_extensions( $ext )
{
    remove_filter( current_filter(), __FUNCTION__ );
    $ext[] = '';
    return $ext;
}

9 thoughts on “How to allow audio files with GET parameters in the audio shortcode?”

  1. Hi Birgire,

    I don’t know how to contact you on Stackoverflow, so here I am on your blog. Hello.

    Your solution to inject Adsense between posts in the WordPress Loop was so short and sweet. I want to do something similar.

    I would like to inject a post (from a specific category) between posts in the Loop. How can I achieve this? My question is posted here. One person replied but it did not work:

    http://stackoverflow.com/questions/25335995/adding-specific-post-category-between-posts-in-loop/25336249#25336249

    Any ideas?

    Leah

  2. @birgire Just wanted to thank you for your awesome plugin and for your patience with my questions. Your plugin works like magic! Expect a Loop Coding Ninja badge in your mailbox Lol. I’ve marked your answer as solved and +1, but I have two questions that I thought would be best to ask here since this will not fit in the forum comment.

    It turns out the problem was this piece of code in the Loop for index.php (I use it to call for the custom field such as ‘price’). Is there a way that I can still use this ‘custom field’ code without interfering with the plugin?

    ————————

    post->ID;
    echo get_post_meta($postid, ‘$’, true);
    wp_reset_query();
    ?>

    post->ID;
    echo get_post_meta($postid, ‘via’, true);
    wp_reset_query();
    ?>

    post->ID;
    echo get_post_meta($postid, ‘ownitnow’, true);
    wp_reset_query();
    ?>
    ————————–

    Another issue is ‘sponsor’ posts are being called twice, once by the main loop and again by the plugin, resulting in duplicate ‘sponsor’ posts on the homepage. How do you exclude ‘sponsor posts’ from the main loop, but KEEP the ‘sponsor posts’ from the plugin?

    Thanks so much,
    Leko

    1. Hi @Leko

      Thanks, you’re welcome 😉

      Don’t use wp_reset_query(), you don’t need it (expect you use query_posts() which isn’t recommended either).

      Regarding the sponsor posts being called twice, you just need to exclude the “sponsor” category from the main query within the “pre_get_posts” hook.

  3. Hmm please ignore the code above, it did not display properly…

    This is the code within the Loop in index.php to call the ‘custom field’

    ——————–
    p o s t -> ID;
    echo get_post_meta($postid, ‘$’, true);
    wp_reset_query();
    ?>
    ———————-

  4. Hello again! Quick question for ya. I am reading about securing/hardening WordPress. They say it is important to update themes/plugins because the updates have patched vulnerabilities. For example, TimThumb plugin was hacked.

    Do you foresee any vulnerabilities or hacker related issues with the Injector plugin?

    1. Hi @Leko

      I don’t see any vulnerabilities for the Injector plugin at the moment.

      It doesn’t have any explicit external user input and it isn’t writing stuff on the disk, like the TimThumb plugin does.

Leave a Reply

Your email address will not be published. Required fields are marked *