1

I am looking to embed videos from websites that do not offer oembed support. I wrote some code but it's not working.

example link:

https://openload.co/f/onU1gT5mkJ8/A_date_with_Lazar_Angelov.mp4

example embed:

<iframe src="https://openload.co/embed/onU1gT5mkJ8/A_date_with_Lazar_Angelov.mp4" scrolling="no" frameborder="0" width="700" height="430" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>

my code:

  add_action( 'init', function()
    {
        wp_embed_register_handler( 
            'openload', 
            '#https://www\.openload\.co/f/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)?#i', 
            'wp_embed_handler_openload' 
        );

    } );

    function wp_embed_handler_openload( $matches, $attr, $url, $rawattr )
    {
        $embed = sprintf(
            '<iframe class="openload-video" src="https://openload.co/embed/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)" scrolling="no" frameborder="0" width="700" height="430" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true">></iframe>',
            esc_attr( $matches[1] ) 
         );

        return apply_filters( 'embed_openload', $embed, $matches, $attr, $url, $rawattr );
    }

I really stucked at this. I would much appreciate any advice or links to any info that can help. Thanks!

1
  • I answered a similar question (same title) recently here that's hopefully helpful. – birgire Nov 27 '16 at 17:50
2

Pretty sure it's the fact you're trying to use the regex pattern in your sprintf call, when you should be using... well, a sprintf format:

$embed = sprintf(
    '<iframe class="openload-video" src="https://openload.co/embed/%s" scrolling="no" frameborder="0" width="700" height="430" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true">></iframe>',
    esc_attr(
        $matches[1]
    ) 
);

Note that you're not using www in your embed url:

https://openload.co/f/onU1gT5mkJ8/A_date_with_Lazar_Angelov.mp4

as expected in your pattern:

#https://www\.openload\.co/f/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)?#i
1
  • yes this is definitely needed here or %1$s – birgire Nov 27 '16 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.