futtta / wp-youtube-lyte

Embed YouTube on WordPress for optimal performance
24 stars 10 forks source link

Short urls in Elementor don't work #27

Closed colmtroy closed 2 years ago

colmtroy commented 3 years ago

So it looks like short urls don't work.

e.g.

See this page https://www.xeroshoes.eu/short-url-test/

The video url is: https://youtu.be/yPK34A3Lk7o

I'm already using this filter https://blog.futtta.be/2021/02/13/fix-for-elementor-3-1-youtube-not-lyte-anymore/

When I switch to the long form youtube url the video works fine - it's just shortened version

futtta commented 3 years ago

In the code snippet can you try replacing lyte_preparse with lyte_parse ?

colmtroy commented 2 years ago

@futtta apols I wrote a reply here yesterday but I must have forgotten to submit it! That's didn't work unfortunately. This is what I see now

Moreover, it also breaks the ones that were working

futtta commented 2 years ago

That implies that the video's were added differently and hence the snippet will have to be adjusted to behave differently based on what info it gets from that Elementor filter. Maybe error_log the YT info like this

if ( ! empty( $pas['youtube_url'] ) ) {
    error_log( "youtube video: " . $pas['youtube_url'] );
    echo lyte_preparse( $pas['youtube_url'] );
    return false;
}

and then check the PHP error log for those log entries, based on that info we might be able to see what needs improving.

colmtroy commented 2 years ago

@futtta apols for the delay - where has 2022 gone already!

here's some error log output for you:

[07-Apr-2022 12:04:19 UTC] youtube_url is: https://youtu.be/XRmikcz1GKE
[07-Apr-2022 12:04:19 UTC] lyte_preparse is: httpv://www.youtube.com/watch?v=https://youtu.be/XRmikcz1GKE
[07-Apr-2022 12:04:19 UTC] lyte_parse is: https://youtu.be/XRmikcz1GKE

So in all cases, the video url is the short url https://youtu.be/XRmikcz1GKE

I wonder if theres some way you could look for the domain youtu.be and then make the assumption we've got a short url, and then modify what gets passed to the preparse function?

futtta commented 2 years ago

OK, can you try changing:

        if ( ! empty( $pas['youtube_url'] ) ) {
            echo lyte_preparse( $pas['youtube_url'] );
            return false;
        }

into

        if ( ! empty( $pas['youtube_url'] ) ) {
                        $youtube_url = str_replace( 'https://youtu.be/', '', $pas['youtube_url'] );
            echo lyte_preparse( $youtube_url );
            return false;
        }
colmtroy commented 2 years ago

@futtta

that did the trick - fantastic! Thank you SO much. That saved me a few hours work replacing the short urls in a ton of pages :)

futtta commented 2 years ago

you're welcome :)